-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathleverage.ts
More file actions
37 lines (29 loc) · 1.04 KB
/
leverage.ts
File metadata and controls
37 lines (29 loc) · 1.04 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
#!/usr/bin/env npx ts-node
// @ts-nocheck
/**
* Leverage Example
*
* Update leverage for a position.
*
* Requires: PRIVATE_KEY environment variable
*/
import { HyperliquidSDK } from '@quicknode/hyperliquid-sdk';
const PRIVATE_KEY = process.env.PRIVATE_KEY;
if (!PRIVATE_KEY) {
console.error("Set PRIVATE_KEY environment variable");
console.error("Example: export PRIVATE_KEY='0x...'");
process.exit(1);
}
async function main() {
const sdk = new HyperliquidSDK(undefined, { privateKey: PRIVATE_KEY });
console.log(`Wallet: ${sdk.address}`);
// Update leverage for BTC to 10x cross margin
const result = await sdk.updateLeverage("BTC", 10, true);
console.log(`Update leverage result: ${JSON.stringify(result)}`);
// Update leverage for ETH to 5x isolated margin
// const result = await sdk.updateLeverage("ETH", 5, false);
// console.log(`Update leverage result: ${JSON.stringify(result)}`);
console.log("\nLeverage methods available:");
console.log(" sdk.updateLeverage(asset, leverage, isCross)");
}
main().catch(console.error);