forked from ChipaDevTeam/PocketOptionAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_order_tracking_fix.py
More file actions
144 lines (113 loc) Β· 4.57 KB
/
test_order_tracking_fix.py
File metadata and controls
144 lines (113 loc) Β· 4.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
Test Order Tracking Fix
Test to verify that order tracking and result checking works properly
"""
import asyncio
import os
from datetime import datetime
from loguru import logger
from pocketoptionapi_async import AsyncPocketOptionClient, OrderDirection
async def test_order_tracking():
"""Test order tracking functionality"""
# Get SSID from environment or use placeholder
ssid = os.getenv("POCKET_OPTION_SSID", "your_session_id_here")
if ssid == "your_session_id_here":
print("Please set POCKET_OPTION_SSID environment variable")
return
print("Testing Order Tracking Fix...")
# Create client
client = AsyncPocketOptionClient(ssid, is_demo=True)
try:
# Connect
print("π‘ Connecting...")
await client.connect()
if not client.is_connected:
print("Failed to connect")
return
print(" Connected successfully")
# Wait for initialization
await asyncio.sleep(3)
# Get balance
balance = await client.get_balance()
if balance:
print(f"Balance: ${balance.balance:.2f} (Demo: {balance.is_demo})")
else:
print("No balance received")
# Place a test order
print("\nPlacing test order...")
order_result = await client.place_order(
asset="EURUSD_otc", amount=1.0, direction=OrderDirection.CALL, duration=60
)
print(f"Order placed: {order_result.order_id}")
print(f" Status: {order_result.status}")
print(f" Asset: {order_result.asset}")
print(f" Amount: ${order_result.amount}")
print(f" Direction: {order_result.direction}")
print(f" Duration: {order_result.duration}s")
# Test order result checking - should return the active order immediately
print("\nπ Checking order result immediately...")
immediate_result = await client.check_order_result(order_result.order_id)
if immediate_result:
print(" Order found in tracking system:")
print(f" Order ID: {immediate_result.order_id}")
print(f" Status: {immediate_result.status}")
print(f" Placed at: {immediate_result.placed_at}")
print(f" Expires at: {immediate_result.expires_at}")
else:
print("Order NOT found in tracking system")
return
# Check active orders
print("\nπ Checking active orders...")
active_orders = await client.get_active_orders()
print(f"Active orders count: {len(active_orders)}")
for order in active_orders:
print(f" - {order.order_id}: {order.status} ({order.asset})")
# Test tracking over time
print("\nβ±οΈ Monitoring order for 30 seconds...")
start_time = datetime.now()
while (datetime.now() - start_time).total_seconds() < 30:
result = await client.check_order_result(order_result.order_id)
if result:
status_emoji = (
"π’"
if result.status == "active"
else "π΄"
if result.status in ["win", "lose"]
else "π‘"
)
print(f" {status_emoji} Order {result.order_id}: {result.status}")
# If order completed, show result
if result.profit is not None:
win_lose = "WIN" if result.profit > 0 else "LOSE"
print(f" Final result: {win_lose} - Profit: ${result.profit:.2f}")
break
else:
print(" Order not found in tracking")
break
await asyncio.sleep(5) # Check every 5 seconds
# Final status
final_result = await client.check_order_result(order_result.order_id)
if final_result:
print(f"\nπ Final order status: {final_result.status}")
if final_result.profit is not None:
print(f"Profit/Loss: ${final_result.profit:.2f}")
else:
print("Profit/Loss: Not yet determined")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
finally:
# Disconnect
print("\nDisconnecting...")
await client.disconnect()
print(" Test completed")
if __name__ == "__main__":
# Configure logging
logger.remove()
logger.add(
lambda msg: print(msg, end=""),
format="<level>{level}</level> | {message}",
level="INFO",
)
asyncio.run(test_order_tracking())