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

Option A: Install from Source (Recommended)

# Clone from GitHub
git clone https://github.com/ChipaDevTeam/BinaryOptionsTools-v2.git
# Or clone from GitLab
# git clone https://gitlab.chipatrade.com/chipadevorg/BinaryOptionsTools-v2.git

cd BinaryOptionsTools-v2/python
git fetch --tags
git checkout "$(git tag -l --sort=-v:refname | head -n 1)"
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install .

Option B: Install from Source Automatically

Requires git, a C toolchain, and a Rust toolchain.

uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
# Install via GitHub
uv pip install "git+https://github.com/ChipaDevTeam/BinaryOptionsTools-v2.git@master#subdirectory=python"
# Or install via GitLab
# uv pip install "git+https://gitlab.chipatrade.com/chipadevorg/BinaryOptionsTools-v2.git@master#subdirectory=python"

Supported OS

Currently supported on Windows, Linux, and macOS.

Supported Python versions

Supports Python 3.8 to 3.13.

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:
    • candles() / get_candles(): Fetches and manually compiles historical candle data from 1-second ticks strictly on UTC boundaries to avoid server-side gaps/overlaps.
    • history(): Retrieves recent data for a specific asset (delegates to candles()).
    • compile_candles(): Compiles custom-period candlesticks from base tick data using strict UTC boundaries.
  • 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.
  • Pending Orders:
    • open_pending_order(): Places a pending limit order.
    • cancel_pending_order(): Cancels a specific pending order by ticket ID.
    • cancel_pending_orders(): Cancels multiple pending orders in a batch.
    • get_pending_deals(): Lists all active pending orders.
    • get_pending_deal(): Retrieves details of a specific pending order.
  • Server Information:
    • server_time(): Gets the current server time.
  • Connection Management:
    • reconnect(): Manually reconnect to the server.
    • shutdown(): Properly close the connection.
  • Advanced / Utilities:
    • wait_for_assets(): Awaits until the assets list is fully loaded from the server.
    • is_demo(): Returns whether the current session is a demo account.
    • is_connected(): Returns connection status.
    • create_raw_handler(): Sets up direct raw WebSocket message listeners with custom validators. 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:
    • candles() / get_candles(): Fetches and manually compiles historical candle data from 1-second ticks strictly on UTC boundaries to avoid server-side gaps/overlaps ("merges").
    • history(): Retrieves recent data for a specific asset (delegates to candles()).
    • compile_candles(): Compiles custom-period candlesticks from base tick data using strict UTC boundaries.
  • 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.
  • Pending Orders:
    • open_pending_order(): Places a pending limit order.
    • cancel_pending_order(): Cancels a specific pending order by ticket ID.
    • cancel_pending_orders(): Cancels multiple pending orders in a batch.
    • get_pending_deals(): Lists all active pending orders.
    • get_pending_deal(): Retrieves details of a specific pending order.
  • Server Information:
    • server_time(): Gets the current server time.
  • Connection Management:
    • reconnect(): Manually reconnect to the server.
    • shutdown(): Properly close the connection.
  • Advanced / Utilities:
    • wait_for_assets(): Awaits until the assets list is fully loaded from the server.
    • is_demo(): Returns whether the current session is a demo account.
    • is_connected(): Returns connection status.
    • create_raw_handler(): Sets up direct raw WebSocket message listeners with custom validators. 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 Distribution

binaryoptionstoolsv2-0.2.13.tar.gz (261.1 kB view details)

Uploaded Source

Built Distributions

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

binaryoptionstoolsv2-0.2.13-cp310-abi3-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

binaryoptionstoolsv2-0.2.13-cp310-abi3-win32.whl (3.3 MB view details)

Uploaded CPython 3.10+Windows x86

binaryoptionstoolsv2-0.2.13-cp310-abi3-musllinux_1_1_x86_64.whl (3.7 MB view details)

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

binaryoptionstoolsv2-0.2.13-cp310-abi3-musllinux_1_1_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.1+ ARM64

binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_x86_64.whl (3.7 MB view details)

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

binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_armv7l.whl (3.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARMv7l

binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

binaryoptionstoolsv2-0.2.13-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.2 MB view details)

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

File details

Details for the file binaryoptionstoolsv2-0.2.13.tar.gz.

File metadata

  • Download URL: binaryoptionstoolsv2-0.2.13.tar.gz
  • Upload date:
  • Size: 261.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for binaryoptionstoolsv2-0.2.13.tar.gz
Algorithm Hash digest
SHA256 d23938d40f3cef25df347d70cbbe21be0196fa8e6133eaaa800e6a3caec86918
MD5 ed54145f1c2a2841ec8be3b5344b6c16
BLAKE2b-256 8678f344b544e0e3551b94ea89d17b9c9544dc338e886e308a4cc5826e2fbbe7

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d06bfc3adee1e5b0908dbf5e6480199a75b8444936bc6bddbdd626b63405e675
MD5 8d5387521e1cc6ea68f0543cfcc2659b
BLAKE2b-256 b4e073052dbb63fbdd8147f386e56d348db57cc46300f663ea3014ab1f05e6d5

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 4e7c8298187fd53354ae4c682425f28bd201b5b5ba55a55b5bb01836a1b418ac
MD5 778d0161b6938ffd9658ff1362e12bb3
BLAKE2b-256 f972f0df43407d0af752a1ea53ebb84510090843ef356823542737e9aa8c3ef7

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 bac6eee10169c4dfbf9b376d0674594b4d334f9a4d4e2add9380492570ea4b78
MD5 110e1ef2b85407e258706ee75eb3d4e8
BLAKE2b-256 884540d5eaf382b4d81c43bb18d538131489ec3a70cd1dde83ebd1e710dc7494

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 29d82af9220cf46647a0af4b2582dbd234cd6c0df7f2bbf5767246eb417a96a6
MD5 63abd7e40c33fe7b8570c731565d56ce
BLAKE2b-256 ba88a4b1ce1995eba4a35678ddc6cb698eb1474f2d31c4c8e196c32ee50ec1fe

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e874e6c1a44a8dfcbd87df27d5a1e074df53983636682d7b9511b61959650d49
MD5 a1b828073012c1c72f4edec38c25c950
BLAKE2b-256 9b251c0bd934220b1116501d96a156d17e5b7f542e6392df309740d49872c70a

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_armv7l.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 68dffe19f800dd817fd4bd6e6805b5a283ea5adaa276eba49bcd025eef574bea
MD5 933f312bfda3f40d02ed6af31e982e88
BLAKE2b-256 e6e87f1f583bff63c5f70d52446d8a2e7901e26c814eeb22e00da66ca0b578ef

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 979d553f7f01e7993d65b3cd684b8b14f9cbfed89de362c7d91e4a522c7ec778
MD5 72de8d968617e2b81729eccc9ed2a8cc
BLAKE2b-256 73144d07d1b6e2799e7a589b9b7f3cf9fdbfd49410ef215cc78898d31459eec7

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.13-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.13-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 3dc7235a296bdadad75f24c5ba2d53f843981f04d0c5299318bde9dfa6a56e5c
MD5 1a70c45a291b60d3bb5d6f6b0adb4bcf
BLAKE2b-256 f0fdd08a6e91fd2d25526fef95faa0058f8347287af45ce2990a307f2926e0f7

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