Automate trading strategies on real or demo accounts. Open and close positions, manage portfolios, and access live PnL — all via REST.
import requests, uuid
BASE = "https://public-api.etoro.com/api/v1"
HEADERS = {
"x-api-key": "YOUR_PUBLIC_API_KEY",
"x-user-key": "YOUR_USER_KEY",
"x-request-id": str(uuid.uuid4()),
}
# Search for an instrument
instruments = requests.get(
f"{BASE}/market-data/search",
headers=HEADERS,
params={"search": "TSLA"}
).json()
instrument_id = instruments["data"][0]["instrumentId"]
# Open a BUY position on Demo
position = requests.post(
f"{BASE}/trading/execution/demo/market-open-orders/by-amount",
headers=HEADERS,
json={
"InstrumentID": instrument_id,
"Amount": 5000,
"IsBuy": True,
}
).json()
print(f"Opened position: {position['data']['positionId']}")
# Check portfolio
portfolio = requests.get(
f"{BASE}/trading/info/demo/portfolio",
headers=HEADERS,
).json()
for pos in portfolio["data"]["positions"]:
print(f"{pos['instrumentName']}: {pos['pnl']}")Build a fully functional algorithmic trading bot using the eToro API with position management, risk controls, and automated strategy execution.
Connect to eToro's WebSocket API for live price streaming, handle reconnections, and process real-time market data efficiently.
A step-by-step guide to building a simple trading bot using the eToro Demo Trading API.
A practical guide for transitioning your trading bot from eToro's demo sandbox to the real trading API.