Documentation/Python API

Python API

Complete Python documentation with async and sync support, type hints, and comprehensive examples

Installation

pip install BinaryOptionsToolsV2

Requires Python 3.7 or higher

Quick Start

Synchronous API

sync_example.py
from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

# Initialize connection
api = PocketOption(ssid="your-session-id")
time.sleep(5)  # Wait for WebSocket connection

# Get balance
balance = api.balance()
print(f"Balance: ${balance}")

# Place a trade
trade_id, trade_data = api.buy(
    asset="EURUSD_otc",
    amount=1.0,
    time=60,
    action="call"
)
print(f"Trade ID: ${trade_id}")

# Check result
time.sleep(65)
result = api.check_win(trade_id)
print(f"Won: ${result}")

Asynchronous API

async_example.py
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio

async def main():
    # Initialize connection
    api = PocketOptionAsync(ssid="your-session-id")
    await asyncio.sleep(5)
    
    # Get balance
    balance = await api.balance()
    print(f"Balance: ${balance}")
    
    # Place a trade
    trade_id, trade_data = await api.buy(
        asset="EURUSD_otc",
        amount=1.0,
        time=60,
        action="call"
    )
    print(f"Trade ID: ${trade_id}")
    
    # Check result
    await asyncio.sleep(65)
    result = await api.check_win(trade_id)
    print(f"Won: ${result}")

# Run async function
asyncio.run(main())

Key Methods

Trading

  • buy(asset, amount, time, action="call")

    Place a CALL trade

  • sell(asset, amount, time)

    Place a PUT trade

  • check_win(trade_id)

    Check trade result

Account

  • balance()

    Get account balance

  • profile()

    Get profile information

Market Data

  • get_candles(asset, period, count)

    Get historical candle data

  • get_payout(asset)

    Get payout percentage

  • subscribe_symbol(asset, callback)

    Subscribe to real-time updates

Type Hints

The library includes comprehensive type hints for better IDE support and type checking:

from BinaryOptionsToolsV2.pocketoption import PocketOption
from typing import Tuple, Dict, List

api: PocketOption = PocketOption(ssid="...")

# Type-annotated variables
balance: float = api.balance()
trade_id: int
trade_data: Dict

trade_id, trade_data = api.buy(
    asset="EURUSD_otc",
    amount=1.0,
    time=60
)

# Type hints for custom functions
def analyze_trade(trade_id: int) -> bool:
    result: bool = api.check_win(trade_id)
    return result