From 866f9906b78daa1ebad2642f3fc030d39e074d72 Mon Sep 17 00:00:00 2001 From: jackyu66git Date: Mon, 4 May 2026 23:35:44 +0800 Subject: [PATCH] fix: HL market order double slippage causing 'Order has invalid size' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: PlaceMarketOrder manually calculated limitPx=mid*0.5 (sell) then passed &limitPx to SDK's MarketOpen. SDK treated this as reference price and applied slippage AGAIN (0.95x), resulting in limitPx=mid*0.475. Notional value fell below HL's 0 minimum → error. Fix: pass nil instead of &limitPx, letting SDK get mid price and apply standard 5% slippage itself. --- exchange/hyperliquid_trade.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/exchange/hyperliquid_trade.go b/exchange/hyperliquid_trade.go index 837beb5..de6e6fd 100644 --- a/exchange/hyperliquid_trade.go +++ b/exchange/hyperliquid_trade.go @@ -145,22 +145,7 @@ func (h *HyperLiquidTrade) PlaceMarketOrder(coin, side, sz string) (string, erro ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - mids, err := h.info.AllMids(ctx) - if err != nil { - return "", fmt.Errorf("mids: %w", err) - } - priceStr, ok := mids[coin] - if !ok { - return "", fmt.Errorf("coin %s not found", coin) - } - midPx, _ := strconv.ParseFloat(priceStr, 64) - - limitPx := midPx * 2.0 - if !isBuy { - limitPx = midPx * 0.5 - } - - result, err := h.exchange.MarketOpen(ctx, coin, isBuy, size, &limitPx, 0.05, nil, nil) + result, err := h.exchange.MarketOpen(ctx, coin, isBuy, size, nil, 0.05, nil, nil) if err != nil { return "", fmt.Errorf("market open: %w", err) }