Skip to content

Commit 439b402

Browse files
committed
Exchange API: Added bulk modify orders
1 parent bcf1a25 commit 439b402

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

hyperliquid/convert.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ func OrderRequestToWire(req OrderRequest, meta map[string]AssetInfo) OrderWire {
5353
OrderType: OrderTypeToWire(req.OrderType),
5454
}
5555
}
56+
func ModifyOrderRequestToWire(req ModifyOrderRequest, meta map[string]AssetInfo) ModifyOrderWire {
57+
info := meta[req.Coin]
58+
return ModifyOrderWire{
59+
OrderId: req.OrderId,
60+
Order: OrderWire{
61+
Asset: info.AssetId,
62+
IsBuy: req.IsBuy,
63+
LimitPx: FloatToWire(req.LimitPx, nil),
64+
SizePx: FloatToWire(req.Sz, &info.SzDecimals),
65+
ReduceOnly: req.ReduceOnly,
66+
OrderType: OrderTypeToWire(req.OrderType),
67+
},
68+
}
69+
}
5670

5771
func OrderTypeToWire(orderType OrderType) OrderTypeWire {
5872
if orderType.Limit != nil {

hyperliquid/exchange_service.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,33 @@ func (api *ExchangeAPI) BulkCancelOrders(cancels []CancelOidWire) (*CancelOrderR
213213
return MakeUniversalRequest[CancelOrderResponse](api, request)
214214
}
215215

216+
// Bulk modify orders
217+
// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
218+
func (api *ExchangeAPI) BulkModifyOrders(modifyRequests []ModifyOrderRequest) (*PlaceOrderResponse, error) {
219+
wires := []ModifyOrderWire{}
220+
221+
for _, req := range modifyRequests {
222+
wires = append(wires, ModifyOrderRequestToWire(req, api.meta))
223+
}
224+
action := ModifyOrderAction{
225+
Type: "batchModify",
226+
Modifies: wires,
227+
}
228+
229+
timestamp := GetNonce()
230+
vVal, rVal, sVal, signErr := api.SignL1Action(action, timestamp)
231+
if signErr != nil {
232+
return nil, signErr
233+
}
234+
request := ExchangeRequest{
235+
Action: action,
236+
Nonce: timestamp,
237+
Signature: ToTypedSig(rVal, sVal, vVal),
238+
VaultAddress: nil,
239+
}
240+
return MakeUniversalRequest[PlaceOrderResponse](api, request)
241+
}
242+
216243
// Cancel exact order by OID
217244
func (api *ExchangeAPI) CancelOrderByOID(coin string, orderID int64) (*CancelOrderResponse, error) {
218245
return api.BulkCancelOrders([]CancelOidWire{{Asset: api.meta[coin].AssetId, Oid: int(orderID)}})

hyperliquid/exchange_types.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ type OrderWire struct {
7373
OrderType OrderTypeWire `msgpack:"t" json:"t"`
7474
Cloid string `msgpack:"c,omitempty" json:"c,omitempty"`
7575
}
76+
type ModifyResponse struct {
77+
Status string `json:"status"`
78+
Response PlaceOrderInnerResponse `json:"response"`
79+
}
80+
type ModifyOrderWire struct {
81+
OrderId int `msgpack:"oid" json:"oid"`
82+
Order OrderWire `msgpack:"order" json:"order"`
83+
}
84+
type ModifyOrderAction struct {
85+
Type string `msgpack:"type" json:"type"`
86+
Modifies []ModifyOrderWire `msgpack:"modifies" json:"modifies"`
87+
}
88+
89+
type ModifyOrderRequest struct {
90+
OrderId int `json:"oid"`
91+
Coin string `json:"coin"`
92+
IsBuy bool `json:"is_buy"`
93+
Sz float64 `json:"sz"`
94+
LimitPx float64 `json:"limit_px"`
95+
OrderType OrderType `json:"order_type"`
96+
ReduceOnly bool `json:"reduce_only"`
97+
Cloid string `json:"cloid,omitempty"`
98+
}
7699

77100
type OrderTypeWire struct {
78101
Limit *LimitOrderType `json:"limit,omitempty" msgpack:"limit,omitempty"`

0 commit comments

Comments
 (0)