fix: correct HL fee parsing (OrderStatus not statuses[]) and add productType to BG fills query
This commit is contained in:
@@ -91,7 +91,7 @@ func (b *BitgetTrade) PlaceMarketOrder(side, symbol, size, tradeSide string) (st
|
||||
func (b *BitgetTrade) GetTradeFee(symbol, orderID string) (feeUSD float64, err error) {
|
||||
ts := fmt.Sprintf("%d", time.Now().UnixMilli())
|
||||
method := "GET"
|
||||
requestPath := "/api/v2/mix/order/fills?symbol=" + symbol + "&orderId=" + orderID
|
||||
requestPath := "/api/v2/mix/order/fills?symbol=" + symbol + "&orderId=" + orderID + "&productType=USDT-FUTURES"
|
||||
host := "https://api.bitget.com"
|
||||
|
||||
sign := b.sign(method, requestPath, ts, "")
|
||||
|
||||
@@ -126,25 +126,24 @@ func (h *HyperLiquidTrade) PlaceMarketOrder(coin, side, sz string) (string, erro
|
||||
// fee amounts in the order response. The result is equivalent to estimating from
|
||||
// TradeAmountUSD, but more accurate for partial fills since it uses actual filled sz/px.
|
||||
func (h *HyperLiquidTrade) EstimateFeeFromResponse(orderResponseJSON string, takerFeePct float64) (feeUSD float64, err error) {
|
||||
// HL MarketOpen returns a single OrderStatus object (NOT wrapped in statuses array):
|
||||
// {"resting":..., "filled":{"totalSz":"82.5","avgPx":"0.12153","oid":52463955193}, "error":...}
|
||||
var resp struct {
|
||||
Statuses []struct {
|
||||
Filled *struct {
|
||||
TotalSz string `json:"totalSz"`
|
||||
AvgPx string `json:"avgPx"`
|
||||
} `json:"filled,omitempty"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
} `json:"statuses"`
|
||||
Resting *json.RawMessage `json:"resting,omitempty"`
|
||||
Filled *struct {
|
||||
TotalSz string `json:"totalSz"`
|
||||
AvgPx string `json:"avgPx"`
|
||||
} `json:"filled,omitempty"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(orderResponseJSON), &resp); err != nil {
|
||||
return 0, fmt.Errorf("parse order response: %w", err)
|
||||
return 0, fmt.Errorf("parse: %w", err)
|
||||
}
|
||||
for _, st := range resp.Statuses {
|
||||
if st.Filled != nil {
|
||||
sz, _ := strconv.ParseFloat(st.Filled.TotalSz, 64)
|
||||
px, _ := strconv.ParseFloat(st.Filled.AvgPx, 64)
|
||||
if sz > 0 && px > 0 {
|
||||
return sz * px * takerFeePct / 100, nil
|
||||
}
|
||||
if resp.Filled != nil {
|
||||
sz, _ := strconv.ParseFloat(resp.Filled.TotalSz, 64)
|
||||
px, _ := strconv.ParseFloat(resp.Filled.AvgPx, 64)
|
||||
if sz > 0 && px > 0 {
|
||||
return sz * px * takerFeePct / 100, nil
|
||||
}
|
||||
}
|
||||
return 0, fmt.Errorf("no filled status in response")
|
||||
|
||||
Reference in New Issue
Block a user