Overview
The OlympTrade API is a powerful Python library that allows you to connect to OlympTrade's WebSocket API for real-time trading operations. With this library, you can:
Real-time Data
Access live price feeds and market data with ultra-low latency
Automated Trading
Build sophisticated trading bots and automated strategies
Market Analysis
Analyze historical data and implement technical indicators
Requirements
Before getting started, make sure you have the following:
Python 3.8+
The library requires Python 3.8 or higher
OlympTrade Account
Valid OlympTrade account with API access
Access Token
API access token from your OlympTrade account
Installation
Install the OlympTrade API library using pip:
pip install olymptrade-api
Or install from source:
git clone https://github.com/your-repo/olymptrade-api.git
cd olymptrade-api
pip install -e .
Virtual Environment Recommended
We recommend using a virtual environment to avoid conflicts with other packages.
Authentication
To use the API, you need to obtain an access token from your OlympTrade account:
-
Login to OlympTrade
Go to olymptrade.com and log in to your account
-
Access Developer Tools
Open your browser's developer tools (F12) and go to the Network tab
-
Find WebSocket Connection
Look for WebSocket connections and find the access_token in the Cookie header
-
Copy Token
Copy the access_token value - this is your API authentication token
Keep Your Token Secure
Never share your access token or commit it to version control. Use environment variables to store sensitive credentials.
Quick Start
Here's a simple example to get you started with the OlympTrade API:
import asyncio
from olymptrade_ws import OlympTradeClient
from olympconfig import parameters
async def on_tick(message):
"""Handle incoming price ticks"""
tick_data = message.get("d", [])
for tick in tick_data:
pair = tick.get("p")
price = tick.get("q")
print(f"{pair}: {price}")
async def main():
# Initialize client with your access token
token = "your_access_token_here"
client = OlympTradeClient(access_token=token)
# Register callback for price updates
client.register_callback(parameters.E_TICK_UPDATE, on_tick)
try:
# Start the client
await client.start()
# Subscribe to EUR/USD price feeds
await client.market.subscribe_ticks("EURUSD")
# Keep the client running
print("Client started. Press Ctrl+C to stop.")
await asyncio.Event().wait()
except KeyboardInterrupt:
print("Stopping client...")
finally:
await client.stop()
if __name__ == "__main__":
asyncio.run(main())
Basic Examples
Placing a Trade
async def place_demo_trade(client, account_id):
"""Place a demo trade"""
result = await client.trade.place_trade(
pair="EURUSD",
amount=10,
direction="up",
duration=60, # 1 minute
account_id=account_id,
group="demo"
)
if result:
print(f"Trade placed successfully: {result}")
else:
print("Failed to place trade")
Getting Account Balance
async def get_account_balance(client):
"""Get current account balance"""
# Subscribe to balance updates
await client.balance.subscribe_balance_updates()
# Wait a moment for balance data
await asyncio.sleep(2)
# Get latest balance
balance_data = client.balance.get_last_balance()
if balance_data:
accounts = balance_data.get('d', [])
for account in accounts:
group = account.get('group')
balance = account.get('balance')
currency = account.get('currency')
print(f"{group.upper()} Account: {balance} {currency}")
else:
print("No balance data available")
Next Steps
Now that you have the basics working, explore more advanced features:
Need Help?
Join our community for support and discussions: