-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathroundtrip.ts
More file actions
36 lines (28 loc) · 988 Bytes
/
roundtrip.ts
File metadata and controls
36 lines (28 loc) · 988 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
36
#!/usr/bin/env npx ts-node
// @ts-nocheck
/**
* Round Trip Example
*
* Complete trade cycle: buy then sell to end up flat.
*/
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 });
// Buy $11 worth of BTC
console.log("Buying BTC...");
const buy = await sdk.marketBuy("BTC", { notional: 11 });
console.log(` Bought: ${buy.filledSize || buy.size} BTC`);
console.log(` Status: ${buy.status}`);
// Sell the same amount
console.log("Selling BTC...");
const sell = await sdk.marketSell("BTC", { size: buy.filledSize || buy.size });
console.log(` Sold: ${sell.filledSize || sell.size} BTC`);
console.log(` Status: ${sell.status}`);
console.log("Done! Position should be flat.");
}
main().catch(console.error);