Python bindings for binary-options-tools. High-performance library for PocketOption trading automation with async/sync support, real-time data streaming, and WebSocket API access.
Project description
BinaryOptionsToolsV2 - Python Package
Python bindings for BinaryOptionsTools - A powerful library for automated binary options trading on PocketOption platform.
Current Status
Available Features:
- Authentication: Secure connection with automated SSID sanitization.
- Trading: Instant Buy/Sell operations with real-time result tracking.
- Account: Balance retrieval, opened/closed deals management.
- Market Data: Real-time candle subscriptions (tick to 300s), historical data fetching.
- Resilience: Automated asset gathering, payout synchronization, and robust reconnection logic.
- Advanced: Raw WebSocket handler API and custom message validators.
How to install
Install it via PyPI:
pip install binaryoptionstoolsv2
Supported OS
Currently supported on Windows, Linux, and macOS.
Supported Python versions
Supports Python 3.8 to 3.13.
Compile from source (Not recommended)
-
Make sure you have
rustandcargoinstalled (Check here) -
Install
maturinin order to compile the library -
Once the source is downloaded (using
git clone https://github.com/ChipaDevTeam/BinaryOptionsTools-v2.git) execute the following commands: To create the.whlfile
# Inside the root folder
cd BinaryOptionsToolsV2
maturin build -r
# Once the command is executed it should print a path to a .whl file, copy it and then run
pip install path/to/file.whl
To install the library in a local virtual environment
# Inside the root folder
cd BinaryOptionsToolsV2
# Activate the virtual environment if not done already
# Execute the following command and it should automatically install the library in the VM
maturin develop
Docs
Comprehensive Documentation for BinaryOptionsToolsV2
__init__.py
This file initializes the Python module and organizes the imports for both synchronous and asynchronous functionality.
Key Details
- Imports
BinaryOptionsToolsV2: Imports all elements and documentation from the Rust module. - Includes Submodules: Imports and exposes
pocketoptionandtracingmodules for user convenience.
Purpose
Serves as the entry point for the package, exposing all essential components of the library.
Inside the pocketoption folder there are 2 main files
asynchronous.py
This file implements the PocketOptionAsync class, which provides an asynchronous interface to interact with Pocket Option.
Key Features of PocketOptionAsync
- Trade Operations:
buy(): Places a buy trade asynchronously.sell(): Places a sell trade asynchronously.check_win(): Checks the outcome of a trade ('win', 'draw', or 'loss').
- Market Data:
get_candles(): Fetches historical candle data.history(): Retrieves recent data for a specific asset.compile_candles(): Compiles custom-period candlesticks from base candle data.
- Account Management:
balance(): Returns the current account balance.opened_deals(): Lists all open trades.closed_deals(): Lists all closed trades.payout(): Returns payout percentages.
- Real-Time Data:
subscribe_symbol(): Provides an asynchronous iterator for real-time candle updates.subscribe_symbol_timed(): Provides an asynchronous iterator for timed real-time candle updates.subscribe_symbol_chunked(): Provides an asynchronous iterator for chunked real-time candle updates.
- Server Information:
server_time(): Gets the current server time.
- Connection Management:
reconnect(): Manually reconnect to the server.shutdown(): Properly close the connection.
Helper Class - AsyncSubscription
Facilitates asynchronous iteration over live data streams, enabling non-blocking operations.
Example Usage
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main():
# Initialize the client
client = PocketOptionAsync(ssid="your-session-id")
# Get account balance
balance = await client.balance()
print(f"Account Balance: ${balance}")
# Place a buy trade
trade_id, deal = await client.buy("EURUSD_otc", 1.0, 60)
print(f"Trade placed: {deal}")
# Check result
result = await client.check_win(trade_id)
print(f"Trade result: {result}")
# Subscribe to real-time data
async for candle in client.subscribe_symbol("EURUSD_otc"):
print(f"New candle: {candle}")
break # Just print one candle for demo
asyncio.run(main())
synchronous.py
This file implements the PocketOption class, a synchronous wrapper around the asynchronous interface provided by PocketOptionAsync.
Key Features of PocketOption
- Trade Operations:
buy(): Places a buy trade using synchronous execution.sell(): Places a sell trade.check_win(): Checks the trade outcome synchronously.
- Market Data:
get_candles(): Fetches historical candle data.history(): Retrieves recent data for a specific asset.compile_candles(): Compiles custom-period candlesticks from base candle data.
- Account Management:
balance(): Retrieves account balance.opened_deals(): Lists all open trades.closed_deals(): Lists all closed trades.payout(): Returns payout percentages.
- Real-Time Data:
subscribe_symbol(): Provides a synchronous iterator for live data updates.subscribe_symbol_timed(): Provides a synchronous iterator for timed real-time candle updates.subscribe_symbol_chunked(): Provides a synchronous iterator for chunked real-time candle updates.
- Server Information:
server_time(): Gets the current server time.
- Connection Management:
reconnect(): Manually reconnect to the server.shutdown(): Properly close the connection.
Helper Class - SyncSubscription
Allows synchronous iteration over real-time data streams for compatibility with simpler scripts.
Example Usage
from BinaryOptionsToolsV2.pocketoption import PocketOption
import time
# Initialize the client
client = PocketOption(ssid="your-session-id")
# Get account balance
balance = client.balance()
print(f"Account Balance: ${balance}")
# Place a buy trade
trade_id, deal = client.buy("EURUSD_otc", 1.0, 60)
print(f"Trade placed: {deal}")
# Check result
result = client.check_win(trade_id)
print(f"Trade result: {result}")
# Subscribe to real-time data
stream = client.subscribe_symbol("EURUSD_otc")
for candle in stream:
print(f"New candle: {candle}")
break # Just print one candle for demo
- Differences Between PocketOption and PocketOptionAsync
| Feature | PocketOption (Synchronous) | PocketOptionAsync (Asynchronous) |
|---|---|---|
| Execution Type | Blocking | Non-blocking |
| Use Case | Simpler scripts | High-frequency or real-time tasks |
| Performance | Slower for concurrent tasks | Scales well with concurrent operations |
Tracing
The tracing module provides functionality to initialize and manage logging for the application.
Key Functions of Tracing
- start_logs():
- Initializes the logging system for the application.
- Arguments:
path(str): Path where log files will be stored.level(str): Logging level (default is "DEBUG").terminal(bool): Whether to display logs in the terminal (default is True).
- Returns: None
- Raises: Exception if there's an error starting the logging system.
Example Usage
from BinaryOptionsToolsV2.tracing import start_logs
# Initialize logging
start_logs(path="logs/", level="INFO", terminal=True)
📖 Detailed Examples
Basic Trading Example (Synchronous)
from BinaryOptionsToolsV2.pocketoption import PocketOption
import time
def main():
# Initialize client
client = PocketOption(ssid="your-session-id")
# Get balance
balance = client.balance()
print(f"Current Balance: ${balance}")
# Place a buy trade on EURUSD for 60 seconds with $1
trade_id, deal = client.buy(asset="EURUSD_otc", amount=1.0, time=60)
print(f"Trade ID: {trade_id}")
print(f"Deal Data: {deal}")
# Wait for trade to complete (60 seconds)
time.sleep(65)
# Check the result
result = client.check_win(trade_id)
print(f"Trade Result: {result['result']}") # 'win', 'loss', or 'draw'
print(f"Profit: ${result.get('profit', 0)}")
if __name__ == "__main__":
main()
Basic Trading Example (Asynchronous)
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main():
# Initialize client
client = PocketOptionAsync(ssid="your-session-id")
# Get balance
balance = await client.balance()
print(f"Current Balance: ${balance}")
# Place a buy trade on EURUSD for 60 seconds with $1
trade_id, deal = await client.buy(asset="EURUSD_otc", amount=1.0, time=60)
print(f"Trade ID: {trade_id}")
print(f"Deal Data: {deal}")
# Wait for trade to complete (60 seconds)
await asyncio.sleep(65)
# Check the result
result = await client.check_win(trade_id)
print(f"Trade Result: {result['result']}") # 'win', 'loss', or 'draw'
print(f"Profit: ${result.get('profit', 0)}")
if __name__ == "__main__":
asyncio.run(main())
Retrieving Historical Data
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main():
client = PocketOptionAsync(ssid="your-session-id")
# Fetch historical data (60s candles, starting from now)
# Note: get_candles takes (asset, period, offset)
candles = await client.get_candles("EURUSD_otc", 60, 0)
print(f"Retrieved {len(candles)} candles")
if candles:
print("Last candle:", candles[-1])
# Output format:
# {
# 'time': 1770428373,
# 'open': 1.22354,
# 'high': 1.22355,
# 'low': 1.22354,
# 'close': 1.22355
# }
if __name__ == "__main__":
asyncio.run(main())
Compiling Custom Period Candles
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main():
client = PocketOptionAsync(ssid="your-session-id")
# Compile 5-minute candles from 1-minute base data
# Parameters: asset, custom_period, lookback_period
candles = await client.compile_candles("EURUSD_otc", 60, 300)
print(f"Compiled {len(candles)} custom candles")
if candles:
print("Latest compiled candle:", candles[-1])
if __name__ == "__main__":
asyncio.run(main())
Real-Time Data Subscription (Synchronous)
from BinaryOptionsToolsV2.pocketoption import PocketOption
import time
def main():
client = PocketOption(ssid="your-session-id")
# Subscribe to real-time candle data
stream = client.subscribe_symbol("EURUSD_otc")
print("Listening for real-time candles...")
for candle in stream:
print(f"Time: {candle.get('time')}")
print(f"Open: {candle.get('open')}")
print(f"High: {candle.get('high')}")
print(f"Low: {candle.get('low')}")
print(f"Close: {candle.get('close')}")
print("---")
if __name__ == "__main__":
main()
Real-Time Data Subscription (Asynchronous)
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main():
client = PocketOptionAsync(ssid="your-session-id")
# Subscribe to real-time candle data
async for candle in client.subscribe_symbol("EURUSD_otc"):
print(f"Time: {candle.get('time')}")
print(f"Open: {candle.get('open')}")
print(f"High: {candle.get('high')}")
print(f"Low: {candle.get('low')}")
print(f"Close: {candle.get('close')}")
print("---")
if __name__ == "__main__":
asyncio.run(main())
Checking Opened Deals
from BinaryOptionsToolsV2.pocketoption import PocketOption
import time
def main():
client = PocketOption(ssid="your-session-id")
# Get all opened deals
opened_deals = client.opened_deals()
if opened_deals:
print(f"You have {len(opened_deals)} opened deals:")
for deal in opened_deals:
print(f" - Trade ID: {deal.get('id')}")
print(f" Asset: {deal.get('asset')}")
print(f" Amount: ${deal.get('amount')}")
print(f" Direction: {deal.get('action')}")
else:
print("No opened deals")
if __name__ == "__main__":
main()
🔑 Important Notes
Connection Initialization
The client automatically establishes a connection during initialization. You can also manually manage the connection using connect(), disconnect(), and reconnect() methods.
# Asynchronous
client = PocketOptionAsync(ssid="your-session-id")
# Connection is already established here
# Manual control
await client.disconnect()
await client.connect()
# Synchronous
client_sync = PocketOption(ssid="your-session-id")
# Connection is already established here
# Manual control
client_sync.disconnect()
client_sync.connect()
Getting Your SSID
- Go to PocketOption
- Open Developer Tools (F12)
- Go to Application/Storage → Cookies
- Find the cookie named
ssid - Copy its value
Supported Assets
Common assets include:
EURUSD_otc- Euro/US Dollar (OTC)GBPUSD_otc- British Pound/US Dollar (OTC)USDJPY_otc- US Dollar/Japanese Yen (OTC)AUDUSD_otc- Australian Dollar/US Dollar (OTC)- And many more...
Use _otc suffix for over-the-counter (24/7 available) assets.
📚 Additional Resources
- Full Examples: docs/examples/python
- API Documentation: https://chipadevteam.github.io/BinaryOptionsTools-v2/python.html
- Discord Community: Join us
⚠️ Risk Warning
Trading binary options involves substantial risk and may result in the loss of all invested capital. This library is provided for educational purposes only. Always trade responsibly and never invest more than you can afford to lose.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 binaryoptionstoolsv2-0.2.9.tar.gz.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9.tar.gz
- Upload date:
- Size: 285.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d741c69161d4e319656a1697e846077378e824658b3f6fe8927f2db757edcb8
|
|
| MD5 |
c38efaf0aa3d030da3da1fe57a6a9c03
|
|
| BLAKE2b-256 |
6b2aebfed62c778746f66e7b92e1c32d630d08a4a45ad7aefb50f402c454df89
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ae7b7d57ba28de6ed23ea880d19a77cf58ef2192af4d10eaedf45f751cc232a
|
|
| MD5 |
572a94787a4fc0b0b5be79106fd1498e
|
|
| BLAKE2b-256 |
f8cec55c3722483a4e0dc4a80e4caacae3b702572804138d74069cfa16557b17
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-win32.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-win32.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.9+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7867bdbbfb57989360c40cef05fb3fd7d8c834c159f375ae802a08257c8ae04d
|
|
| MD5 |
9bc4d6043a0a963aec689148990e38bf
|
|
| BLAKE2b-256 |
943654ef6d3bd3cbaa907db5c48c9a54ce5651e1b86fc6a0e8b67df8df7217e3
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.9+, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8569ed6dad3d41be74e6e4aec7a92a4ce50faf5c29730e245cd4cf5ec38c856
|
|
| MD5 |
3d56c43d8cf58a0213e7b26d0d9a2b6e
|
|
| BLAKE2b-256 |
6dc57b7d9c76116569aa247d248b9ef3746e41ac05eaa84ece69c9ed46986cd0
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-musllinux_1_1_aarch64.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-musllinux_1_1_aarch64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.9+, musllinux: musl 1.1+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d962ff6ec5023bfa56fbd15f5936d11a5c4969be4fcfe5af95d5226ada0a9bcb
|
|
| MD5 |
1ffaaf4bfd74e57becac5c7e5723be6c
|
|
| BLAKE2b-256 |
d3b5c639e0a44a4274df3a651e419362a1518e23cc8abc03b5a5636c89a2b628
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a5c10a8e3a1427096effc8a6eb8a0c489e5a9f0bb2b3ff1139bb612d75a0221
|
|
| MD5 |
05a11d8d88ce2dd857fe3251bea7da08
|
|
| BLAKE2b-256 |
03a663c1ea945cce4212005a24178d6412ade26afc256be386a6d35aac322521
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-manylinux_2_28_armv7l.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-manylinux_2_28_armv7l.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ba636fba6adde3440cd24af72b48ea7a838b60c951a87260dbdefc395adadbe
|
|
| MD5 |
4be50072da40f860a19670a09b046668
|
|
| BLAKE2b-256 |
33636c7f51b3f9653ea49f6d3f39e4d86a0854d30d98bfc818828e0c11d78223
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e71d792b2a1d2fdac51becabb5897671f788d30eb8c0542c15c9ec977bdc6a3
|
|
| MD5 |
92330d8c54bbb04dcfd723ffe4973238
|
|
| BLAKE2b-256 |
8297c19e6300f35b954b8502dbbe06080c9a11d1f2c903d32b6b22738b19123f
|
File details
Details for the file binaryoptionstoolsv2-0.2.9-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: binaryoptionstoolsv2-0.2.9-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 6.8 MB
- Tags: CPython 3.9+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de48e5377818e02892e4bdbb79f6db162d949295837482867a8d38ff23b13b3d
|
|
| MD5 |
895126d8ae1d8fffd8baa00ff8bbe58d
|
|
| BLAKE2b-256 |
9463284eda253221fee77b0b9eb5cf25207bab35ea2dc2028e76af08c13fe8e0
|