Documentation/Examples

Examples & Tutorials

Practical examples and trading bot templates to get you started

Basic Trade

python

Place a simple CALL trade and check the result

from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

api = PocketOption(ssid="your-ssid")
time.sleep(5)

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

# Wait and check
time.sleep(65)
won = api.check_win(trade_id)
print(f"Won: {won}")

Martingale Bot

python

Automated martingale strategy - doubles bet after loss

from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

api = PocketOption(ssid="your-ssid")
time.sleep(5)

base_amount = 1.0
amount = base_amount
max_trades = 10

for i in range(max_trades):
    trade_id, _ = api.buy(
        asset="EURUSD_otc",
        amount=amount,
        time=60
    )
    
    time.sleep(65)
    won = api.check_win(trade_id)
    
    if won:
        print(f"Trade {i+1}: Won $" + str(amount))
        amount = base_amount
    else:
        print(f"Trade {i+1}: Lost $" + str(amount))
        amount *= 2  # Double the bet

Real-time Price Monitor

python

Subscribe to live price updates and log them

from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

api = PocketOption(ssid="your-ssid")
time.sleep(5)

def price_callback(data):
    print(f"Price update: {data['price']} at {data['timestamp']}")

# Subscribe to symbol
api.subscribe_symbol("EURUSD_otc", price_callback)

# Keep running
while True:
    time.sleep(1)

Candle Data Analysis

python

Fetch and analyze historical candle data

from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

api = PocketOption(ssid="your-ssid")
time.sleep(5)

# Get 100 candles
candles = api.get_candles("EURUSD_otc", period=60, count=100)

# Calculate average
prices = [c['close'] for c in candles]
avg_price = sum(prices) / len(prices)

print(f"Average price: {avg_price}")
print(f"Highest: {max(prices)}")
print(f"Lowest: {min(prices)}")

JavaScript Bot

javascript

Simple trading bot with Node.js

const { PocketOption } = require('@rick-29/binary-options-tools');

async function tradingBot() {
  const api = new PocketOption('your-ssid');
  await new Promise(resolve => setTimeout(resolve, 5000));
  
  const balance = await api.balance();
  console.log(`Starting balance: $${balance}`);
  
  for (let i = 0; i < 5; i++) {
    const { tradeId } = await api.buy({
      asset: 'EURUSD_otc',
      amount: 1.0,
      time: 60
    });
    
    await new Promise(resolve => setTimeout(resolve, 65000));
    const won = await api.checkWin(tradeId);
    console.log(`Trade ${i+1}: ${won ? 'Won' : 'Lost'}`);
  }
}

tradingBot().catch(console.error);

Multi-Asset Trading

python

Trade multiple assets simultaneously

from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

api = PocketOption(ssid="your-ssid")
time.sleep(5)

assets = ["EURUSD_otc", "GBPUSD_otc", "USDJPY_otc"]
trades = {}

# Place trades on all assets
for asset in assets:
    trade_id, _ = api.buy(asset=asset, amount=1.0, time=60)
    trades[trade_id] = asset
    print(f"Trade placed on {asset}")

# Wait for all to complete
time.sleep(65)

# Check results
for trade_id, asset in trades.items():
    won = api.check_win(trade_id)
    print(f"{asset}: {'Won' if won else 'Lost'}")

Balance Monitor

python

Monitor account balance and send alerts

from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

api = PocketOption(ssid="your-ssid")
time.sleep(5)

initial_balance = api.balance()
threshold = initial_balance * 0.9  # Alert if drops 10%

while True:
    current_balance = api.balance()
    change = ((current_balance - initial_balance) / initial_balance) * 100
    
    print(f"Balance: ${current_balance:.2f} ({change:+.2f}%)")
    
    if current_balance < threshold:
        print("⚠️ ALERT: Balance dropped below threshold!")
        break
    
    time.sleep(60)  # Check every minute

Payout Finder

python

Find assets with best payout rates

from BinaryOptionsToolsV2.pocketoption import PocketOption
import time

api = PocketOption(ssid="your-ssid")
time.sleep(5)

assets = ["EURUSD_otc", "GBPUSD_otc", "USDJPY_otc", 
          "BTCUSD_otc", "ETHUSD_otc"]

payouts = {}
for asset in assets:
    payout = api.get_payout(asset)
    payouts[asset] = payout
    print(f"{asset}: {payout * 100:.1f}%")

# Find best payout
best = max(payouts.items(), key=lambda x: x[1])
print(f"\nBest payout: {best[0]} at {best[1] * 100:.1f}%")

Need a Custom Trading Bot?

Our team can build professional trading bots tailored to your strategy

Get Your Custom Bot →