-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcancel_order.py
More file actions
53 lines (37 loc) · 1.1 KB
/
cancel_order.py
File metadata and controls
53 lines (37 loc) · 1.1 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
#!/usr/bin/env python3
"""
Cancel Order Example
Place an order and then cancel it by OID.
Requirements:
pip install hyperliquid-sdk
Usage:
export PRIVATE_KEY="0x..."
python cancel_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 Cancel 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 3% below mid
limit_price = int(mid * 0.97)
order = sdk.buy("BTC", notional=11, price=limit_price, tif="gtc")
print(f"Placed order OID: {order.oid}")
# Cancel using the order object
order.cancel()
print("Cancelled via order.cancel()")
# Alternative: cancel by OID directly
# sdk.cancel(12345, "BTC")
if __name__ == "__main__":
main()