Skip to main content

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

Discord Python

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

# 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

  1. __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 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

  1. 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())
  1. 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
  1. 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

  1. Go to PocketOption
  2. Open Developer Tools (F12)
  3. Go to Application/Storage → Cookies
  4. Find the cookie named ssid
  5. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pocketoption_tools-0.2.10-cp39-abi3-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

pocketoption_tools-0.2.10-cp39-abi3-win32.whl (3.0 MB view details)

Uploaded CPython 3.9+Windows x86

pocketoption_tools-0.2.10-cp39-abi3-musllinux_1_1_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ x86-64

pocketoption_tools-0.2.10-cp39-abi3-musllinux_1_1_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ ARM64

pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_armv7l.whl (3.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARMv7l

pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

pocketoption_tools-0.2.10-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (6.7 MB view details)

Uploaded CPython 3.9+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 41f4454a4316813d18883935902b47e2cdaf07ff5976cbf60acccb60d1bcd8f6
MD5 22e4f8379e6e650479e83527767e6e25
BLAKE2b-256 899e680ef326c08daec368240a85a7ce89dfbdfeb1dd811cc83cacf3a131224e

See more details on using hashes here.

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-win32.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 46cd0ebaa4cc558987e0e1ab8e27ba76dd8315c604d2c855b30de6f574798b72
MD5 de353ee7a9799cf6a558660e0a235575
BLAKE2b-256 dee6be023b0ec0b7bbe9dc23964931781e7e2bc6686fa754697b05df98a823c7

See more details on using hashes here.

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8635ed4eff275c0cb85eec4a5d95504751b56f3f7d3d0fd6ee4997abcd23d5aa
MD5 401e26c989676ce7bea5942461841d3d
BLAKE2b-256 046ca952a438f52f78374a822426da212eea70dc425671916a653d1d0a214875

See more details on using hashes here.

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 1955cff21019da7a08f4aa0f6c79f824ce811d49cb5d6944e5c6e132fb6583aa
MD5 93bf66ed4759fbb9c57b0debeb89907f
BLAKE2b-256 53779b8aa2780f35c5beae67e419559eb15c56ef27b430acb6d98d002a850a75

See more details on using hashes here.

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e52f19f5e1ca07a7b195b46c1603f5d76f63dc6d6b1fe290a40251c5eae7eab1
MD5 a69ce4ad54d54d47b2eb64b58b344c0a
BLAKE2b-256 b1c3b0f31c87e3646d9487c3a0b443b5a1c30b6e95145b1220b937af377cfbd9

See more details on using hashes here.

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_armv7l.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 2d17e4b42c1e40039889e85a13809436bfbe8a70af4c7ea43b7ad8b972f5e170
MD5 3f39c54634d07aa80f99de87aa54ac51
BLAKE2b-256 53be7f8ac2a3b46dfaddfed68ab143df366ac6cbd2af10529b423ba66db84dab

See more details on using hashes here.

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c9a14a0ae774fde76168bf996f6e91e6975c9b014faca869950f401346832117
MD5 566822435a9244e27501e26745ae62a2
BLAKE2b-256 c0cade881f486c53f4eb7e99ee92fc4ec893ce5c611595fa20c207c3dc107ffe

See more details on using hashes here.

File details

Details for the file pocketoption_tools-0.2.10-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pocketoption_tools-0.2.10-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 cfa5c286e20ac6171434879f65dfcacfd1034b5fe43f0267f297e7dca7ff5cca
MD5 687a7453577a458790b60a0f58a11aaa
BLAKE2b-256 e6062505b2bdd6cf26b98546fb8346b18d239fd780ccf6c6e1bf4efc7e9f5022

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page