-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcancel_order.ts
More file actions
35 lines (27 loc) · 907 Bytes
/
cancel_order.ts
File metadata and controls
35 lines (27 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env npx ts-node
// @ts-nocheck
/**
* Cancel Order Example
*
* Place an order and then cancel it by OID.
*/
import { HyperliquidSDK } from '@quicknode/hyperliquid-sdk';
const PRIVATE_KEY = process.env.PRIVATE_KEY;
if (!PRIVATE_KEY) {
console.error("Set PRIVATE_KEY environment variable");
process.exit(1);
}
async function main() {
const sdk = new HyperliquidSDK(undefined, { privateKey: PRIVATE_KEY });
// Place a resting order 3% below mid
const mid = await sdk.getMid("BTC");
const limitPrice = Math.floor(mid * 0.97);
const order = await sdk.buy("BTC", { notional: 11, price: limitPrice, tif: "gtc" });
console.log(`Placed order OID: ${order.oid}`);
// Cancel using the order object
await order.cancel();
console.log("Cancelled via order.cancel()");
// Alternative: cancel by OID directly
// await sdk.cancel(12345, "BTC");
}
main().catch(console.error);