API Reference
Complete reference for all OlympTrade API methods and functionality
Authentication
All API requests require authentication using email and password credentials.
Initialize Connection
Create and authenticate a new API connection.
Parameters
Example
import asyncio
from olymptrade_ws import OlympTradeClient
async def main():
client = OlympTradeClient(access_token="YOUR_ACCESS_TOKEN")
await client.start()
if client.is_connected:
print("Successfully connected to OlympTrade API")
else:
print("Failed to connect")
await client.stop()
if __name__ == "__main__":
asyncio.run(main())
Connection Management
is_connected
Check if the API connection is active and authenticated.
Returns
Example
# After starting the client
print(f"Connection status: {client.is_connected}")
stop()
Disconnect from the OlympTrade API and close the session.
Example
await client.stop()
print("Disconnected from API")
Account Methods
get_balance()
Retrieve current account balance information.
Returns
Example
balance = await client.balance.get_balance()
demo_acc = next(acc for acc in balance['d'] if acc['group'] == 'demo')
print(f"Demo account balance: {demo_acc['amount']}")
get_profile()
Get detailed profile information for the authenticated account.
Returns
Example
profile = await client.get_profile()
print(f"User ID: {profile['user_id']}")
print(f"Account type: {profile['account_type']}")
print(f"Registration date: {profile['created_at']}")
get_open_trades()
Retrieve all currently open trading positions.
Returns
Example
positions = await client.trade.get_open_trades(account_id, group="demo")
for position in positions:
print(f"Asset: {position['asset']}")
print(f"Amount: ${position['amount']}")
print(f"Direction: {position['direction']}")
print(f"Profit/Loss: ${position['pnl']}")
print("---")
Trading Methods
place_order()
Place a trade order on a specified asset.
Example
order_result = await client.trade.place_order(
pair="LATAM_X",
amount=1,
direction="up",
duration=60,
account_id=demo_acc['account_id'],
group="demo"
)
print("Order result:", order_result)
close_position()
Close an open position before expiration (if available).
Example
result = await client.trade.close_position(position_id)
if result['success']:
print(f"Position closed. Final PnL: ${result['pnl']}")
else:
print(f"Failed to close position: {result['error']}")
get_candles()
Retrieve historical candlestick data for technical analysis.
Example
candles = await client.market.get_candles("LATAM_X", size=60, count=10)
for candle in candles:
print(f"Time: {candle['time']}")
print(f"OHLC: {candle['open']}, {candle['high']}, {candle['low']}, {candle['close']}")
print(f"Volume: {candle['volume']}")
print("---")
Real-time Data
subscribe_ticks()
Subscribe to real-time price ticks for a specified asset.
Example
async def on_tick(tick):
print("Tick:", tick)
await client.market.subscribe_ticks("LATAM_X")
# You can then listen for tick events via your event handler
subscribe_to_candles()
Subscribe to real-time candlestick updates.
Example
async def on_candle(candle):
print("New candle:", candle)
await client.market.subscribe_candles("LATAM_X", size=60)
# Listen for candle events via your event handler
Error Handling
The API uses standard HTTP status codes and provides detailed error messages.
Common Error Codes
Exception Handling Example
from olymptrade_ws import OlympTradeClient
async def main():
client = OlympTradeClient(access_token="YOUR_ACCESS_TOKEN")
try:
await client.start()
balance = await client.balance.get_balance()
print(f"Balance: {balance}")
except Exception as e:
print(f"API Error: {e}")
finally:
await client.stop()
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Need Professional Bot Development?
Get custom trading bots built by experts using the OlympTrade API