- Overview
- Features
- Installation
- Configuration
- Quick Start
- Usage Examples
- Advanced Strategies
- Session & SSID Management
- Logging & Monitoring
- Testing
- Troubleshooting
- Contributing
- License
- Contact
- Disclaimer
Pocket Option API is a professional, fully asynchronous WebSocket API client for the Pocket Option broker. It is built for high-frequency, robust, and scalable trading bots, research tools, and automated strategies.
Key capabilities:
- Live & demo trading
- Real-time candles and tickers
- Listing available assets and payout rates
- Full trade lifecycle management (place, monitor, result)
- Automated login and session handling (including CAPTCHA)
- Asynchronous Python: Utilizes modern
asynciofor high performance and low latency. - Automatic CAPTCHA Handling: Selenium-based login with integrated Recaptcha solver.
- Robust WebSocket Client: Automatic reconnect, keep-alive pings, and multi-region fallback.
- Real-time Market Data: Subscribe to candles, ticks, and asset updates.
- Type-safe Models: Built with Pydantic for data validation and auto-completion.
- Comprehensive Logging: Configurable logging via Loguru, with daily rotating logs.
- Session Management: Secure storage of SSID and credentials for demo and live accounts.
- Flexible Configuration: Environment variables or config files for timeouts, regions, and more.
# Clone the repository
git clone https://github.com/A11ksa/-API-Pocket-Option.git
cd -API-Pocket-Option
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install package
pip install .Ensure you have Google Chrome installed for auto-login and CAPTCHA solving.
-
Credentials & SSID: On first run, the library will open Chrome, perform login, solve CAPTCHA, and extract SSID.
- Credentials are stored in
sessions/config.json. - Session data (SSID) is saved in
sessions/session.json.
- Credentials are stored in
-
Environment Variables: You may override defaults via a
.envfile or environment variables:POCKET_EMAIL,POCKET_PASSWORDPING_INTERVAL,DEFAULT_TIMEOUT,LOG_LEVEL, etc.
-
Manual SSID: To skip auto-login, manually extract your SSID from browser DevTools and place it in
sessions/session.json:
{
"live": "YOUR_SESSION_ID",
"demo": "YOUR_DEMO_SESSION_ID"
}import asyncio
from api_pocket import AsyncPocketOptionClient, OrderDirection, get_ssid
async def main():
# Retrieve SSID (auto-login)
ssid = get_ssid(email="you@example.com", password="YourPassword")
client = AsyncPocketOptionClient(ssid=ssid["demo"], is_demo=True)
await client.connect()
balance = await client.get_balance()
print(f"Balance: {balance.balance} {balance.currency}")
assets = await client.get_available_assets()
for symbol, info in assets.items():
print(symbol, "→ payout:", info.payout)
# Place a 1-minute CALL order
order = await client.place_order(
asset="EURUSD_otc",
amount=10.0,
direction=OrderDirection.CALL,
duration=60
)
print("Order placed, ID:", order.order_id)
# Wait for result (no arbitrary timeout)
result = await client.check_win(order.order_id)
print("Trade finished:", result)
await client.disconnect()
if __name__ == "__main__":
asyncio.run(main())See test4.py for a full demonstration of all basic features. This script walks through login, balance retrieval, asset listing, order placement, and result fetching.
Integrate with custom signal sources (e.g., Telegram, WebSocket feeds) to build automated bots:
async def run_signal_bot(signal_queue):
ssid = get_ssid(email="...")["demo"]
client = AsyncPocketOptionClient(ssid=ssid, is_demo=True)
await client.connect()
while True:
signal = await signal_queue.get()
order = await client.place_order(
asset=signal.asset,
amount=signal.amount,
direction=OrderDirection.CALL if signal.side == "CALL" else OrderDirection.PUT,
duration=signal.duration
)
print(f"Executed: {order.asset} {order.direction}")
result = await client.check_win(order.order_id)
print("Result:", result)- First Run: Auto-login to generate session.
- Subsequent Runs: Uses saved session until expired.
- Switching Accounts: Update
sessions/config.jsonwith new credentials.
- Logs are stored at
log-YYYY-MM-DD.txt. - Control verbosity with
LOG_LEVEL(e.g.,DEBUG,INFO,ERROR). - Enable advanced health checks in
api_pocket/monitoring.py.
Run the example script:
python test4.pyEnsure all operations complete without errors.
- Chrome fails to launch: Verify Chrome installation and
webdriver-managercompatibility. - Captcha solver hangs: Solve manually or increase timeout.
- WebSocket errors: Check your network; try changing region in config.
- Order not placed: Ensure asset is open and sufficient balance.
For further help, open an issue on GitHub.
Contributions are welcome! Please:
- Fork the repository.
- Create a feature branch.
- Write tests and ensure formatting.
- Submit a Pull Request.
Follow existing code style and PEP8 guidelines.
This project is licensed under the MIT License. See LICENSE for details.
- Author: Ahmed (ar123ksa@gmail.com)
- Telegram: @A11ksa
This library is for educational and research purposes. Not affiliated with Pocket Option. Trading involves risk — use at your own discretion.