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:
    • 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.12.tar.gz (254.2 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.12-cp39-abi3-win_amd64.whl (3.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

binaryoptionstoolsv2-0.2.12-cp39-abi3-win32.whl (3.0 MB view details)

Uploaded CPython 3.9+Windows x86

binaryoptionstoolsv2-0.2.12-cp39-abi3-musllinux_1_1_x86_64.whl (3.9 MB view details)

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

binaryoptionstoolsv2-0.2.12-cp39-abi3-musllinux_1_1_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ ARM64

binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_x86_64.whl (3.9 MB view details)

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

binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_armv7l.whl (3.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARMv7l

binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

binaryoptionstoolsv2-0.2.12-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (6.8 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 binaryoptionstoolsv2-0.2.12.tar.gz.

File metadata

  • Download URL: binaryoptionstoolsv2-0.2.12.tar.gz
  • Upload date:
  • Size: 254.2 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.12.tar.gz
Algorithm Hash digest
SHA256 cf58227b4743a0d19708ee6b04942f2daef485c808d5b05dcb8edd033afd79cb
MD5 eee03279f7648bdcd230d9dedfea273a
BLAKE2b-256 559d0a24562bc0b38f5bd225c0a076c76b3430eb9170d49d4342c7120f8f8081

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 94946bd18d148f10d2ff782a34796dcfad21e88b24e77578d65783a6ad2538f0
MD5 0da933a7ae6128a18c9a8b0754c06f15
BLAKE2b-256 93f1d95195090c3b64d6d994d48ec533496f7f876d83c66e0027468f9836b25d

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-win32.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 84af010bdc621e9bd9469eff764dd6d365af381dd3c535d1cd07427836312404
MD5 9312ddaeea748871d3174a023a6fbc65
BLAKE2b-256 19f32a285eb3c6cb7323b8dbcc2d60c01fe25d19eedefe5a58455eb90ede5609

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 cee6720bca37a2ba87bb2a2f5db1004240ec046f0a331ffbe67d20a5899dd880
MD5 b9e025cdbf93140d212d4e3404017a15
BLAKE2b-256 2276eb8cce2865145873e4a6ebdd8e590fd349e2365cfcefeb22041b167fdd6e

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 f79056caabaaed4f2552207523de862f37db29fd8ec7f59bd8207c3c190ef73e
MD5 5237512840e29c3af1a2a2cdd043595d
BLAKE2b-256 d6675224603fdce1cfb989ef4f0431df5f642d224274b57bdd1ea32691d7d265

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 daead5a06db3c0d45dfc7099cee029424118838e4c8d8189c9c8495bf517e85e
MD5 6cd49fe00f59eb485c914211dc9b4eae
BLAKE2b-256 2469cf0cbba883fd7f8fd27a9bed1045545e3ab109b62a868debb99c49671a87

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_armv7l.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 2a0da8697f19a912932785a7c593353ca23245ede93c5afd38ae71ec4a85b81c
MD5 6661a2f96e6f29a2ddf2d2511e407c3f
BLAKE2b-256 9e746dcf9fc85baedba590fe594804c69e46fc51326eddc0aba328c4d3f25286

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6dc1349b262681147df3be11466cd04e9e5eeac648dabf712d8b6785062e4eb6
MD5 732aec958ab0cb481d55cb5ce56698e5
BLAKE2b-256 3c92c711c85132adc606e001786d0c6c853afe758671a9d3374b7a24644f4f6b

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.12-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.12-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 373f4108c1fa6c00a67503370ae59e4bb8b76b9a3eb0bb717d7dbaa82231c77c
MD5 f123d6e9b38a9fde22fd47ae10e5cfba
BLAKE2b-256 1fca27d4d0ec2a2bfd117a9b7dd92abf1919cf20ce86db015451e2c21688d5ff

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