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 rust and cargo installed (Check here)
-
Install maturin in 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 .whl file
cd BinaryOptionsToolsV2
maturin build -r
pip install path/to/file.whl
To install the library in a local virtual environment
cd BinaryOptionsToolsV2
maturin develop
Docs
Comprehensive Documentation for BinaryOptionsToolsV2
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
pocketoption and tracing modules 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
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():
client = PocketOptionAsync(ssid="your-session-id")
balance = await client.balance()
print(f"Account Balance: ${balance}")
trade_id, deal = await client.buy("EURUSD_otc", 1.0, 60)
print(f"Trade placed: {deal}")
result = await client.check_win(trade_id)
print(f"Trade result: {result}")
async for candle in client.subscribe_symbol("EURUSD_otc"):
print(f"New candle: {candle}")
break
asyncio.run(main())
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
client = PocketOption(ssid="your-session-id")
balance = client.balance()
print(f"Account Balance: ${balance}")
trade_id, deal = client.buy("EURUSD_otc", 1.0, 60)
print(f"Trade placed: {deal}")
result = client.check_win(trade_id)
print(f"Trade result: {result}")
stream = client.subscribe_symbol("EURUSD_otc")
for candle in stream:
print(f"New candle: {candle}")
break
- Differences Between PocketOption and PocketOptionAsync
| 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
start_logs(path="logs/", level="INFO", terminal=True)
📖 Detailed Examples
Basic Trading Example (Synchronous)
from BinaryOptionsToolsV2.pocketoption import PocketOption
import time
def main():
client = PocketOption(ssid="your-session-id")
balance = client.balance()
print(f"Current Balance: ${balance}")
trade_id, deal = client.buy(asset="EURUSD_otc", amount=1.0, time=60)
print(f"Trade ID: {trade_id}")
print(f"Deal Data: {deal}")
time.sleep(65)
result = client.check_win(trade_id)
print(f"Trade Result: {result['result']}")
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():
client = PocketOptionAsync(ssid="your-session-id")
balance = await client.balance()
print(f"Current Balance: ${balance}")
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}")
await asyncio.sleep(65)
result = await client.check_win(trade_id)
print(f"Trade Result: {result['result']}")
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")
candles = await client.get_candles("EURUSD_otc", 60, 0)
print(f"Retrieved {len(candles)} candles")
if candles:
print("Last candle:", candles[-1])
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")
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")
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")
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")
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.
client = PocketOptionAsync(ssid="your-session-id")
await client.disconnect()
await client.connect()
client_sync = PocketOption(ssid="your-session-id")
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
⚠️ 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.