mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-16 09:11:03 +08:00
fix: correct Lighter API response parsing for GetOpenOrders
- Changed response field from 'data' to 'orders' to match Lighter API - Updated OrderResponse struct to match Lighter's actual field names - Fixed field types: price/quantity as strings, is_ask for side
This commit is contained in:
@@ -148,7 +148,7 @@ func (t *LighterTraderV2) GetOrderStatus(symbol string, orderID string) (map[str
|
|||||||
"orderId": order.OrderID,
|
"orderId": order.OrderID,
|
||||||
"status": unifiedStatus,
|
"status": unifiedStatus,
|
||||||
"avgPrice": order.Price,
|
"avgPrice": order.Price,
|
||||||
"executedQty": order.FilledQty,
|
"executedQty": order.FilledBaseAmount,
|
||||||
"commission": 0.0,
|
"commission": 0.0,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -239,11 +239,11 @@ func (t *LighterTraderV2) GetActiveOrders(symbol string) ([]OrderResponse, error
|
|||||||
|
|
||||||
logger.Infof("📋 LIGHTER GetActiveOrders raw response: %s", string(body))
|
logger.Infof("📋 LIGHTER GetActiveOrders raw response: %s", string(body))
|
||||||
|
|
||||||
// Parse response
|
// Parse response - Lighter API uses "orders" field, not "data"
|
||||||
var apiResp struct {
|
var apiResp struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Data []OrderResponse `json:"data"`
|
Orders []OrderResponse `json:"orders"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(body, &apiResp); err != nil {
|
if err := json.Unmarshal(body, &apiResp); err != nil {
|
||||||
@@ -254,8 +254,8 @@ func (t *LighterTraderV2) GetActiveOrders(symbol string) ([]OrderResponse, error
|
|||||||
return nil, fmt.Errorf("failed to get active orders (code %d): %s", apiResp.Code, apiResp.Message)
|
return nil, fmt.Errorf("failed to get active orders (code %d): %s", apiResp.Code, apiResp.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infof("✓ LIGHTER - Retrieved %d active orders", len(apiResp.Data))
|
logger.Infof("✓ LIGHTER - Retrieved %d active orders", len(apiResp.Orders))
|
||||||
return apiResp.Data, nil
|
return apiResp.Orders, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelOrder Cancel a single order
|
// CancelOrder Cancel a single order
|
||||||
|
|||||||
@@ -697,19 +697,19 @@ func (t *LighterTraderV2) GetOpenOrders(symbol string) ([]OpenOrder, error) {
|
|||||||
|
|
||||||
var result []OpenOrder
|
var result []OpenOrder
|
||||||
for _, order := range activeOrders {
|
for _, order := range activeOrders {
|
||||||
// Convert side: Lighter uses "bid"/"ask", we need "BUY"/"SELL"
|
// Convert side: Lighter uses is_ask (true=sell, false=buy)
|
||||||
side := "BUY"
|
side := "BUY"
|
||||||
if order.Side == "ask" || order.Side == "SELL" || order.Side == "sell" {
|
if order.IsAsk {
|
||||||
side = "SELL"
|
side = "SELL"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine order type
|
// Determine order type from Lighter's type field
|
||||||
orderType := "LIMIT"
|
orderType := "LIMIT"
|
||||||
if order.OrderType == "market" {
|
if order.Type == "market" {
|
||||||
orderType = "MARKET"
|
orderType = "MARKET"
|
||||||
} else if order.OrderType == "stop_loss" {
|
} else if order.Type == "stop_loss" || order.Type == "stop" {
|
||||||
orderType = "STOP_MARKET"
|
orderType = "STOP_MARKET"
|
||||||
} else if order.OrderType == "take_profit" {
|
} else if order.Type == "take_profit" {
|
||||||
orderType = "TAKE_PROFIT_MARKET"
|
orderType = "TAKE_PROFIT_MARKET"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,15 +719,23 @@ func (t *LighterTraderV2) GetOpenOrders(symbol string) ([]OpenOrder, error) {
|
|||||||
positionSide = "SHORT"
|
positionSide = "SHORT"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse price and quantity from string fields
|
||||||
|
price, _ := strconv.ParseFloat(order.Price, 64)
|
||||||
|
quantity, _ := strconv.ParseFloat(order.RemainingBaseAmount, 64)
|
||||||
|
if quantity == 0 {
|
||||||
|
quantity, _ = strconv.ParseFloat(order.InitialBaseAmount, 64)
|
||||||
|
}
|
||||||
|
triggerPrice, _ := strconv.ParseFloat(order.TriggerPrice, 64)
|
||||||
|
|
||||||
openOrder := OpenOrder{
|
openOrder := OpenOrder{
|
||||||
OrderID: order.OrderID,
|
OrderID: order.OrderID,
|
||||||
Symbol: symbol,
|
Symbol: symbol,
|
||||||
Side: side,
|
Side: side,
|
||||||
PositionSide: positionSide,
|
PositionSide: positionSide,
|
||||||
Type: orderType,
|
Type: orderType,
|
||||||
Price: order.Price,
|
Price: price,
|
||||||
StopPrice: order.Price, // For stop orders, price is the trigger price
|
StopPrice: triggerPrice,
|
||||||
Quantity: order.Quantity,
|
Quantity: quantity,
|
||||||
Status: "NEW",
|
Status: "NEW",
|
||||||
}
|
}
|
||||||
result = append(result, openOrder)
|
result = append(result, openOrder)
|
||||||
|
|||||||
@@ -41,18 +41,24 @@ type CreateOrderRequest struct {
|
|||||||
PostOnly bool `json:"post_only"` // Post-only (maker only)
|
PostOnly bool `json:"post_only"` // Post-only (maker only)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderResponse Order response (Lighter)
|
// OrderResponse Order response (Lighter API)
|
||||||
|
// Field names must match Lighter API response exactly
|
||||||
type OrderResponse struct {
|
type OrderResponse struct {
|
||||||
OrderID string `json:"order_id"`
|
OrderID string `json:"order_id"`
|
||||||
Symbol string `json:"symbol"`
|
OrderIndex int64 `json:"order_index"`
|
||||||
Side string `json:"side"`
|
MarketIndex int `json:"market_index"`
|
||||||
OrderType string `json:"order_type"`
|
Side string `json:"side"` // "bid" or "ask"
|
||||||
Quantity float64 `json:"quantity"`
|
Type string `json:"type"` // "limit", "market", etc.
|
||||||
Price float64 `json:"price"`
|
IsAsk bool `json:"is_ask"` // true = sell, false = buy
|
||||||
Status string `json:"status"` // "open", "filled", "cancelled"
|
Price string `json:"price"` // Price as string
|
||||||
FilledQty float64 `json:"filled_qty"`
|
InitialBaseAmount string `json:"initial_base_amount"` // Original quantity
|
||||||
RemainingQty float64 `json:"remaining_qty"`
|
RemainingBaseAmount string `json:"remaining_base_amount"` // Remaining quantity
|
||||||
CreateTime int64 `json:"create_time"`
|
FilledBaseAmount string `json:"filled_base_amount"` // Filled quantity
|
||||||
|
Status string `json:"status"` // "open", "filled", "cancelled"
|
||||||
|
TriggerPrice string `json:"trigger_price"` // For stop orders
|
||||||
|
ReduceOnly bool `json:"reduce_only"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LighterTradeResponse represents the response from Lighter trades API
|
// LighterTradeResponse represents the response from Lighter trades API
|
||||||
|
|||||||
Reference in New Issue
Block a user