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 Distribution

binaryoptionstoolsv2-0.2.11.tar.gz (248.9 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.11-cp39-abi3-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.9+Windows x86-64

binaryoptionstoolsv2-0.2.11-cp39-abi3-win32.whl (3.1 MB view details)

Uploaded CPython 3.9+Windows x86

binaryoptionstoolsv2-0.2.11-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.11-cp39-abi3-musllinux_1_1_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ ARM64

binaryoptionstoolsv2-0.2.11-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.11-cp39-abi3-manylinux_2_28_armv7l.whl (3.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARMv7l

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

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

binaryoptionstoolsv2-0.2.11-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (6.9 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.11.tar.gz.

File metadata

  • Download URL: binaryoptionstoolsv2-0.2.11.tar.gz
  • Upload date:
  • Size: 248.9 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.11.tar.gz
Algorithm Hash digest
SHA256 6110c846dd7020867f1a58f7675236d9956419a9d6ba2c89c50d39fe5ebb5be5
MD5 4aa5cf137387ab0e6b868c3ebfbacde1
BLAKE2b-256 0a3d3d03dd27111b407b2a2a2ac8092644843e11e209ac444c0f7ab97b0e7ea7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.11-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e2b9ebb32ca14daa25058cf9e83fe07839a887dacacaab25816118752606a68d
MD5 c84ff282ff6e81d5e831a7ff623ea2ee
BLAKE2b-256 906247239985ffa52468bfbbea00fd49d2e340da15c5d744f70ddf92f726ecf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.11-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 bcf8e058af53cebc55adb53eee83ced410f1cd3be5ddcdcb115407bab872e7fb
MD5 e05a98fd8b4f50f9cd46b0ffd2b1a7f0
BLAKE2b-256 8dfe6294bcccaf3f75c6b087573943de635e9d6b4df6840b6653b02e3ab0b13c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.11-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6748b0fa94a7b6603821f68127bf130c7c0458323b402cad1f25361a1b337395
MD5 50db541b6826f3ad64b56b0241ef3a3c
BLAKE2b-256 3acb36a4b48eb418ccd3e198be7f58c34437e538fc2da01f6763d3c3e521105a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.11-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 ec265794f6ce1cfd88eedbff79ef8445deaab710c6e45dd596c05a3090f5a08e
MD5 4abee78c2ed15504e1497cb8fb27fc2d
BLAKE2b-256 1ace0b40ec8fbbe2d75165f45d6651269ae2aa9fac196ca28be2fd9f0aa3d218

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.11-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7bca61668ebe6f7ae4452ec44dec4ce78bf5b4c1a2f129a96a8f38cec527e3df
MD5 19b579d9935fda949a2fb560819f805d
BLAKE2b-256 651ffb27bb64dd22fdf64d1ae2a1603e624c6cb0ac6e3c414bc7a56113d204ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.11-cp39-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 86aebbf2e2919f0a01c192e3249d543e9589a254853dd229bfde644e19e6e5e9
MD5 ee14d5d252007a9fe74d8fd99890a588
BLAKE2b-256 228831b6441f3ebb480e66a51c201c7d2d4fb140692651cc2f3a74e37868da96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for binaryoptionstoolsv2-0.2.11-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5e30695b314ee13eb35ca38e212ed1a054a3fccbc4d1bcd4e8e64202278bb345
MD5 5bf94ee416e6a0d523c78de9695f920c
BLAKE2b-256 879661cab547c759bc51d4f60c464646ba35dbe7456bdf1d4032ca721e56df2f

See more details on using hashes here.

File details

Details for the file binaryoptionstoolsv2-0.2.11-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.11-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f2d4031ba7cf32bd42cfe08a229b2bc15ad971b72f2dad4c800b44c88c97d154
MD5 4d165e5123d2741b20051e5aae4255f0
BLAKE2b-256 649cc7d462e3599081e3a28a149fe54f5b840b6742be96b4b3ff4e7501e24d13

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