Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions hyperliquid/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ func OrderRequestToWire(req OrderRequest, meta map[string]AssetInfo) OrderWire {
OrderType: OrderTypeToWire(req.OrderType),
}
}
func ModifyOrderRequestToWire(req ModifyOrderRequest, meta map[string]AssetInfo) ModifyOrderWire {
info := meta[req.Coin]
return ModifyOrderWire{
OrderId: req.OrderId,
Order: OrderWire{
Asset: info.AssetId,
IsBuy: req.IsBuy,
LimitPx: FloatToWire(req.LimitPx, nil),
SizePx: FloatToWire(req.Sz, &info.SzDecimals),
ReduceOnly: req.ReduceOnly,
OrderType: OrderTypeToWire(req.OrderType),
},
}
}

func OrderTypeToWire(orderType OrderType) OrderTypeWire {
if orderType.Limit != nil {
Expand Down
27 changes: 27 additions & 0 deletions hyperliquid/exchange_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,33 @@ func (api *ExchangeAPI) BulkCancelOrders(cancels []CancelOidWire) (*CancelOrderR
return MakeUniversalRequest[CancelOrderResponse](api, request)
}

// Bulk modify orders
// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
func (api *ExchangeAPI) BulkModifyOrders(modifyRequests []ModifyOrderRequest) (*PlaceOrderResponse, error) {
wires := []ModifyOrderWire{}

for _, req := range modifyRequests {
wires = append(wires, ModifyOrderRequestToWire(req, api.meta))
}
action := ModifyOrderAction{
Type: "batchModify",
Modifies: wires,
}

timestamp := GetNonce()
vVal, rVal, sVal, signErr := api.SignL1Action(action, timestamp)
if signErr != nil {
return nil, signErr
}
request := ExchangeRequest{
Action: action,
Nonce: timestamp,
Signature: ToTypedSig(rVal, sVal, vVal),
VaultAddress: nil,
}
return MakeUniversalRequest[PlaceOrderResponse](api, request)
}

// Cancel exact order by OID
func (api *ExchangeAPI) CancelOrderByOID(coin string, orderID int64) (*CancelOrderResponse, error) {
return api.BulkCancelOrders([]CancelOidWire{{Asset: api.meta[coin].AssetId, Oid: int(orderID)}})
Expand Down
23 changes: 23 additions & 0 deletions hyperliquid/exchange_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ type OrderWire struct {
OrderType OrderTypeWire `msgpack:"t" json:"t"`
Cloid string `msgpack:"c,omitempty" json:"c,omitempty"`
}
type ModifyResponse struct {
Status string `json:"status"`
Response PlaceOrderInnerResponse `json:"response"`
}
type ModifyOrderWire struct {
OrderId int `msgpack:"oid" json:"oid"`
Order OrderWire `msgpack:"order" json:"order"`
}
type ModifyOrderAction struct {
Type string `msgpack:"type" json:"type"`
Modifies []ModifyOrderWire `msgpack:"modifies" json:"modifies"`
}

type ModifyOrderRequest struct {
OrderId int `json:"oid"`
Coin string `json:"coin"`
IsBuy bool `json:"is_buy"`
Sz float64 `json:"sz"`
LimitPx float64 `json:"limit_px"`
OrderType OrderType `json:"order_type"`
ReduceOnly bool `json:"reduce_only"`
Cloid string `json:"cloid,omitempty"`
}

type OrderTypeWire struct {
Limit *LimitOrderType `json:"limit,omitempty" msgpack:"limit,omitempty"`
Expand Down