Unofficial Python API Wrapper & client for the TradoWix binary options trading platform.
pytradowix is a high-performance, asynchronous Python client wrapper designed for the TradoWix trading platform. Engineered for algorithmic trading, automated signal execution, and financial market data analysis, it enables seamless integration with TradoWix's WebSocket and REST APIs.
- β‘ Real-Time Price Streaming: Fast, asynchronous subscription to live currency and OTC asset price tick updates.
- π Unlimited Historical Data: Retrieve comprehensive historical candles (OHLC) using backward-paginated queries (tested for weeks/months of history).
- π€ Automated Trade Execution: Place binary option orders (CALL/PUT) programmatically and await resolution results.
- π Secure Session Caching: Automatic session token caching (
~/.pytradowix/session.json) to bypass repeated credentials requests. - π Connection Recovery: In-built automatic reconnection policy with custom exponential backoff delays.
- π‘οΈ Fully Type-Safe: Complies with strict type-checking (
mypy --strict) and exports fully documented frozen dataclasses.
- π Installation
- β‘ Quick Start
- π Event Callbacks
- π‘ API Reference
- π¦ Typed Data Classes
- π Auto-Reconnect
- π Session Caching
- π§ͺ Running Tests
- π Project Structure
- βοΈ Environment Variables
- π¬ Contact
- π License
# From source (recommended during development)
git clone https://github.com/usmanch96/pytradowix.git
cd pytradowix
pip install -e .
# Install dev extras (pytest, mypy)
pip install -e ".[dev]"import asyncio
import os
from dotenv import load_dotenv
from pytradowix import Tradowix
load_dotenv()
async def main():
client = Tradowix(
email=os.getenv("TRADOWIX_EMAIL"),
password=os.getenv("TRADOWIX_PASSWORD"),
is_demo=True, # trade on demo account
)
await client.connect()
# Account info
profile = client.get_profile()
balance = client.get_balance()
print(f"Hello {profile.display_name}! Balance: {balance.current_balance} {balance.currency}")
# Historical candles (1 week of 1-minute bars)
candles = await client.get_historical_candles(
symbol="USDJPY-OTC",
amount_of_seconds=604800, # 7 days
period=60, # 1-minute bars
)
print(f"Fetched {len(candles)} candles. Oldest: {candles[0]}, Newest: {candles[-1]}")
# Subscribe to live prices
def on_tick(quote):
print(f"[TICK] {quote.symbol}: {quote.price}")
client.on_quote = on_tick
await client.subscribe_ticks("USDJPY-OTC")
await asyncio.sleep(5)
# Place a trade
trade = await client.buy(amount=1.0, symbol="USDJPY-OTC", direction="call", duration=1)
trade_id = trade.get("tradeId") or trade["id"]
print(f"Trade placed: {trade_id}")
# Wait for settlement
result = await client.check_win(trade_id, timeout=120.0)
print(f"Result: {result.result.upper()}, P&L: ${result.profit}")
await client.close()
asyncio.run(main())The client supports both synchronous and asynchronous event callbacks to respond to real-time events on the platform:
# Triggered when the WebSocket connection is successfully authenticated and instruments cache is loaded
client.on_connect = lambda: print("π Connected and ready!")
# Triggered when the connection closes gracefully or unexpectedly
client.on_disconnect = lambda: print("π Disconnected!")
# Triggered whenever the account balance changes (e.g. from trade placements or settlements)
client.on_balance_update = lambda balance: print(f"π° New Balance: {balance.current_balance} {balance.currency}")
# Triggered automatically when any placed trade is settled by the server
client.on_trade_settled = lambda result: print(f"Settled: {result.trade_id} -> {result.result.upper()} (${result.profit:+.2f})")
# Triggered when aggregated OHLC candles update or close (requires setup_candle_stream)
client.on_candle_update = lambda symbol, period, candle, is_closed: print(f"Candle closed? {is_closed} - Close: {candle.close}")| Method | Description |
|---|---|
connect() |
Authenticate and establish WebSocket connection |
close() |
Gracefully disconnect |
get_profile() |
Returns ProfileInfo β user profile data |
get_balance() |
Returns Balance β demo/real/bonus balances |
get_assets() |
Returns list[AssetInfo] β all tradeable instruments |
is_asset_tradable(symbol) |
Safety check verifying if an asset is active and open for trading |
change_account(mode) |
Switch between "demo" and "real" account modes |
edit_demo_balance(amount) |
Request a demo balance top-up |
get_highest_payout_assets(min_payout, mode) |
Filter active/open instruments by minimum payout rate, sorted in descending order of payout |
subscribe_ticks(symbol) |
Start receiving live Quote ticks for a symbol |
unsubscribe_ticks(symbol) |
Stop receiving ticks for a symbol |
setup_candle_stream(symbol, periods) |
Configure timeframe aggregators (e.g. [10, 60]) to build live candles from streamed ticks |
get_candles(symbol, end_from_time, minutes, timeframe) |
Fetch a single batch of historical candles |
get_historical_candles(symbol, amount_of_seconds, period) |
Fetch unlimited history via backward pagination |
buy(amount, symbol, direction, duration, is_demo, expiration_mode) |
Place a turbo (minutes) or blitz (seconds) trade |
put(amount, symbol, duration, is_demo, expiration_mode) |
Convenience alias for buy(..., direction="put") |
buy_blitz(amount, symbol, duration_seconds) |
Place a blitz call (seconds) trade |
put_blitz(amount, symbol, duration_seconds) |
Place a blitz put (seconds) trade |
check_win(trade_id, timeout) |
Wait for and return a TradeResult |
get_open_trades(is_demo, timeout) |
Returns list[TradeResult] β retrieve all active open trades |
get_trade_history(page, page_size, is_demo, timeout) |
Returns list[TradeResult] β retrieve historical settled trades |
get_server_time() |
Returns the estimated synchronized server timestamp in seconds |
All public methods return typed, frozen dataclasses β no more opaque dicts.
from pytradowix import Candle, Balance, TradeResult, Quote, AssetInfo, ProfileInfo| Type | Fields |
|---|---|
Candle |
time, open, high, low, close, .color |
Balance |
demo_balance, real_balance, current_balance, currency, is_demo |
ProfileInfo |
id, email, full_name, display_name, country, ... |
AssetInfo |
symbol, name, is_open, is_otc, turbo_payout_rate, ... |
TradeResult |
trade_id, result, profit, new_balance, direction, ... |
Quote |
symbol, price, timestamp |
The client supports automatic reconnection with exponential backoff:
from pytradowix import Tradowix, ReconnectPolicy
client = Tradowix(
email="...",
password="...",
reconnect_policy=ReconnectPolicy(
enabled=True,
max_attempts=0, # 0 = infinite retries
base_delay=1.0,
max_delay=30.0,
),
)The client automatically caches session tokens to ~/.pytradowix/session.json in the user's home directory. On the next run, the cached token is validated with a lightweight profile request before falling back to a full credential login. This avoids unnecessary authentication round-trips.
pip install -e ".[dev]"
pytest tests/ -vpytradowix/
βββ __init__.py # Public API surface
βββ client.py # Core Tradowix client class
βββ config.py # Session caching configuration
βββ exceptions.py # Custom exception hierarchy
βββ types.py # Typed frozen dataclasses
βββ py.typed # PEP 561 type marker
βββ utils/
β βββ waits.py # Async slot registry for WS event coordination
βββ _api/
βββ account.py # connect, profile, balance, change_account
βββ trading.py # buy, put, check_win
βββ realtime.py # subscribe/unsubscribe ticks
βββ history.py # get_candles, get_historical_candles
examples/
βββ fetch_balance.py
βββ place_trade.py
βββ fetch_history.py
tests/
βββ test_types.py
βββ test_waits.py
Copy the template .env.example to .env in the project root and fill in your credentials:
cp .env.example .env.env structure:
TRADOWIX_EMAIL=your@email.com
TRADOWIX_PASSWORD=yourpasswordFor questions, feedback, or custom integrations:
- Telegram: @usmanch069
MIT License β see LICENSE.
