-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_darwin_status.py
More file actions
executable file
·74 lines (59 loc) · 2.13 KB
/
test_darwin_status.py
File metadata and controls
executable file
·74 lines (59 loc) · 2.13 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
#!/usr/bin/env python3
"""
Test script for Darwin status with enhanced connection tracking
"""
import sys
import time
import logging
from pprint import pprint
from directa_api.trading import DirectaTrading
# Setup logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger('test_darwin_status')
def test_darwin_status(host="127.0.0.1", port=10002):
"""
Test the Darwin status functionality with multiple connection attempts
"""
print(f"Testing Darwin status on {host}:{port}...")
# Create trading instance
trading = DirectaTrading(host=host, port=port)
# First attempt to connect
print("\n=== First connection attempt ===")
connected = trading.connect()
print(f"Connected: {connected}")
if connected:
# Check Darwin status
print("\n=== Initial status check ===")
status = trading.get_darwin_status()
print("Darwin Status:")
pprint(status)
# Disconnect and reconnect to generate connection history
print("\n=== Disconnecting... ===")
trading.disconnect()
# Wait a moment
time.sleep(1)
# Second connection attempt
print("\n=== Second connection attempt ===")
connected = trading.connect()
print(f"Connected: {connected}")
# Check Darwin status again
if connected:
print("\n=== Status after reconnection ===")
status = trading.get_darwin_status()
print("Darwin Status:")
pprint(status)
# Show connection metrics
print("\n=== Connection Metrics ===")
metrics = trading.get_connection_metrics()
pprint(metrics)
# Clean up
trading.disconnect()
print("\nTest completed.")
if __name__ == "__main__":
# Use command line arguments for host/port if provided
host = sys.argv[1] if len(sys.argv) > 1 else "127.0.0.1"
port = int(sys.argv[2]) if len(sys.argv) > 2 else 10002
test_darwin_status(host, port)