-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathschedule_cancel.py
More file actions
58 lines (42 loc) · 1.57 KB
/
schedule_cancel.py
File metadata and controls
58 lines (42 loc) · 1.57 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
#!/usr/bin/env python3
"""
Schedule Cancel Example (Dead Man's Switch)
Schedule automatic cancellation of all orders after a delay.
If you don't send another schedule_cancel before the time expires,
all your orders are cancelled. Useful as a safety mechanism.
NOTE: Requires $1M trading volume on your account to use this feature.
Requirements:
pip install hyperliquid-sdk
Usage:
export PRIVATE_KEY="0x..."
python schedule_cancel.py
"""
import os
import sys
import time
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 Schedule Cancel Example")
print("=" * 50)
sdk = HyperliquidSDK(private_key=PRIVATE_KEY)
print(f"Address: {sdk.address}")
# Schedule cancel all orders in 60 seconds
# cancel_time = int(time.time() * 1000) + 60000 # 60 seconds from now
# result = sdk.schedule_cancel(cancel_time)
# print(f"Scheduled cancel at {cancel_time}: {result}")
# To cancel the scheduled cancel (keep orders alive):
# result = sdk.schedule_cancel(None)
# print(f"Cancelled scheduled cancel: {result}")
print()
print("Schedule cancel methods available:")
print(" sdk.schedule_cancel(time_ms) # Schedule cancel at timestamp")
print(" sdk.schedule_cancel(None) # Cancel the scheduled cancel")
print()
print("NOTE: Requires $1M trading volume on your account")
if __name__ == "__main__":
main()