Trading Operations
Essential trading functions - buy, sell, and manage your trades
Basic Trading - Buy & Sell
BeginnerLearn how to place basic buy and sell orders with BinaryOptionsToolsV2
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main(ssid: str):
# The API automatically detects if the 'ssid' is for real or demo account
api = PocketOptionAsync(ssid)
# Place a BUY order
(buy_id, buy_data) = await api.buy(
asset="EURUSD_otc",
amount=1.0,
time=60,
check_win=False
)
print(f"Buy trade id: {buy_id}")
print(f"Buy trade data: {buy_data}")
# Place a SELL order
(sell_id, sell_data) = await api.sell(
asset="EURUSD_otc",
amount=1.0,
time=60,
check_win=False
)
print(f"Sell trade id: {sell_id}")
print(f"Sell trade data: {sell_data}")
if __name__ == '__main__':
ssid = input('Please enter your ssid: ')
asyncio.run(main(ssid))
Check Trade Results
BeginnerMonitor your trades and check win/loss results
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main(ssid: str):
# Initialize API
api = PocketOptionAsync(ssid)
# Place trades without automatic win checking
(buy_id, _) = await api.buy(
asset="EURUSD_otc",
amount=1.0,
time=15,
check_win=False
)
(sell_id, _) = await api.sell(
asset="EURUSD_otc",
amount=1.0,
time=300,
check_win=False
)
print(f"Trade IDs: Buy={buy_id}, Sell={sell_id}")
# Manually check trade results
buy_data = await api.check_win(buy_id)
print(f"Buy trade result: {buy_data['result']}")
print(f"Buy trade data: {buy_data}")
sell_data = await api.check_win(sell_id)
print(f"Sell trade result: {sell_data['result']}")
print(f"Sell trade data: {sell_data}")
if __name__ == '__main__':
ssid = input('Please enter your ssid: ')
asyncio.run(main(ssid))
Trade History & Open Positions
IntermediateRetrieve and monitor your open and closed trades
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main(ssid: str):
api = PocketOptionAsync(ssid)
# Place some test trades
_ = await api.buy(asset="EURUSD_otc", amount=1.0, time=60, check_win=False)
_ = await api.sell(asset="EURUSD_otc", amount=1.0, time=60, check_win=False)
# Get currently opened deals
opened_deals = await api.opened_deals()
print(f"Opened deals: {opened_deals}")
print(f"Number of opened deals: {len(opened_deals)} (should be at least 2)")
# Wait for trades to complete
await asyncio.sleep(62)
# Get closed deals history
closed_deals = await api.closed_deals()
print(f"Closed deals: {closed_deals}")
print(f"Number of closed deals: {len(closed_deals)} (should be at least 2)")
if __name__ == '__main__':
ssid = input('Please enter your ssid: ')
asyncio.run(main(ssid))
Market Data
Access real-time and historical market data
Account Balance
BeginnerRetrieve your current account balance
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main(ssid: str):
# The API automatically detects if the 'ssid' is for real or demo account
api = PocketOptionAsync(ssid)
await asyncio.sleep(5) # Wait for connection
balance = await api.balance()
print(f"Current Balance: ${balance}")
if __name__ == '__main__':
ssid = input('Please enter your ssid: ')
asyncio.run(main(ssid))
Historical Candles
IntermediateFetch historical candlestick data for technical analysis
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import pandas as pd
import asyncio
async def main(ssid: str):
api = PocketOptionAsync(ssid)
await asyncio.sleep(5) # Wait for connection
# Test different time frames and periods
times = [3600 * i for i in range(1, 11)] # 1-10 hours back
time_frames = [1, 5, 15, 30, 60, 300] # Different timeframes in seconds
for time in times:
for frame in time_frames:
# Get candles data
candles = await api.get_candles("EURUSD_otc", frame, time)
# Convert to pandas DataFrame for analysis
candles_df = pd.DataFrame.from_dict(candles)
print(f"Timeframe: {frame}s, Period: {time}s")
print(f"Candles DataFrame: {candles_df.head()}")
print(f"Number of candles: {len(candles_df)}")
print("-" * 50)
if __name__ == '__main__':
ssid = input('Please enter your ssid: ')
asyncio.run(main(ssid))
Payout Rates
BeginnerGet current payout rates for different assets
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
import asyncio
async def main(ssid: str):
api = PocketOptionAsync(ssid)
await asyncio.sleep(5) # Wait for connection
# Get all available payouts
full_payout = await api.payout()
print(f"All Payouts: {full_payout}")
# Get payouts for specific assets
assets = ["EURUSD_otc", "EURUSD", "AEX25"]
partial_payout = await api.payout(assets)
print(f"Specific Assets Payout: {partial_payout}")
# Get payout for single asset
single_payout = await api.payout("EURUSD_otc")
print(f"EURUSD_otc Payout: {single_payout}%")
if __name__ == '__main__':
ssid = input('Please enter your ssid: ')
asyncio.run(main(ssid))