Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

Commit 9e5d7b6

Browse files
committed
dsesed
1 parent b6f2a3a commit 9e5d7b6

5 files changed

Lines changed: 30 additions & 11 deletions

File tree

223 Bytes
Binary file not shown.

pocketoptionapi/stable_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# from pocketoptionapi.expiration import get_expiration_time, get_remaning_time
1818
import pandas as pd
1919
from pocketoptionapi.ws.chanels.get_balances import *
20+
from pocketoptionapi.ws.client import WebsocketClient
2021

2122
# Obtener la zona horaria local del sistema como una cadena en el formato IANA
2223
local_zone_name = get_localzone()
@@ -103,6 +104,8 @@ def connect(self):
103104
return False
104105
return True
105106

107+
async def reconect(self):
108+
await WebsocketClient(self).reconnect()
106109
@staticmethod
107110
def check_connect():
108111
# True/False
162 Bytes
Binary file not shown.

pocketoptionapi/ws/client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import logging
88
import ssl
9-
9+
import time
1010
# Suponiendo la existencia de estos módulos basados en tu código original
1111
import pocketoptionapi.constants as OP_code
1212
import pocketoptionapi.global_value as global_value
@@ -63,8 +63,7 @@ async def reconnect(self):
6363
regs = self.region.get_regions()
6464
for i in regs:
6565
print(f"Reconnecting to {i}...")
66-
async with websockets.connect(i, extra_headers={"Origin": "https://m.pocketoption.com"}) as ws:
67-
66+
async with websockets.connect(i, extra_headers={"Origin": "https://m.pocketoption.com "}) as ws:
6867
print("Conectado a: ", i)
6968
self.websocket = ws
7069
self.url = i
@@ -140,6 +139,7 @@ async def on_message(self, message): # pylint: disable=unused-argument
140139
# global_value.ssl_Mutual_exclusion = True
141140
logger = logging.getLogger(__name__)
142141
logger.debug(message)
142+
print(message)
143143

144144
# message = json.loads(str(message))
145145

@@ -203,7 +203,8 @@ async def on_message(self, message): # pylint: disable=unused-argument
203203
await self.websocket.send("3")
204204

205205
elif message.startswith('40{"sid":"'):
206-
# print(f"{self.url.split('/')[2]} got 40 sid send session")
206+
print(f"{self.url.split('/')[2]} got 40 sid send session")
207+
print(f"send: {self.ssid}")
207208
await self.websocket.send(self.ssid)
208209

209210
elif message.startswith('451-['):
@@ -245,7 +246,7 @@ async def on_error(self, error): # pylint: disable=unused-argument
245246
logger = logging.getLogger(__name__)
246247
logger.error(error)
247248
try:
248-
self.reconnect()
249+
await self.reconnect()
249250
except:
250251
global_value.websocket_error_reason = str(error)
251252
global_value.check_websocket_if_error = True
@@ -255,6 +256,6 @@ async def on_close(self, error): # pylint: disable=unused-argument
255256
logger = logging.getLogger(__name__)
256257
logger.debug("Websocket connection closed.")
257258
try:
258-
self.reconnect()
259+
await self.reconnect()
259260
except:
260261
global_value.websocket_is_connected = False

test.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
import random
22
import time
33
import dotenv
4+
import asyncio
45
from pocketoptionapi.stable_api import PocketOption
56
import os
67
dotenv.load_dotenv()
7-
ssid = os.getenv("SSID")
8-
api = PocketOption(ssid)
9-
print(ssid)
8+
SSID=(r'42["auth",{"session":"a:4:{s:10:"session_id";s:32:"a1dc009a7f1f0c8267d940d0a036156f";s:10:"ip_address";s:12:"190.162.4.33";s:10:"user_agent";s:120:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 OP";s:13:"last_activity";i:1709914958;}793884e7bccc89ec798c06ef1279fcf2","isDemo":1,"uid":27658142,"platform":1}]')
9+
api = PocketOption(SSID)
10+
print(SSID)
1011

1112
def direction():
1213
# Selecciona aleatoriamente entre 'call' y 'put'
1314
return random.choice(['call', 'put'])
1415

15-
if __name__ == "__main__":
16+
def main():
1617
api.connect()
17-
time.sleep(2)
18+
19+
max_retries = 5
20+
for _ in range(max_retries):
21+
time.sleep(5)
22+
try:
23+
asyncio.run(api.reconect())
24+
except:
25+
pass
26+
if api.check_connect():
27+
break # Exit loop if connected
28+
else:
29+
print("Failed to connect after max retries")
30+
31+
if __name__ == '__main__':
32+
main()

0 commit comments

Comments
 (0)