-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear_trade_states.py
More file actions
42 lines (35 loc) · 1.12 KB
/
clear_trade_states.py
File metadata and controls
42 lines (35 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
#!/usr/bin/env python3
"""
Clear all trade states from Redis
"""
import os
import redis
# Connect to Redis
redis_host = os.getenv('REDIS_HOST', 'localhost')
redis_port = int(os.getenv('REDIS_PORT', 6379))
redis_db = int(os.getenv('REDIS_DB', 0))
client = redis.Redis(
host=redis_host,
port=redis_port,
db=redis_db,
decode_responses=True
)
print(f"Connected to Redis at {redis_host}:{redis_port}/{redis_db}")
# Find all trade_state keys
trade_state_keys = client.keys('trade_state:*')
active_keys = client.keys('trade_states:*:active')
symbols_keys = client.keys('trade_states:*:symbols')
all_keys = trade_state_keys + active_keys + symbols_keys
print(f"\nFound {len(all_keys)} keys to delete:")
print(f" - {len(trade_state_keys)} trade_state keys")
print(f" - {len(active_keys)} active index keys")
print(f" - {len(symbols_keys)} symbols index keys")
if all_keys:
confirm = input("\nDelete all these keys? (yes/no): ")
if confirm.lower() == 'yes':
deleted = client.delete(*all_keys)
print(f"\n✓ Deleted {deleted} keys")
else:
print("\nCancelled")
else:
print("\nNo keys to delete")