-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfluent_builder.py
More file actions
87 lines (70 loc) · 2.22 KB
/
fluent_builder.py
File metadata and controls
87 lines (70 loc) · 2.22 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
"""
Fluent Order Builder Example
For power users who want maximum control with IDE autocomplete.
Requirements:
pip install hyperliquid-sdk
Usage:
export PRIVATE_KEY="0x..."
python fluent_builder.py
"""
import os
import sys
from hyperliquid_sdk import HyperliquidSDK, Order
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 Fluent Order Builder Example")
print("=" * 50)
sdk = HyperliquidSDK(private_key=PRIVATE_KEY)
mid = sdk.get_mid("BTC")
print(f"BTC mid price: ${mid:,.2f}")
# Simple limit order with GTC (Good Till Cancelled) - minimum $10 value
# Use size directly to ensure proper decimal precision (BTC allows 5 decimals)
order = sdk.order(
Order.buy("BTC")
.size(0.00017) # ~$11 worth at ~$65k (minimum is $10)
.price(int(mid * 0.97))
.gtc()
)
print(f"Limit GTC: {order}")
order.cancel()
# Market order by notional value
# order = sdk.order(
# Order.sell("ETH")
# .notional(10)
# .market()
# )
# print(f"Market: {order}")
# Reduce-only order (only closes existing position)
# order = sdk.order(
# Order.sell("BTC")
# .size(0.001)
# .price(int(mid * 1.03))
# .gtc()
# .reduce_only()
# )
# print(f"Reduce-only: {order}")
# ALO order (Add Liquidity Only / Post-Only)
# order = sdk.order(
# Order.buy("BTC")
# .size(0.001)
# .price(int(mid * 0.95))
# .alo()
# )
# print(f"Post-only: {order}")
print()
print("Fluent builder methods:")
print(" .size(0.001) - Set size in asset units")
print(" .notional(100) - Set size in USD")
print(" .price(65000) - Set limit price")
print(" .gtc() - Good Till Cancelled")
print(" .ioc() - Immediate Or Cancel")
print(" .alo() - Add Liquidity Only (post-only)")
print(" .market() - Market order")
print(" .reduce_only() - Only close position")
if __name__ == "__main__":
main()