@@ -120,8 +120,13 @@ func (api *ExchangeAPI) MarketOrder(coin string, size float64, slippage *float64
120120
121121// MarketOrderSpot is a market order for a spot coin.
122122// It is used to buy/sell a spot coin.
123+ // Limit order with TIF=IOC and px=market price * (1 +- slippage).
124+ // Size determines the amount of the coin to buy/sell.
125+ //
126+ // MarketOrderSpot("HYPE", 0.1, nil) // Buy 0.1 HYPE
127+ // MarketOrderSpot("HYPE", -0.1, nil) // Sell 0.1 HYPE
128+ // MarketOrderSpot("HYPE", 0.1, &slippage) // Buy 0.1 HYPE with slippage
123129func (api * ExchangeAPI ) MarketOrderSpot (coin string , size float64 , slippage * float64 ) (* PlaceOrderResponse , error ) {
124- spotName := api .spotMeta [coin ].SpotName
125130 slpg := GetSlippage (slippage )
126131 isBuy := IsBuy (size )
127132 finalPx := api .SlippagePriceSpot (coin , isBuy , slpg )
@@ -131,7 +136,7 @@ func (api *ExchangeAPI) MarketOrderSpot(coin string, size float64, slippage *flo
131136 },
132137 }
133138 orderRequest := OrderRequest {
134- Coin : spotName ,
139+ Coin : coin ,
135140 IsBuy : isBuy ,
136141 Sz : math .Abs (size ),
137142 LimitPx : finalPx ,
@@ -208,42 +213,26 @@ func (api *ExchangeAPI) ClosePosition(coin string) (*PlaceOrderResponse, error)
208213
209214// Place single order
210215func (api * ExchangeAPI ) Order (request OrderRequest , grouping Grouping ) (* PlaceOrderResponse , error ) {
211- return api .BulkOrders ([]OrderRequest {request }, grouping )
216+ return api .BulkOrders ([]OrderRequest {request }, grouping , false )
212217}
213218
214219// OrderSpot places a spot order
215220func (api * ExchangeAPI ) OrderSpot (request OrderRequest , grouping Grouping ) (* PlaceOrderResponse , error ) {
216- return api .BulkOrdersSpot ([]OrderRequest {request }, grouping )
221+ return api .BulkOrders ([]OrderRequest {request }, grouping , true )
217222}
218223
219224// Place orders in bulk
220225// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
221- func (api * ExchangeAPI ) BulkOrders (requests []OrderRequest , grouping Grouping ) (* PlaceOrderResponse , error ) {
226+ func (api * ExchangeAPI ) BulkOrders (requests []OrderRequest , grouping Grouping , isSpot bool ) (* PlaceOrderResponse , error ) {
222227 var wires []OrderWire
223- for _ , req := range requests {
224- wires = append (wires , OrderRequestToWire (req , api .meta , false ))
228+ var meta map [string ]AssetInfo
229+ if isSpot {
230+ meta = api .spotMeta
231+ } else {
232+ meta = api .meta
225233 }
226- timestamp := GetNonce ()
227- action := OrderWiresToOrderAction (wires , grouping )
228- v , r , s , err := api .SignL1Action (action , timestamp )
229- if err != nil {
230- api .debug ("Error signing L1 action: %s" , err )
231- return nil , err
232- }
233- request := ExchangeRequest {
234- Action : action ,
235- Nonce : timestamp ,
236- Signature : ToTypedSig (r , s , v ),
237- VaultAddress : nil ,
238- }
239- return MakeUniversalRequest [PlaceOrderResponse ](api , request )
240- }
241-
242- // BulkOrdersSpot places spot orders
243- func (api * ExchangeAPI ) BulkOrdersSpot (requests []OrderRequest , grouping Grouping ) (* PlaceOrderResponse , error ) {
244- var wires []OrderWire
245234 for _ , req := range requests {
246- wires = append (wires , OrderRequestToWire (req , api . spotMeta , true ))
235+ wires = append (wires , OrderRequestToWire (req , meta , isSpot ))
247236 }
248237 timestamp := GetNonce ()
249238 action := OrderWiresToOrderAction (wires , grouping )
@@ -353,7 +342,7 @@ func (api *ExchangeAPI) Withdraw(destination string, amount float64) (*WithdrawR
353342 action := WithdrawAction {
354343 Type : "withdraw3" ,
355344 Destination : destination ,
356- Amount : FloatToWire (amount , & SZ_DECIMALS ),
345+ Amount : FloatToWire (amount , PERP_MAX_DECIMALS , SZ_DECIMALS ),
357346 Time : nonce ,
358347 }
359348 signatureChainID , chainType := api .getChainParams ()
0 commit comments