-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathroundtrip.py
More file actions
52 lines (37 loc) · 1.12 KB
/
roundtrip.py
File metadata and controls
52 lines (37 loc) · 1.12 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
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""
Round Trip Example
Complete trade cycle: buy then sell to end up flat.
Requirements:
pip install hyperliquid-sdk
Usage:
export PRIVATE_KEY="0x..."
python roundtrip.py
"""
import os
import sys
from hyperliquid_sdk import HyperliquidSDK
PRIVATE_KEY = os.environ.get("PRIVATE_KEY")
if not PRIVATE_KEY:
print("Error: Set PRIVATE_KEY environment variable")
print(" export PRIVATE_KEY='0xYourPrivateKey'")
sys.exit(1)
def main():
print("Hyperliquid Round Trip Example")
print("=" * 50)
sdk = HyperliquidSDK(private_key=PRIVATE_KEY)
print(f"Address: {sdk.address}")
# Buy $11 worth of BTC
print("Buying BTC...")
buy = sdk.market_buy("BTC", notional=11)
filled_size = buy.filled_size or buy.size
print(f" Bought: {filled_size} BTC")
print(f" Status: {buy.status}")
# Sell the same amount
print("Selling BTC...")
sell = sdk.market_sell("BTC", size=filled_size)
print(f" Sold: {sell.filled_size or sell.size} BTC")
print(f" Status: {sell.status}")
print("Done! Position should be flat.")
if __name__ == "__main__":
main()