mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-17 09:24:36 +08:00
fix: Lighter CancelStopOrders now filters by TriggerPrice, proxyBinance checks upstream status
- CancelStopOrders: only cancel orders with non-empty TriggerPrice (was canceling ALL orders including regular limit orders — safety bug) - proxyBinance: return 502 when upstream returns non-200 instead of silently proxying error pages - Remove redundant CORS headers in agent/web.go (already handled by gin middleware)
This commit is contained in:
11
agent/web.go
11
agent/web.go
@@ -122,15 +122,22 @@ func proxyBinance(rw http.ResponseWriter, url string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Forward upstream error status codes instead of silently proxying bad data
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
writeJSON(rw, 502, map[string]string{"error": fmt.Sprintf("upstream returned status %d", resp.StatusCode)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
rw.Header().Set("Content-Type", "application/json")
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
rw.Header().Set("Access-Control-Allow-Origin", "*")
|
// CORS is handled by the gin middleware — no need to set it here
|
||||||
// Limit response body to 2MB to prevent memory exhaustion
|
// Limit response body to 2MB to prevent memory exhaustion
|
||||||
io.Copy(rw, io.LimitReader(resp.Body, 2*1024*1024))
|
io.Copy(rw, io.LimitReader(resp.Body, 2*1024*1024))
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeJSON(w http.ResponseWriter, status int, v interface{}) {
|
func writeJSON(w http.ResponseWriter, status int, v interface{}) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
// CORS is handled by the gin middleware — no need to set it here
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
json.NewEncoder(w).Encode(v)
|
json.NewEncoder(w).Encode(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,17 +186,22 @@ func (t *LighterTraderV2) CancelStopOrders(symbol string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canceledCount := 0
|
canceledCount := 0
|
||||||
|
skippedCount := 0
|
||||||
for _, order := range orders {
|
for _, order := range orders {
|
||||||
// TODO: Check order type, only cancel stop orders
|
// Only cancel orders with a trigger price (stop-loss / take-profit)
|
||||||
// For now, cancel all orders
|
// Regular limit orders have empty or "0" trigger price
|
||||||
|
if order.TriggerPrice == "" || order.TriggerPrice == "0" || order.TriggerPrice == "0.0" {
|
||||||
|
skippedCount++
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := t.CancelOrder(symbol, order.OrderID); err != nil {
|
if err := t.CancelOrder(symbol, order.OrderID); err != nil {
|
||||||
logger.Infof("⚠️ Failed to cancel order (ID: %s): %v", order.OrderID, err)
|
logger.Infof("⚠️ Failed to cancel stop order (ID: %s): %v", order.OrderID, err)
|
||||||
} else {
|
} else {
|
||||||
canceledCount++
|
canceledCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infof("✓ LIGHTER - Canceled %d stop orders", canceledCount)
|
logger.Infof("✓ LIGHTER - Canceled %d stop orders (skipped %d regular orders)", canceledCount, skippedCount)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user