diff --git a/config.json b/config.json index 810986d..cfc0df3 100644 --- a/config.json +++ b/config.json @@ -3,7 +3,7 @@ "trade_enabled": true, "arb_threshold": 0.02, "scan_interval_ms": 200, - "trade_threshold": 0.05, + "trade_threshold": 0.03, "trade_amount_usd": 20, "trade_cooldown_ms": 30000, "alert_cooldown_sec": 300, diff --git a/exchange/bitget_trade.go b/exchange/bitget_trade.go index 5fd3349..7184063 100644 --- a/exchange/bitget_trade.go +++ b/exchange/bitget_trade.go @@ -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, "") diff --git a/exchange/hyperliquid_trade.go b/exchange/hyperliquid_trade.go index 37c285d..70b3b3a 100644 --- a/exchange/hyperliquid_trade.go +++ b/exchange/hyperliquid_trade.go @@ -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")