Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,44 +107,3 @@ To get the correct SSID:
5. Look for a message that starts with `42["auth",`
6. Copy the **entire message** including the `42["auth",{...}]` part

### Websockets version error

## Traceback:
```
2025-07-13 15:25:16.531 | INFO | pocketoptionapi_async.client:__init__:130 - Initialized PocketOption client (demo=True, uid=105754921, persistent=False) with enhanced monitoring
2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:connect:162 - Connecting to PocketOption...
2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:_start_regular_connection:187 - Starting regular connection...
2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:_start_regular_connection:198 - Demo mode: Using demo regions: ['DEMO', 'DEMO_2']
2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.client:_start_regular_connection:219 - Trying region: DEMO with URL: wss://demo-api-eu.po.market/socket.io/?EIO=4&transport=websocket
2025-07-13 15:25:16.532 | INFO | pocketoptionapi_async.websocket_client:connect:162 - Attempting to connect to wss://demo-api-eu.po.market/socket.io/?EIO=4&transport=websocket
2025-07-13 15:25:16.556 | WARNING | pocketoptionapi_async.websocket_client:connect:206 - Failed to connect to wss://demo-api-eu.po.market/socket.io/?EIO=4&transport=websocket: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers'
2025-07-13 15:25:16.556 | WARNING | pocketoptionapi_async.client:_start_regular_connection:242 - Failed to connect to region DEMO: Failed to connect to any WebSocket endpoint
2025-07-13 15:25:16.556 | INFO | pocketoptionapi_async.client:_start_regular_connection:219 - Trying region: DEMO_2 with URL: wss://try-demo-eu.po.market/socket.io/?EIO=4&transport=websocket
2025-07-13 15:25:16.556 | INFO | pocketoptionapi_async.websocket_client:connect:162 - Attempting to connect to wss://try-demo-eu.po.market/socket.io/?EIO=4&transport=websocket
2025-07-13 15:25:16.558 | WARNING | pocketoptionapi_async.websocket_client:connect:206 - Failed to connect to wss://try-demo-eu.po.market/socket.io/?EIO=4&transport=websocket: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers'
2025-07-13 15:25:16.558 | WARNING | pocketoptionapi_async.client:_start_regular_connection:242 - Failed to connect to region DEMO_2: Failed to connect to any WebSocket endpoint
Traceback (most recent call last):
File "/Users/vigowalker/Downloads/resurgenthavoc_bot/test1.py", line 20, in <module>
asyncio.run(main())
File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/vigowalker/Downloads/resurgenthavoc_bot/test1.py", line 9, in main
account_info = await client.get_balance()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vigowalker/Downloads/resurgenthavoc_bot/.conda/lib/python3.11/site-packages/pocketoptionapi_async/client.py", line 376, in get_balance
raise ConnectionError("Not connected to PocketOption")
pocketoptionapi_async.exceptions.ConnectionError: Not connected to PocketOption
```

to fix this error, run this commands:
```
pip uninstall websockets
pip install websockets==11.0
```
7 changes: 1 addition & 6 deletions docs/termux-setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,8 @@ <h3>7. Run Your First Script</h3>
<p>If everything is configured correctly, you should see your account balance displayed.</p>
</div>

<div class="card">
<div class="card">
<h3>Common Issues and Solutions</h3>
<h4>WebSocket Connection Error</h4>
<p>If you encounter a WebSocket connection error with <code>extra_headers</code>, fix it by:</p>
<pre><code>pip uninstall websockets
pip install websockets==11.0</code></pre>

<h4>Permission Denied Errors</h4>
<p>If you get permission errors when installing packages:</p>
<pre><code>termux-setup-storage</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion pocketoptionapi_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# Create REGIONS instance
REGIONS = Regions()

__version__ = "2.0.0"
__version__ = "2.0.1"
__author__ = "PocketOptionAPI Team"

__all__ = [
Expand Down
7 changes: 4 additions & 3 deletions pocketoptionapi_async/connection_keep_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from typing import Optional, List, Callable, Dict, Any
from datetime import datetime, timedelta
from loguru import logger

import websockets.legacy.client
from websockets.exceptions import ConnectionClosed
from websockets.legacy.client import connect, WebSocketClientProtocol

from models import ConnectionInfo, ConnectionStatus
from constants import REGIONS
Comment on lines 13 to 14
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if other files in the package use relative imports consistently
rg -n "^from (models|constants) import" pocketoptionapi_async/

Repository: ChipaDevTeam/PocketOptionAPI

Length of output: 253


🏁 Script executed:

# List the structure of pocketoptionapi_async to see what modules exist
ls -la pocketoptionapi_async/ | head -20

Repository: ChipaDevTeam/PocketOptionAPI

Length of output: 908


🏁 Script executed:

# Check if models.py and constants.py exist in the directory
fd "^(models|constants)\.py$" pocketoptionapi_async/

Repository: ChipaDevTeam/PocketOptionAPI

Length of output: 138


🏁 Script executed:

# Check how other files in pocketoptionapi_async import from these modules
rg -n "from.*models import|from.*constants import" pocketoptionapi_async/ -A 1

Repository: ChipaDevTeam/PocketOptionAPI

Length of output: 1234


Relative imports missing leading dot.

The imports from models import ... and from constants import ... will fail when this module is imported as part of the pocketoptionapi_async package. All other files in the package use relative imports with a leading dot. They should be:

🐛 Proposed fix
-from models import ConnectionInfo, ConnectionStatus
-from constants import REGIONS
+from .models import ConnectionInfo, ConnectionStatus
+from .constants import REGIONS
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from models import ConnectionInfo, ConnectionStatus
from constants import REGIONS
from .models import ConnectionInfo, ConnectionStatus
from .constants import REGIONS
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pocketoptionapi_async/connection_keep_alive.py` around lines 13 - 14, The
imports at the top of connection_keep_alive.py are absolute and will break when
imported as part of the pocketoptionapi_async package; change the two import
statements to use package-relative imports (i.e., import ConnectionInfo and
ConnectionStatus from .models and REGIONS from .constants) so they match the
rest of the package's style and resolve correctly at runtime; update the import
lines that currently reference models and constants to use a leading dot.

Expand All @@ -23,7 +24,7 @@ def __init__(self, ssid: str, is_demo: bool = True):
self.is_demo = is_demo

# Connection state
self.websocket: Optional[WebSocketClientProtocol] = None
self.websocket: Optional[websockets.legacy.client.WebSocketClientProtocol] = None
self.connection_info: Optional[ConnectionInfo] = None
self.is_connected = False
self.should_reconnect = True
Expand Down Expand Up @@ -138,7 +139,7 @@ async def _establish_connection(self) -> bool:

# Connect with headers (like old API)
self.websocket = await asyncio.wait_for(
connect(
websockets.legacy.client.connect(
url,
ssl=ssl_context,
extra_headers={
Expand Down
11 changes: 6 additions & 5 deletions pocketoptionapi_async/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from typing import Optional, Callable, Dict, Any, List, Deque
from datetime import datetime
from collections import deque
import websockets

import websockets.legacy.client
from websockets.exceptions import ConnectionClosed
from websockets.legacy.client import WebSocketClientProtocol

from loguru import logger

from .models import ConnectionInfo, ConnectionStatus, ServerTime
Expand Down Expand Up @@ -63,7 +64,7 @@ class ConnectionPool:
"""Connection pool for better resource management"""

def __init__(self, max_connections: int = 3):
self.active_connections: Dict[str, WebSocketClientProtocol] = {}
self.active_connections: Dict[str, websockets.legacy.client.WebSocketClientProtocol] = {}
self.connection_stats: Dict[str, Dict[str, Any]] = {}
self._pool_lock = asyncio.Lock()

Expand Down Expand Up @@ -120,7 +121,7 @@ class AsyncWebSocketClient:
"""

def __init__(self):
self.websocket: Optional[WebSocketClientProtocol] = None
self.websocket: Optional[websockets.legacy.client.WebSocketClientProtocol] = None
self.connection_info: Optional[ConnectionInfo] = None
self.server_time: Optional[ServerTime] = None
self._ping_task: Optional[asyncio.Task] = None
Expand Down Expand Up @@ -169,7 +170,7 @@ async def connect(self, urls: List[str], ssid: str) -> bool:

# Connect with timeout
ws = await asyncio.wait_for(
websockets.connect(
websockets.legacy.client.connect(
url,
ssl=ssl_context,
extra_headers=DEFAULT_HEADERS,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [
]
dependencies = [
"aiohttp>=3.8.0",
"websockets>=11.0.0",
"websockets>=12.0",
"asyncio",
"python-dotenv>=1.0.0",
"tzlocal>=4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp>=3.8.0
websockets>=11.0.0
websockets>=12.0
asyncio
python-dotenv>=1.0.0
tzlocal>=4.0.0
Expand Down
4 changes: 2 additions & 2 deletions tools/client_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import websockets
import anyio
import websockets.legacy.client
from rich.pretty import pprint as print
from pocketoptionapi_async.constants import REGIONS

Expand All @@ -12,7 +12,7 @@ async def websocket_client(url, pro):
for i in region_urls:
print(f"Trying {i}...")
try:
async with websockets.connect(
async with websockets.legacy.client.connect(
i,
extra_headers={
"Origin": "https://pocketoption.com/" # main URL
Expand Down