mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-16 17:12:25 +08:00
fix(okx): correctly parse slTriggerPx/tpTriggerPx for algo orders
This commit is contained in:
@@ -1438,7 +1438,8 @@ func (t *OKXTrader) GetOpenOrders(symbol string) ([]OpenOrder, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Get pending algo orders (stop-loss/take-profit)
|
// 2. Get pending algo orders (stop-loss/take-profit)
|
||||||
algoPath := fmt.Sprintf("%s?instId=%s&instType=SWAP", okxAlgoPendingPath, instId)
|
// OKX requires ordType parameter for algo orders API
|
||||||
|
algoPath := fmt.Sprintf("%s?instId=%s&instType=SWAP&ordType=conditional", okxAlgoPendingPath, instId)
|
||||||
algoData, err := t.doRequest("GET", algoPath, nil)
|
algoData, err := t.doRequest("GET", algoPath, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("[OKX] Failed to get algo orders: %v", err)
|
logger.Warnf("[OKX] Failed to get algo orders: %v", err)
|
||||||
@@ -1451,12 +1452,13 @@ func (t *OKXTrader) GetOpenOrders(symbol string) ([]OpenOrder, error) {
|
|||||||
PosSide string `json:"posSide"`
|
PosSide string `json:"posSide"`
|
||||||
OrdType string `json:"ordType"` // conditional/oco/trigger
|
OrdType string `json:"ordType"` // conditional/oco/trigger
|
||||||
TriggerPx string `json:"triggerPx"`
|
TriggerPx string `json:"triggerPx"`
|
||||||
|
SlTriggerPx string `json:"slTriggerPx"` // Stop loss trigger price
|
||||||
|
TpTriggerPx string `json:"tpTriggerPx"` // Take profit trigger price
|
||||||
Sz string `json:"sz"`
|
Sz string `json:"sz"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(algoData, &algoOrders); err == nil {
|
if err := json.Unmarshal(algoData, &algoOrders); err == nil {
|
||||||
for _, order := range algoOrders {
|
for _, order := range algoOrders {
|
||||||
triggerPrice, _ := strconv.ParseFloat(order.TriggerPx, 64)
|
|
||||||
quantity, _ := strconv.ParseFloat(order.Sz, 64)
|
quantity, _ := strconv.ParseFloat(order.Sz, 64)
|
||||||
|
|
||||||
side := strings.ToUpper(order.Side)
|
side := strings.ToUpper(order.Side)
|
||||||
@@ -1465,23 +1467,59 @@ func (t *OKXTrader) GetOpenOrders(symbol string) ([]OpenOrder, error) {
|
|||||||
positionSide = "BOTH"
|
positionSide = "BOTH"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map OKX algo order type
|
// Check for stop loss order (slTriggerPx is set)
|
||||||
orderType := "STOP_MARKET"
|
if order.SlTriggerPx != "" {
|
||||||
if order.OrdType == "oco" {
|
slPrice, _ := strconv.ParseFloat(order.SlTriggerPx, 64)
|
||||||
orderType = "TAKE_PROFIT_MARKET"
|
if slPrice > 0 {
|
||||||
|
result = append(result, OpenOrder{
|
||||||
|
OrderID: order.AlgoId + "_sl",
|
||||||
|
Symbol: symbol,
|
||||||
|
Side: side,
|
||||||
|
PositionSide: positionSide,
|
||||||
|
Type: "STOP_MARKET",
|
||||||
|
Price: 0,
|
||||||
|
StopPrice: slPrice,
|
||||||
|
Quantity: quantity,
|
||||||
|
Status: "NEW",
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = append(result, OpenOrder{
|
// Check for take profit order (tpTriggerPx is set)
|
||||||
OrderID: order.AlgoId,
|
if order.TpTriggerPx != "" {
|
||||||
Symbol: symbol,
|
tpPrice, _ := strconv.ParseFloat(order.TpTriggerPx, 64)
|
||||||
Side: side,
|
if tpPrice > 0 {
|
||||||
PositionSide: positionSide,
|
result = append(result, OpenOrder{
|
||||||
Type: orderType,
|
OrderID: order.AlgoId + "_tp",
|
||||||
Price: 0,
|
Symbol: symbol,
|
||||||
StopPrice: triggerPrice,
|
Side: side,
|
||||||
Quantity: quantity,
|
PositionSide: positionSide,
|
||||||
Status: "NEW",
|
Type: "TAKE_PROFIT_MARKET",
|
||||||
})
|
Price: 0,
|
||||||
|
StopPrice: tpPrice,
|
||||||
|
Quantity: quantity,
|
||||||
|
Status: "NEW",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for trigger orders (triggerPx is set)
|
||||||
|
if order.TriggerPx != "" && order.SlTriggerPx == "" && order.TpTriggerPx == "" {
|
||||||
|
triggerPrice, _ := strconv.ParseFloat(order.TriggerPx, 64)
|
||||||
|
if triggerPrice > 0 {
|
||||||
|
result = append(result, OpenOrder{
|
||||||
|
OrderID: order.AlgoId,
|
||||||
|
Symbol: symbol,
|
||||||
|
Side: side,
|
||||||
|
PositionSide: positionSide,
|
||||||
|
Type: "STOP_MARKET",
|
||||||
|
Price: 0,
|
||||||
|
StopPrice: triggerPrice,
|
||||||
|
Quantity: quantity,
|
||||||
|
Status: "NEW",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user