|
| 1 | +""" |
| 2 | +Example demonstrating the correct way to use SSID with PocketOption API |
| 3 | +
|
| 4 | +This example shows how to: |
| 5 | +1. Get the correct SSID format from browser |
| 6 | +2. Initialize the client properly |
| 7 | +3. Handle authentication errors |
| 8 | +""" |
| 9 | + |
| 10 | +import asyncio |
| 11 | +from pocketoptionapi_async import AsyncPocketOptionClient |
| 12 | +from pocketoptionapi_async.exceptions import InvalidParameterError, AuthenticationError |
| 13 | + |
| 14 | + |
| 15 | +async def main(): |
| 16 | + print("=" * 70) |
| 17 | + print("PocketOption API - Correct SSID Usage Example") |
| 18 | + print("=" * 70) |
| 19 | + |
| 20 | + print("\n📋 INSTRUCTIONS:") |
| 21 | + print("1. Open PocketOption in your browser (https://pocketoption.com)") |
| 22 | + print("2. Press F12 to open Developer Tools") |
| 23 | + print("3. Go to the Network tab") |
| 24 | + print("4. Filter by 'WS' (WebSocket)") |
| 25 | + print("5. Look for a message starting with: 42[\"auth\",") |
| 26 | + print("6. Copy the ENTIRE message (including 42[\"auth\",{...}])") |
| 27 | + print("\n") |
| 28 | + |
| 29 | + # Example of CORRECT SSID format |
| 30 | + print("✅ CORRECT SSID format:") |
| 31 | + print(' 42["auth",{"session":"your_session_here","isDemo":1,"uid":12345,"platform":1}]') |
| 32 | + print("\n") |
| 33 | + |
| 34 | + # Example of WRONG format |
| 35 | + print("❌ WRONG SSID format (just the session ID):") |
| 36 | + print(' dxxxxxxxxxxxxxxxxxxxxxxxxxxxx') |
| 37 | + print("\n") |
| 38 | + |
| 39 | + # Get SSID from user |
| 40 | + ssid_input = input("Enter your SSID (or press Enter to see demo): ").strip() |
| 41 | + |
| 42 | + if not ssid_input: |
| 43 | + print("\n📝 Using demo SSID to show validation...") |
| 44 | + ssid_input = '42["auth",{"session":"demo_session_id","isDemo":1,"uid":12345,"platform":1}]' |
| 45 | + |
| 46 | + print("\n" + "=" * 70) |
| 47 | + |
| 48 | + try: |
| 49 | + print("🔧 Initializing PocketOption client...") |
| 50 | + |
| 51 | + # Create client with SSID |
| 52 | + client = AsyncPocketOptionClient( |
| 53 | + ssid=ssid_input, |
| 54 | + is_demo=True, # Set to False for live trading |
| 55 | + enable_logging=True # Set to False to reduce console output |
| 56 | + ) |
| 57 | + |
| 58 | + print("✅ Client initialized successfully!") |
| 59 | + print(f" Session ID: {client.session_id[:20]}...") |
| 60 | + print(f" User ID: {client.uid}") |
| 61 | + print(f" Demo mode: {client.is_demo}") |
| 62 | + print("\n") |
| 63 | + |
| 64 | + # Try to connect |
| 65 | + print("🔌 Connecting to PocketOption...") |
| 66 | + connected = await client.connect() |
| 67 | + |
| 68 | + if connected: |
| 69 | + print("✅ Connected successfully!") |
| 70 | + |
| 71 | + # Get balance |
| 72 | + try: |
| 73 | + balance = await client.get_balance() |
| 74 | + print(f"💰 Balance: {balance.balance} {balance.currency}") |
| 75 | + except Exception as e: |
| 76 | + print(f"⚠️ Could not get balance: {e}") |
| 77 | + |
| 78 | + # Disconnect |
| 79 | + await client.disconnect() |
| 80 | + print("✅ Disconnected successfully") |
| 81 | + |
| 82 | + else: |
| 83 | + print("❌ Connection failed") |
| 84 | + print("\n💡 Troubleshooting:") |
| 85 | + print(" • Make sure your SSID is in the correct format") |
| 86 | + print(" • Your SSID might be expired - get a fresh one from browser") |
| 87 | + print(" • Make sure you copied the ENTIRE message including 42[\"auth\",{...}]") |
| 88 | + |
| 89 | + except InvalidParameterError as e: |
| 90 | + print(f"\n❌ SSID Format Error:") |
| 91 | + print(f" {e}") |
| 92 | + print("\n💡 Make sure you're using the complete SSID format from browser DevTools!") |
| 93 | + |
| 94 | + except AuthenticationError as e: |
| 95 | + print(f"\n❌ Authentication Error:") |
| 96 | + print(f" {e}") |
| 97 | + print("\n💡 Your SSID might be expired. Get a fresh one from your browser!") |
| 98 | + |
| 99 | + except Exception as e: |
| 100 | + print(f"\n❌ Unexpected Error:") |
| 101 | + print(f" {type(e).__name__}: {e}") |
| 102 | + |
| 103 | + print("\n" + "=" * 70) |
| 104 | + |
| 105 | + |
| 106 | +if __name__ == "__main__": |
| 107 | + asyncio.run(main()) |
0 commit comments