fix: correct HL fee parsing (OrderStatus not statuses[]) and add productType to BG fills query

This commit is contained in:
jackyu66git
2026-05-04 20:06:27 +08:00
parent 6e9b982c66
commit 411365b66e
3 changed files with 16 additions and 17 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
"trade_enabled": true, "trade_enabled": true,
"arb_threshold": 0.02, "arb_threshold": 0.02,
"scan_interval_ms": 200, "scan_interval_ms": 200,
"trade_threshold": 0.05, "trade_threshold": 0.03,
"trade_amount_usd": 20, "trade_amount_usd": 20,
"trade_cooldown_ms": 30000, "trade_cooldown_ms": 30000,
"alert_cooldown_sec": 300, "alert_cooldown_sec": 300,
+1 -1
View File
@@ -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) { func (b *BitgetTrade) GetTradeFee(symbol, orderID string) (feeUSD float64, err error) {
ts := fmt.Sprintf("%d", time.Now().UnixMilli()) ts := fmt.Sprintf("%d", time.Now().UnixMilli())
method := "GET" 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" host := "https://api.bitget.com"
sign := b.sign(method, requestPath, ts, "") sign := b.sign(method, requestPath, ts, "")
+14 -15
View File
@@ -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 // 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. // 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) { 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 { var resp struct {
Statuses []struct { Resting *json.RawMessage `json:"resting,omitempty"`
Filled *struct { Filled *struct {
TotalSz string `json:"totalSz"` TotalSz string `json:"totalSz"`
AvgPx string `json:"avgPx"` AvgPx string `json:"avgPx"`
} `json:"filled,omitempty"` } `json:"filled,omitempty"`
Error *string `json:"error,omitempty"` Error *string `json:"error,omitempty"`
} `json:"statuses"`
} }
if err := json.Unmarshal([]byte(orderResponseJSON), &resp); err != nil { 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 resp.Filled != nil {
if st.Filled != nil { sz, _ := strconv.ParseFloat(resp.Filled.TotalSz, 64)
sz, _ := strconv.ParseFloat(st.Filled.TotalSz, 64) px, _ := strconv.ParseFloat(resp.Filled.AvgPx, 64)
px, _ := strconv.ParseFloat(st.Filled.AvgPx, 64) if sz > 0 && px > 0 {
if sz > 0 && px > 0 { return sz * px * takerFeePct / 100, nil
return sz * px * takerFeePct / 100, nil
}
} }
} }
return 0, fmt.Errorf("no filled status in response") return 0, fmt.Errorf("no filled status in response")