Skip to content

Commit b13388b

Browse files
committed
feat: add CancelOrderByCloid method
1 parent 956da12 commit b13388b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

hyperliquid/exchange_service.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type IExchangeAPI interface {
1919

2020
// Order management
2121
CancelOrderByOID(coin string, orderID int) (any, error)
22+
CancelOrderByCloid(coin string, clientOID string) (any, error)
2223
BulkCancelOrders(cancels []CancelOidWire) (any, error)
2324
CancelAllOrdersByCoin(coin string) (any, error)
2425
CancelAllOrders() (any, error)
@@ -310,6 +311,33 @@ func (api *ExchangeAPI) CancelOrderByOID(coin string, orderID int64) (*CancelOrd
310311
return api.BulkCancelOrders([]CancelOidWire{{Asset: api.meta[coin].AssetId, Oid: int(orderID)}})
311312
}
312313

314+
// Cancel exact order by Client Order Id
315+
// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
316+
func (api *ExchangeAPI) CancelOrderByCloid(coin string, clientOID string) (*CancelOrderResponse, error) {
317+
timestamp := GetNonce()
318+
action := CancelCloidOrderAction{
319+
Type: "cancelByCloid",
320+
Cancels: []CancelCloidWire{
321+
{
322+
Asset: api.meta[coin].AssetId,
323+
Cloid: clientOID,
324+
},
325+
},
326+
}
327+
v, r, s, err := api.SignL1Action(action, timestamp)
328+
if err != nil {
329+
api.debug("Error signing L1 action: %s", err)
330+
return nil, err
331+
}
332+
request := ExchangeRequest{
333+
Action: action,
334+
Nonce: timestamp,
335+
Signature: ToTypedSig(r, s, v),
336+
VaultAddress: nil,
337+
}
338+
return MakeUniversalRequest[CancelOrderResponse](api, request)
339+
}
340+
313341
// Cancel all orders for a given coin
314342
func (api *ExchangeAPI) CancelAllOrdersByCoin(coin string) (*CancelOrderResponse, error) {
315343
orders, err := api.infoAPI.GetOpenOrders(api.AccountAddress())

hyperliquid/exchange_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ type CancelOidWire struct {
146146
Oid int `msgpack:"o" json:"o"`
147147
}
148148

149+
type CancelCloidWire struct {
150+
Asset int `msgpack:"asset" json:"asset"`
151+
Cloid string `msgpack:"cloid" json:"cloid"`
152+
}
153+
154+
type CancelCloidOrderAction struct {
155+
Type string `msgpack:"type" json:"type"`
156+
Cancels []CancelCloidWire `msgpack:"cancels" json:"cancels"`
157+
}
158+
149159
type CancelOrderResponse struct {
150160
Status string `json:"status"`
151161
Response InnerCancelResponse `json:"response"`

0 commit comments

Comments
 (0)