Skip to content

Commit 8867f37

Browse files
Merge pull request #12 from itay747/bulkModify
Exchange API: Added bulk modify orders
2 parents 6caf66f + 439b402 commit 8867f37

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
@@ -62,6 +62,20 @@ func OrderRequestToWire(req OrderRequest, meta map[string]AssetInfo, isSpot bool
6262
OrderType: OrderTypeToWire(req.OrderType),
6363
}
6464
}
65+
func ModifyOrderRequestToWire(req ModifyOrderRequest, meta map[string]AssetInfo) ModifyOrderWire {
66+
info := meta[req.Coin]
67+
return ModifyOrderWire{
68+
OrderId: req.OrderId,
69+
Order: OrderWire{
70+
Asset: info.AssetId,
71+
IsBuy: req.IsBuy,
72+
LimitPx: FloatToWire(req.LimitPx, nil),
73+
SizePx: FloatToWire(req.Sz, &info.SzDecimals),
74+
ReduceOnly: req.ReduceOnly,
75+
OrderType: OrderTypeToWire(req.OrderType),
76+
},
77+
}
78+
}
6579

6680
func OrderTypeToWire(orderType OrderType) OrderTypeWire {
6781
if orderType.Limit != nil {

hyperliquid/exchange_service.go

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

275+
// Bulk modify orders
276+
// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
277+
func (api *ExchangeAPI) BulkModifyOrders(modifyRequests []ModifyOrderRequest) (*PlaceOrderResponse, error) {
278+
wires := []ModifyOrderWire{}
279+
280+
for _, req := range modifyRequests {
281+
wires = append(wires, ModifyOrderRequestToWire(req, api.meta))
282+
}
283+
action := ModifyOrderAction{
284+
Type: "batchModify",
285+
Modifies: wires,
286+
}
287+
288+
timestamp := GetNonce()
289+
vVal, rVal, sVal, signErr := api.SignL1Action(action, timestamp)
290+
if signErr != nil {
291+
return nil, signErr
292+
}
293+
request := ExchangeRequest{
294+
Action: action,
295+
Nonce: timestamp,
296+
Signature: ToTypedSig(rVal, sVal, vVal),
297+
VaultAddress: nil,
298+
}
299+
return MakeUniversalRequest[PlaceOrderResponse](api, request)
300+
}
301+
275302
// Cancel exact order by OID
276303
func (api *ExchangeAPI) CancelOrderByOID(coin string, orderID int64) (*CancelOrderResponse, error) {
277304
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
@@ -75,6 +75,29 @@ type OrderWire struct {
7575
OrderType OrderTypeWire `msgpack:"t" json:"t"`
7676
Cloid string `msgpack:"c,omitempty" json:"c,omitempty"`
7777
}
78+
type ModifyResponse struct {
79+
Status string `json:"status"`
80+
Response PlaceOrderInnerResponse `json:"response"`
81+
}
82+
type ModifyOrderWire struct {
83+
OrderId int `msgpack:"oid" json:"oid"`
84+
Order OrderWire `msgpack:"order" json:"order"`
85+
}
86+
type ModifyOrderAction struct {
87+
Type string `msgpack:"type" json:"type"`
88+
Modifies []ModifyOrderWire `msgpack:"modifies" json:"modifies"`
89+
}
90+
91+
type ModifyOrderRequest struct {
92+
OrderId int `json:"oid"`
93+
Coin string `json:"coin"`
94+
IsBuy bool `json:"is_buy"`
95+
Sz float64 `json:"sz"`
96+
LimitPx float64 `json:"limit_px"`
97+
OrderType OrderType `json:"order_type"`
98+
ReduceOnly bool `json:"reduce_only"`
99+
Cloid string `json:"cloid,omitempty"`
100+
}
78101

79102
type OrderTypeWire struct {
80103
Limit *LimitOrderType `json:"limit,omitempty" msgpack:"limit,omitempty"`

0 commit comments

Comments
 (0)