-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodify_order.py
More file actions
57 lines (41 loc) · 1.23 KB
/
modify_order.py
File metadata and controls
57 lines (41 loc) · 1.23 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
#!/usr/bin/env python3
"""
Modify Order Example
Place a resting order and then modify its price.
Requirements:
pip install hyperliquid-sdk
Usage:
export PRIVATE_KEY="0x..."
python modify_order.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 Modify Order Example")
print("=" * 50)
sdk = HyperliquidSDK(private_key=PRIVATE_KEY)
print(f"Address: {sdk.address}")
# Get current price
mid = sdk.get_mid("BTC")
print(f"BTC mid price: ${mid:,.2f}")
# Place a resting order
limit_price = int(mid * 0.97)
order = sdk.buy("BTC", notional=11, price=limit_price, tif="gtc")
print(f"Placed order at ${limit_price:,}")
print(f" OID: {order.oid}")
# Modify to a new price (4% below mid)
new_price = int(mid * 0.96)
new_order = order.modify(price=new_price)
print(f"Modified to ${new_price:,}")
print(f" New OID: {new_order.oid}")
# Clean up
new_order.cancel()
print("Order cancelled.")
if __name__ == "__main__":
main()