forked from ChipaDevTeam/PocketOptionAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_complete_ssid.py
More file actions
165 lines (121 loc) Β· 4.89 KB
/
test_complete_ssid.py
File metadata and controls
165 lines (121 loc) Β· 4.89 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""
Test script demonstrating complete SSID format handling
"""
import asyncio
import os
from pocketoptionapi_async import AsyncPocketOptionClient
async def test_complete_ssid_format():
"""Test the complete SSID format functionality"""
print("Testing Complete SSID Format Handling")
print("=" * 50)
# Test 1: Complete SSID format (what the user wants)
complete_ssid = r'42["auth",{"session":"n1p5ah5u8t9438rbunpgrq0hlq","isDemo":1,"uid":72645361,"platform":1,"isFastHistory":true}]'
print("π Testing with complete SSID format:")
print(f" SSID: {complete_ssid[:50]}...")
print()
try:
# Create client with complete SSID
client = AsyncPocketOptionClient(ssid=complete_ssid, is_demo=True)
# Check that the SSID is handled correctly
formatted_message = client._format_session_message()
print(" Client created successfully")
print(f"π€ Formatted message: {formatted_message[:50]}...")
print(f"π Session extracted: {getattr(client, 'session_id', 'N/A')[:20]}...")
print(f"π€ UID extracted: {client.uid}")
print(f"π·οΈ Platform: {client.platform}")
print(f"Demo mode: {client.is_demo}")
print(f"β‘ Fast history: {client.is_fast_history}")
# Test connection (will fail with test SSID but should show proper format)
print("\nTesting connection...")
try:
await client.connect()
if client.is_connected:
print(" Connected successfully!")
print(f"π Connection info: {client.connection_info}")
else:
print(" Connection failed (expected with test SSID)")
except Exception as e:
print(f" Connection error (expected): {str(e)[:100]}...")
await client.disconnect()
except Exception as e:
print(f"Error: {e}")
print("\n" + "=" * 50)
# Test 2: Raw session ID format (for comparison)
raw_session = "n1p5ah5u8t9438rbunpgrq0hlq"
print("π Testing with raw session ID:")
print(f" Session: {raw_session}")
print()
try:
# Create client with raw session
client2 = AsyncPocketOptionClient(
ssid=raw_session, is_demo=True, uid=72645361, platform=1
)
formatted_message2 = client2._format_session_message()
print(" Client created successfully")
print(f"π€ Formatted message: {formatted_message2[:50]}...")
print(f"π Session: {getattr(client2, 'session_id', 'N/A')}")
print(f"π€ UID: {client2.uid}")
print(f"π·οΈ Platform: {client2.platform}")
except Exception as e:
print(f"Error: {e}")
print("\n" + "=" * 50)
print(" SSID Format Tests Completed!")
async def test_real_connection():
"""Test with real SSID if available"""
print("\nTesting Real Connection (Optional)")
print("=" * 40)
# Check for real SSID in environment
real_ssid = os.getenv("POCKET_OPTION_SSID")
if not real_ssid:
print(" No real SSID found in environment variable POCKET_OPTION_SSID")
print(" Set it like this for real testing:")
print(
' export POCKET_OPTION_SSID=\'42["auth",{"session":"your_session","isDemo":1,"uid":your_uid,"platform":1}]\''
)
return
print(f"π Found real SSID: {real_ssid[:30]}...")
try:
client = AsyncPocketOptionClient(ssid=real_ssid)
print("Attempting real connection...")
await client.connect()
if client.is_connected:
print(" Successfully connected!")
# Test basic functionality
try:
balance = await client.get_balance()
print(f"Balance: ${balance.balance:.2f}")
# Test health status
health = await client.get_health_status()
print(f"π₯ Health: {health}")
except Exception as e:
print(f" API error: {e}")
else:
print("Connection failed")
await client.disconnect()
print("Disconnected")
except Exception as e:
print(f"Connection error: {e}")
async def main():
"""Main test function"""
print("PocketOption SSID Format Test Suite")
print("=" * 60)
print()
# Test SSID format handling
await test_complete_ssid_format()
# Test real connection if available
await test_real_connection()
print("\nπ All tests completed!")
print()
print("π Usage Examples:")
print("1. Complete SSID format (recommended):")
print(
' ssid = r\'42["auth",{"session":"your_session","isDemo":1,"uid":your_uid,"platform":1}]\''
)
print(" client = AsyncPocketOptionClient(ssid=ssid)")
print()
print("2. Raw session format:")
print(
' client = AsyncPocketOptionClient(ssid="your_session", uid=your_uid, is_demo=True)'
)
if __name__ == "__main__":
asyncio.run(main())