Async API client for Pocket Option platform
Project description
⚡ PocketOption API SDK (Unofficial)
🌐 Available languages: 🇬🇧 English | 🇷🇺 Русский
Asynchronous Python SDK for interacting with the PocketOption API (unofficial).
Fully type-hinted, built on pydantic, with middleware and event support.
Supports Python 3.13+ and is fully asynchronous (asyncio + aiohttp).
⚠️ Disclaimer
⚠️ This project is not a trading bot.
⚠️ It is not affiliated with PocketOption and is intended for integrations and analytical purposes only.
⚠️ Investing in financial instruments carries risks. Past performance does not guarantee future returns, and asset values may fluctuate due to market conditions and movements in underlying instruments. Any forecasts or illustrations are for informational purposes only and do not constitute guarantees or investment advice. This project is not an invitation or recommendation to invest. Before making investment decisions, consult financial, legal, and tax professionals to determine whether such products suit your goals, risk tolerance, and personal circumstances.
P.S. Their demo mode is surprisingly fun to play around with 😎
🚀 Features
-
🔌 Connects to PocketOption WebSocket API (via
socket.io) -
🔐 Session-based authentication
-
💹 Order and trade management (demo / real account)
-
📊 Market stream subscriptions
-
💾 Built-in in-memory storages (
MemoryCandleStorage,MemoryDealsStorage) -
⚙️ Middleware chain for event and request interception
-
💬 Event model with decorators (
@client.on.*) -
✅ Strict type hints
🔑 Getting Session ID and UID
To interact with the API, you need a valid session payload from the browser.
- Open Pocket Option in your browser
- Open Developer Tools
- Go to the Network tab
- Filter by WebSocket (WS)
- Find a request to {region}...
- Fimd message containing
42["auth" - Copy the
sessionanduid
Example:
42["auth",{"session":"abcd1234efgh5678","isDemo":1,"uid":1234589,"platform":1}]
⚙️ Usage Example
import asyncio
import os
import random
from pocket_option import PocketOptionClient
from pocket_option.constants import Regions
from pocket_option.contrib.candles import MemoryCandleStorage
from pocket_option.contrib.deals import MemoryDealsStorage
from pocket_option.models import (
Asset,
AuthorizationData,
ChangeAssetRequest,
DealAction,
SuccessAuthEvent,
UpdateCloseValueItem,
)
rnd = random.SystemRandom()
client = PocketOptionClient()
storage = MemoryCandleStorage(client)
deals = MemoryDealsStorage(client)
@client.on.connect
async def on_connect(data: None):
print("Success connected")
await client.emit.auth(
AuthorizationData.model_validate(
{
"session": os.environ["PO_SESSION"],
"isDemo": 1,
"uid": int(os.environ["PO_UID"]),
"platform": 2,
"isFastHistory": True,
"isOptimized": True,
},
),
)
@client.on.success_auth
async def on_success_auth(data: SuccessAuthEvent):
print("Success authorized with id %s", data.id)
await client.emit.indicator_load()
await client.emit.favorite_load()
await client.emit.price_alert_load()
await client.emit.subscribe_to_asset(Asset.AUDCAD_otc)
await client.emit.change_asset(ChangeAssetRequest(asset=Asset.AUDCAD_otc, period=30))
await client.emit.subscribe_for_market_sentiment(Asset.AUDCAD_otc)
@client.on.update_close_value
async def on_update_close_value(assets: list[UpdateCloseValueItem]):
print("Assets updated: ", assets)
def get_signal(storage: MemoryCandleStorage) -> DealAction | None:
# magic
return rnd.choice([DealAction.CALL, DealAction.PUT, None])
async def main():
await client.connect(Regions.DEMO)
while True:
direction = get_signal(storage)
if direction is None:
await asyncio.sleep(5)
continue
deal = await deals.open_deal(
asset=Asset.AUDCAD_otc,
amount=10,
action=direction,
is_demo=1,
option_type=100,
time=60,
)
print("✅ Opened deal:", deal)
result = await deals.check_deal_result(wait_time=60, deal=deal)
print("✅ Deal result:", result)
await asyncio.sleep(65)
asyncio.run(main())
📜 License
MIT License — do whatever you want, but at your own risk.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pocket_option-0.1.6.tar.gz.
File metadata
- Download URL: pocket_option-0.1.6.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.2 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86cefeff86190e26980df5e42a5c9012e1fea9226db7e268422128c5f62d7c4d
|
|
| MD5 |
58e60c318d65786d150cbc0bf856a9c0
|
|
| BLAKE2b-256 |
f29170096573c789ba5bd1c8984e2bcf01be6f1c1a570b3e9fae416b685bbace
|
File details
Details for the file pocket_option-0.1.6-py3-none-any.whl.
File metadata
- Download URL: pocket_option-0.1.6-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.2 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20a65409ef4595fe3d1f68a35f47f0cf06d94e8c54a3e2a752b29aafac3efd97
|
|
| MD5 |
6b8a0a79919d8f722398a762ac60d42e
|
|
| BLAKE2b-256 |
e25582ce0dc707515150249ee83fadc97b462143fb400a9522d576d0cbe0ada3
|