-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodify_order.ts
More file actions
39 lines (31 loc) · 1.07 KB
/
modify_order.ts
File metadata and controls
39 lines (31 loc) · 1.07 KB
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
36
37
38
39
#!/usr/bin/env npx ts-node
// @ts-nocheck
/**
* Modify Order Example
*
* Place a resting order and then modify its price.
*/
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
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 at $${limitPrice.toLocaleString()}`);
console.log(` OID: ${order.oid}`);
// Modify to a new price (4% below mid)
const newPrice = Math.floor(mid * 0.96);
const newOrder = await order.modify({ price: newPrice });
console.log(`Modified to $${newPrice.toLocaleString()}`);
console.log(` New OID: ${newOrder.oid}`);
// Clean up
await newOrder.cancel();
console.log("Order cancelled.");
}
main().catch(console.error);