Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
61aa091
Merge pull request #5 from theshadow76/Add-client-py-header
theshadow76 Feb 17, 2024
34cb5a0
Update README.md
theshadow76 Feb 21, 2024
8da59f0
Create FUNDING.yml
theshadow76 Feb 25, 2024
3b91b43
Update README.md
theshadow76 Mar 8, 2024
d4b932e
Update README.md
theshadow76 Mar 8, 2024
4ef3eee
cfghjn
theshadow76 Mar 8, 2024
8b94098
Update README.md
theshadow76 Apr 7, 2024
cfb51dc
dhwahdwa
theshadow76 Apr 11, 2024
b159434
Update client_test.py
theshadow76 Apr 11, 2024
97749c9
Add files via upload
chema2411 Apr 11, 2024
ea7bc01
Merge pull request #9 from chema2411/main
theshadow76 Apr 11, 2024
4957615
little update
theshadow76 Apr 11, 2024
b6f2a3a
update
theshadow76 Apr 11, 2024
9e5d7b6
dsesed
theshadow76 Apr 11, 2024
18b22ef
gb
theshadow76 Apr 11, 2024
00b4e6d
Add files via upload
chema2411 Apr 12, 2024
29f8516
Merge pull request #10 from chema2411/main
theshadow76 Apr 12, 2024
d2d904b
test
theshadow76 Apr 12, 2024
d4087fa
hhjjj
theshadow76 Apr 12, 2024
caf6bc2
Merge branch 'main' of https://github.com/theshadow76/PocketOptionAPI
theshadow76 Apr 12, 2024
3f7322c
dawdwa
theshadow76 Apr 12, 2024
2074940
Update README.md
theshadow76 May 6, 2024
ab30caa
Update README.md
theshadow76 May 6, 2024
817d3e8
Update README.md
theshadow76 May 7, 2024
9da91a0
Updated buying and connections
theshadow76 May 7, 2024
bee9487
added v2
theshadow76 Jun 9, 2024
b53b388
dsvs
theshadow76 Jun 9, 2024
332cc1a
w
theshadow76 Jun 9, 2024
d658ae0
Update
theshadow76 Jun 9, 2024
fbe8616
fsefs
theshadow76 Jun 9, 2024
16d47ea
dhsfs
theshadow76 Jun 17, 2024
2fd7180
fesbf
theshadow76 Jun 21, 2024
7fad350
hewdwb
theshadow76 Jun 21, 2024
3a4010c
fssf
theshadow76 Jun 21, 2024
46fc4f7
sfeesf
theshadow76 Jun 21, 2024
7a8e318
fsefesf
theshadow76 Jun 22, 2024
8cde0af
Update
theshadow76 Aug 24, 2024
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
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: theshadow76
custom: ['https://paypal.me/shadowtechsc?country.x=CL&locale.x=es_XC]'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
env
pocket.log
pocket.log
.env
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# Pocket Option API
# Pocket Option API

In development!

for a better understanding, check this [link](https://github.com/theshadow76/PocketOptionAPI/issues/4)

# help me

you can donate here: [paypal](https://paypal.me/shadowtechsc?country.x=CL&locale.x=es_XC)

or my BTC adress: bc1qmvpmpdt96vmgq3s3rh3gzxf75eml52r2d7sclw

By donating you are helping me make this project better!
14 changes: 8 additions & 6 deletions client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
import anyio
from rich.pretty import pprint as print
import json
from pocketoptionapi.constants import REGION

SESSION = r'42["auth",{"session":"a:4:{s:10:\"session_id\";s:32:\"da7a5a82c8f6c35a87b2ee31d4f5b3b4\";s:10:\"ip_address\";s:10:\"90.36.9.15\";s:10:\"user_agent\";s:120:\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OP\";s:13:\"last_activity\";i:1707667599;}3a0058a58a6df5e7b49f652f8e4f8249","isDemo":1,"uid":27658142,"platform":1}]'
SESSION = 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":0,"uid":27658142,"platform":1}]'


async def websocket_client(url, pro):
while True:
for i in REGION.get_regions(REGION):
print(f"Trying {i}...")
try:
async with websockets.connect(
url,
i, #teoria de los issues
extra_headers={
"Origin": "https://pocket-link19.co",
# "Origin": "https://po.trade/"
#"Origin": "https://pocket-link19.co",
"Origin": "https://po.trade/"
},
) as websocket:
async for message in websocket:
Expand All @@ -23,7 +25,7 @@ async def websocket_client(url, pro):
except Exception as e:
print(e)
print("Connection lost... reconnecting")
await anyio.sleep(5)
# await anyio.sleep(5)
return True


Expand Down
4 changes: 3 additions & 1 deletion docs/todo.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# todo

### Add login system
- Not Done
- Not Done

-- updated
Empty file added pocketoptionapi/_.py
Empty file.
Binary file modified pocketoptionapi/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified pocketoptionapi/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/api.cpython-310.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/api.cpython-311.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/api.cpython-312.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/api.cpython-37.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/api.cpython-38.pyc
Binary file not shown.
Binary file added pocketoptionapi/__pycache__/api.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file modified pocketoptionapi/__pycache__/constants.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
298 changes: 298 additions & 0 deletions pocketoptionapi/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
"""Module for Pocket Option API."""
import asyncio
import datetime
import time
import json
import logging
import threading
import requests
import ssl
import atexit
from collections import deque
from pocketoptionapi.ws.client import WebsocketClient
from pocketoptionapi.ws.channels.get_balances import *

from pocketoptionapi.ws.channels.ssid import Ssid
# from pocketoptionapi.ws.channels.subscribe import *
# from pocketoptionapi.ws.channels.unsubscribe import *
# from pocketoptionapi.ws.channels.setactives import SetActives
from pocketoptionapi.ws.channels.candles import GetCandles
# from pocketoptionapi.ws.channels.buyv2 import Buyv2
from pocketoptionapi.ws.channels.buyv3 import *
# from pocketoptionapi.ws.channels.user import *
# from pocketoptionapi.ws.channels.api_game_betinfo import Game_betinfo
# from pocketoptionapi.ws.channels.instruments import Get_instruments
# from pocketoptionapi.ws.channels.get_financial_information import GetFinancialInformation
# from pocketoptionapi.ws.channels.strike_list import Strike_list
# from pocketoptionapi.ws.channels.leaderboard import Leader_Board

# from pocketoptionapi.ws.channels.traders_mood import Traders_mood_subscribe
# from pocketoptionapi.ws.channels.traders_mood import Traders_mood_unsubscribe
# from pocketoptionapi.ws.channels.buy_place_order_temp import Buy_place_order_temp
# from pocketoptionapi.ws.channels.get_order import Get_order
# from pocketoptionapi.ws.channels.get_deferred_orders import GetDeferredOrders
# from pocketoptionapi.ws.channels.get_positions import *

# from pocketoptionapi.ws.channels.get_available_leverages import Get_available_leverages
# from pocketoptionapi.ws.channels.cancel_order import Cancel_order
# from pocketoptionapi.ws.channels.close_position import Close_position
# from pocketoptionapi.ws.channels.get_overnight_fee import Get_overnight_fee
# from pocketoptionapi.ws.channels.heartbeat import Heartbeat

# from pocketoptionapi.ws.channels.digital_option import *
# from pocketoptionapi.ws.channels.api_game_getoptions import *
# from pocketoptionapi.ws.channels.sell_option import Sell_Option
# from pocketoptionapi.ws.channels.change_tpsl import Change_Tpsl
# from pocketoptionapi.ws.channels.change_auto_margin_call import ChangeAutoMarginCall

from pocketoptionapi.ws.objects.timesync import TimeSync
# from pocketoptionapi.ws.objects.profile import Profile
from pocketoptionapi.ws.objects.candles import Candles
# from pocketoptionapi.ws.objects.listinfodata import ListInfoData
# from pocketoptionapi.ws.objects.betinfo import Game_betinfo_data
import pocketoptionapi.global_value as global_value
from pocketoptionapi.ws.channels.change_symbol import ChangeSymbol
from collections import defaultdict
from pocketoptionapi.ws.objects.time_sync import TimeSynchronizer


def nested_dict(n, type):
if n == 1:
return defaultdict(type)
else:
return defaultdict(lambda: nested_dict(n - 1, type))


# InsecureRequestWarning: Unverified HTTPS request is being made.
# Adding certificate verification is strongly advised.
# See: https://urllib3.readthedocs.org/en/latest/security.html


class PocketOptionAPI(object): # pylint: disable=too-many-instance-attributes
"""Class for communication with Pocket Option API."""

# pylint: disable=too-many-public-methods
socket_option_opened = {}
time_sync = TimeSync()
sync = TimeSynchronizer()
timesync = None
# pylint: disable=too-many-arguments
# profile = Profile()
candles = Candles()
# listinfodata = ListInfoData()
api_option_init_all_result = []
api_option_init_all_result_v2 = []
# for digital
underlying_list_data = None
position_changed = None
instrument_quites_generated_data = nested_dict(2, dict)
instrument_quotes_generated_raw_data = nested_dict(2, dict)
instrument_quites_generated_timestamp = nested_dict(2, dict)
strike_list = None
leaderboard_deals_client = None
# position_changed_data = nested_dict(2, dict)
# microserviceName_binary_options_name_option=nested_dict(2,dict)
order_async = None
# game_betinfo = Game_betinfo_data()
instruments = None
financial_information = None
buy_id = None
buy_order_id = None
traders_mood = {} # get hight(put) %
order_data = None
positions = None
position = None
deferred_orders = None
position_history = None
position_history_v2 = None
available_leverages = None
order_canceled = None
close_position_data = None
overnight_fee = None
# ---for real time
digital_option_placed_id = None
live_deal_data = nested_dict(3, deque)

subscribe_commission_changed_data = nested_dict(2, dict)
real_time_candles = nested_dict(3, dict)
real_time_candles_maxdict_table = nested_dict(2, dict)
candle_generated_check = nested_dict(2, dict)
candle_generated_all_size_check = nested_dict(1, dict)
# ---for api_game_getoptions_result
api_game_getoptions_result = None
sold_options_respond = None
tpsl_changed_respond = None
auto_margin_call_changed_respond = None
top_assets_updated_data = {}
get_options_v2_data = None
# --for binary option multi buy
buy_multi_result = None
buy_multi_option = {}
#
result = None
training_balance_reset_request = None
balances_raw = None
user_profile_client = None
leaderboard_userinfo_deals_client = None
users_availability = None
history_data = None
historyNew = None
server_timestamp = None
sync_datetime = None

# ------------------

def __init__(self, proxies=None):
"""
:param dict proxies: (optional) The http request proxies.
"""
self.websocket_client = None
self.websocket_thread = None
# self.wss_url = "wss://api-us-north.po.market/socket.io/?EIO=4&transport=websocket"
self.session = requests.Session()
self.session.verify = False
self.session.trust_env = False
self.proxies = proxies
# is used to determine if a buyOrder was set or failed. If
# it is None, there had been no buy order yet or just send.
# If it is false, the last failed
# If it is true, the last buy order was successful
self.buy_successful = None
self.loop = asyncio.get_event_loop()
self.websocket_client = WebsocketClient(self)

@property
def websocket(self):
"""Property to get websocket.

:returns: The instance of :class:`WebSocket <websocket.WebSocket>`.
"""
return self.websocket_client

def send_websocket_request(self, name, msg, request_id="", no_force_send=True):
"""Send websocket request to IQ Option server.

:param no_force_send:
:param request_id:
:param str name: The websocket request name.
:param dict msg: The websocket request msg.
"""

logger = logging.getLogger(__name__)

# data = json.dumps(dict(name=name, msg=msg, request_id=request_id))
data = f'42{json.dumps(msg)}'

while (global_value.ssl_Mutual_exclusion or global_value.ssl_Mutual_exclusion_write) and no_force_send:
pass
global_value.ssl_Mutual_exclusion_write = True

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

# Ejecutar la corutina connect dentro del bucle de eventos del nuevo hilo
loop.run_until_complete(self.websocket.send_message(data))

logger.debug(data)
global_value.ssl_Mutual_exclusion_write = False

def start_websocket(self):
global_value.websocket_is_connected = False
global_value.check_websocket_if_error = False
global_value.websocket_error_reason = None

# Obtener o crear un nuevo bucle de eventos para este hilo
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

# Ejecutar la corutina connect dentro del bucle de eventos del nuevo hilo
loop.run_until_complete(self.websocket.connect())
loop.run_forever()

while True:
try:
if global_value.check_websocket_if_error:
return False, global_value.websocket_error_reason
if global_value.websocket_is_connected is False:
return False, "Websocket connection closed."
elif global_value.websocket_is_connected is True:
return True, None

except:
pass
pass

def connect(self):
"""Method for connection to Pocket Option API."""

global_value.ssl_Mutual_exclusion = False
global_value.ssl_Mutual_exclusion_write = False

check_websocket, websocket_reason = self.start_websocket()

if not check_websocket:
return check_websocket, websocket_reason

self.time_sync.server_timestamps = None
while True:
try:
if self.time_sync.server_timestamps is not None:
break
except:
pass
return True, None

async def close(self, error=None):
await self.websocket.on_close(error)
self.websocket_thread.join()

def websocket_alive(self):
return self.websocket_thread.is_alive()

@property
def get_balances(self):
"""Property for get IQ Option http getprofile resource.

:returns: The instance of :class:`Login
<iqoptionapi.http.getprofile.Getprofile>`.
"""
return Get_Balances(self)

# ____________for_______binary_______option_____________

@property
def buyv3(self):
return Buyv3(self)

@property
def getcandles(self):
"""Property for get IQ Option websocket candles chanel.

:returns: The instance of :class:`GetCandles
<pocketoptionapi.ws.channels.candles.GetCandles>`.
"""
return GetCandles(self)

@property
def change_symbol(self):
"""Property for get Pocket Option websocket change_symbol chanel.

:returns: The instance of :class:`ChangeSymbol
<iqoptionapi.ws.channels.change_symbol.ChangeSymbol>`.
"""
return ChangeSymbol(self)

@property
def synced_datetime(self):
try:
if self.time_sync is not None:
self.sync.synchronize(self.time_sync.server_timestamp)
self.sync_datetime = self.sync.get_synced_datetime()
else:
logging.error("timesync no está establecido")
self.sync_datetime = None
except Exception as e:
logging.error(e)
self.sync_datetime = None

return self.sync_datetime
Binary file modified pocketoptionapi/backend/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified pocketoptionapi/backend/ws/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified pocketoptionapi/backend/ws/__pycache__/client.cpython-311.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions pocketoptionapi/backend/ws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ async def websocket_client(self, url, pro):
async with websockets.connect(
url,
extra_headers={
"Origin": "https://pocket-link19.co",
# "Origin": "https://po.trade/"
# "Origin": "https://pocket-link19.co",
"Origin": "https://po.trade/"
},
) as websocket:
async for message in websocket:
Expand Down
Loading