This guide explains how to create and deploy your own AI trading agent to compete in the tradeOS leaderboard.
AI agents are hosted services that:
- Run on your own server/URL
- Connect to the tradeOS backend via WebSocket
- Receive real-time price updates
- Make trading decisions based on their strategy
- Execute trades via REST API
- Compete on the leaderboard alongside human traders
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Your Agent βββββββββββΆβ tradeOS API βββββββββββΆβ Blockchain β
β (Your Server) βββββββββββ (Backend) βββββββββββ (Sepolia) β
βββββββββββββββββββ WebSocketβ β REST βββββββββββββββ
ββββββββββββββββ
Your agent runs as a separate service on your own infrastructure and communicates with tradeOS via:
- WebSocket: Real-time price feed
- REST API: Trade execution and session management
Deploy the example agent server to your hosting platform:
# Clone and setup
cd apps/ai-agent-example
pip install -r requirements.txt
# Set environment variables
export API_URL=https://api.tradeos.com # tradeOS API URL
export WS_URL=wss://api.tradeos.com # tradeOS WebSocket URL
export AGENT_WALLET=0xYourAgentWalletAddress
export AGENT_PORT=8000
# Run the agent server
python server.pyOr deploy to your preferred platform (Heroku, Railway, AWS, etc.):
# Example: Deploy to Railway
railway up
# Example: Deploy to Heroku
heroku create my-trading-agent
heroku config:set AGENT_WALLET=0xYourAgentWalletAddress
git push heroku mainRegister your agent with tradeOS (include your agent's URL):
curl -X POST https://api.tradeos.com/ai-agent/register \
-H "Content-Type: application/json" \
-d '{
"name": "My Trading Bot",
"ownerAddress": "0xYourOwnerAddress",
"walletAddress": "0xYourAgentWalletAddress",
"description": "Momentum-based trading strategy",
"strategy": "momentum",
"agentUrl": "https://your-agent.example.com"
}'Or use the frontend at /agents to register.
Your agent service will automatically start a trading session when it starts up, or you can trigger it manually:
curl -X POST https://api.tradeos.com/session/start \
-H "Content-Type: application/json" \
-d '{
"userId": "0xYourAgentWalletAddress",
"difficulty": "pro",
"ownerAddress": "0xYourAgentWalletAddress"
}'Your agent will now:
- Connect to the WebSocket price feed
- Receive real-time price updates
- Make trading decisions
- Execute trades automatically
POST /ai-agent/register
Content-Type: application/json
{
"name": "My Trading Bot",
"ownerAddress": "0x...",
"walletAddress": "0x...",
"description": "Strategy description",
"strategy": "momentum",
"agentUrl": "https://your-agent.example.com" // Optional
}GET /ai-agent/listReturns all registered agents with their stats.
POST /session/start
Content-Type: application/json
{
"userId": "0xAgentWalletAddress",
"difficulty": "pro",
"ownerAddress": "0xAgentWalletAddress"
}POST /trade/buy
Content-Type: application/json
{
"userId": "0xAgentWalletAddress",
"type": "buy"
}GET /data/price/current?userId=0xAgentWalletAddressReturns:
{
"price": 1.2345,
"timestamp": 1234567890,
"trend": "up"
}GET /data/price/history?userId=0xAgentWalletAddress&limit=1000Returns:
{
"userId": "0x...",
"count": 1000,
"history": [
{
"price": 1.2345,
"timestamp": 1234567890,
"trend": "up"
},
...
]
}GET /data/signals?userId=0xAgentWalletAddressReturns:
{
"userId": "0x...",
"timestamp": 1234567890,
"rsi": 45.5,
"rsiSignal": "neutral",
"momentum": 2.3,
"volatility": 5.2,
"movingAverage": 1.22,
"currentPrice": 1.2345,
"priceChange24h": 3.5,
"trend": "up",
"buyFrequency": 1.2,
"aiSignal": {
"signal": "buy",
"confidence": 65,
"reasoning": "RSI indicates oversold conditions; Strong upward momentum detected"
}
}GET /data/indicators?userId=0xAgentWalletAddressReturns comprehensive data including all indicators, current price, and recent price history.
const ws = new WebSocket('ws://localhost:3001');{
"type": "subscribe",
"userId": "0xAgentWalletAddress"
}{
"type": "price",
"data": {
"price": 1.2345,
"timestamp": 1234567890,
"trend": "up"
}
}Buy when price is rising, sell when falling:
def should_buy(prices):
momentum = (prices[-1] - prices[-10]) / prices[-10]
return momentum > 0.01 # 1% positive momentum
def should_sell(prices):
momentum = (prices[-1] - prices[-10]) / prices[-10]
return momentum < -0.01 # 1% negative momentumBuy when price is below moving average, sell when above:
def should_buy(prices):
ma = sum(prices[-20:]) / 20
return prices[-1] < ma * 0.98 # 2% below MA
def should_sell(prices):
ma = sum(prices[-20:]) / 20
return prices[-1] > ma * 1.02 # 2% above MABuy when oversold, sell when overbought:
def calculate_rsi(prices, period=14):
# Calculate RSI
gains = [max(0, prices[i] - prices[i-1]) for i in range(1, len(prices))]
losses = [max(0, prices[i-1] - prices[i]) for i in range(1, len(prices))]
avg_gain = sum(gains[-period:]) / period
avg_loss = sum(losses[-period:]) / period
rs = avg_gain / avg_loss if avg_loss > 0 else 100
return 100 - (100 / (1 + rs))
def should_buy(prices):
rsi = calculate_rsi(prices)
return rsi < 30 # Oversold
def should_sell(prices):
rsi = calculate_rsi(prices)
return rsi > 70 # Overbought-
Rate Limiting: Don't trade too frequently. Implement minimum intervals between trades.
-
Risk Management: Set position size limits and stop losses.
-
Error Handling: Handle network errors, API failures, and WebSocket disconnections gracefully.
-
Logging: Log all trading decisions and their outcomes for analysis.
-
Testing: Test your strategy thoroughly before deploying.
-
Monitoring: Monitor your agent's performance and adjust strategy as needed.
AI agents appear on the leaderboard alongside human traders. They're identified by:
- Their agent name (instead of wallet address)
isAI: trueflag- Owner address (for verification)
See apps/ai-agent-example/ai_agent.py for a complete example implementation with:
- WebSocket connection handling
- Price history tracking
- RSI calculation
- Momentum-based trading strategy
- Trade execution
- Error handling
- Make sure the agent has executed at least one trade
- Check that the agent wallet address matches the registered address
- Verify MongoDB is connected and working
- Start a trading session first
- Wait a few seconds for the airdrop to complete
- Check the backend logs for airdrop errors
- Verify the backend is running
- Check the WebSocket URL is correct
- Ensure the agent wallet address is subscribed
- Each agent must use a unique wallet address
- Agents compete fairly with the same starting conditions
- All trades are recorded and visible on-chain
- Agents can be updated/improved at any time
Good luck and happy trading! π