Bots EndpointBot Data
Get Bot Data
Retrieve bot information with user bot tickers and account details
Retrieve comprehensive bot information including all associated user broker accounts, tickers, and bot state. This endpoint provides everything a bot needs to know about its configuration and the users/tickers it should operate on.
Endpoint
GET /api/bots/:slugAuthentication
All requests require bot API key authentication via the x-api-key header.
headers: {
'x-api-key': 'your-bot-api-key'
}Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | Bot identifier (alphanumeric, hyphens, underscores only) |
Slug Validation
The slug must match the regex pattern: /^[a-zA-Z0-9_-]+$/
Response
Success Response (200 OK)
{
"botId": "123e4567-e89b-12d3-a456-426614174000",
"botSlug": "my-trading-bot",
"userBrokerAccounts": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"accountNumber": "123456789",
"user": {
"id": "789e4567-e89b-12d3-a456-426614174001",
"email": "user@example.com"
},
"authorization": {
"id": "321e4567-e89b-12d3-a456-426614174002",
"accessToken": "encrypted-token",
"broker": "tradier"
},
"userBotTickers": {
"AAPL": {
"userBotTickerId": "111e4567-e89b-12d3-a456-426614174003",
"tickerId": "222e4567-e89b-12d3-a456-426614174004",
"status": "active",
"quantity": 100,
"extraConfig": {
"customSetting": "value"
}
},
"TSLA": {
"userBotTickerId": "333e4567-e89b-12d3-a456-426614174005",
"tickerId": "444e4567-e89b-12d3-a456-426614174006",
"status": "active",
"quantity": 50,
"extraConfig": null
}
},
"botState": {
"AAPL": {
"lastPrice": 150.25,
"position": "long",
"entryPrice": 145.00
},
"TSLA": {}
}
}
]
}Response Schema
| Field | Type | Description |
|---|---|---|
botId | string | UUID of the bot |
botSlug | string | Bot slug identifier |
userBrokerAccounts | array | Array of user broker accounts associated with this bot |
userBrokerAccounts[].id | string | UUID of the user broker account |
userBrokerAccounts[].accountNumber | string | Broker account number |
userBrokerAccounts[].user | object | User information |
userBrokerAccounts[].user.id | string | UUID of the user |
userBrokerAccounts[].user.email | string | User email address |
userBrokerAccounts[].authorization | object | Broker authorization details |
userBrokerAccounts[].authorization.id | string | Authorization ID |
userBrokerAccounts[].authorization.accessToken | string | Encrypted access token (for reference only) |
userBrokerAccounts[].authorization.broker | string | Broker code (e.g., "tradier") |
userBrokerAccounts[].userBotTickers | object | Object keyed by ticker symbol with ticker configuration |
userBrokerAccounts[].userBotTickers[SYMBOL].userBotTickerId | string | UUID of the user bot ticker |
userBrokerAccounts[].userBotTickers[SYMBOL].tickerId | string | UUID of the ticker |
userBrokerAccounts[].userBotTickers[SYMBOL].status | string | Status of the ticker (e.g., "active") |
userBrokerAccounts[].userBotTickers[SYMBOL].quantity | number | Quantity/position size for this ticker |
userBrokerAccounts[].userBotTickers[SYMBOL].extraConfig | object|null | Additional configuration for this ticker |
userBrokerAccounts[].botState | object | Bot state object keyed by ticker symbol |
userBrokerAccounts[].botState[SYMBOL] | object | State data for the ticker (structure defined by bot) |
Notes
- The
userBotTickersobject is keyed by ticker symbol (e.g., "AAPL", "TSLA") - The
botStateobject is keyed by ticker symbol and contains bot-specific state data - Only accounts with active subscriptions and connected broker authorizations are included
- The response is cached for 5 minutes for performance
Error Responses
400 Bad Request
Invalid slug format:
{
"error": "Invalid slug format. Only alphanumeric characters, hyphens, and underscores are allowed.",
"code": "BAD_REQUEST"
}Missing slug:
{
"error": "Bot slug is required",
"code": "BAD_REQUEST"
}401 Unauthorized
Missing API key:
{
"message": "API key required. Include x-api-key header."
}403 Forbidden
Invalid API key:
{
"message": "Invalid API key for this bot"
}404 Not Found
Bot not found:
{
"error": "Bot with slug 'my-bot' not found",
"code": "NOT_FOUND"
}500 Internal Server Error
{
"error": "Internal server error",
"code": "INTERNAL_SERVER_ERROR"
}Code Examples
TypeScript
async function getBotInfo(botSlug: string, apiKey: string) {
const response = await fetch(`https://api.example.com/api/bots/${botSlug}`, {
method: "GET",
headers: {
"x-api-key": apiKey,
},
});
if (!response.ok) {
const error = await response.json();
throw new Error(`Failed to get bot info: ${error.error}`);
}
return await response.json();
}
// Example usage
const botInfo = await getBotInfo("my-trading-bot", "your-api-key");
// Iterate through accounts and tickers
for (const account of botInfo.userBrokerAccounts) {
console.log(`Account: ${account.accountNumber}`);
console.log(`User: ${account.user.email}`);
// Iterate through tickers for this account
for (const [symbol, tickerConfig] of Object.entries(account.userBotTickers)) {
console.log(` Ticker: ${symbol}`);
console.log(` Status: ${tickerConfig.status}`);
console.log(` Quantity: ${tickerConfig.quantity}`);
// Get bot state for this ticker
const state = account.botState[symbol] || {};
console.log(` State:`, state);
}
}Python
import requests
from typing import Dict, Any
def get_bot_info(bot_slug: str, api_key: str) -> Dict[str, Any]:
"""
Retrieve bot information with user bot tickers and account details.
Args:
bot_slug: Bot identifier
api_key: Bot API key
Returns:
Dictionary containing bot information, accounts, and tickers
Raises:
requests.HTTPError: If the request fails
"""
url = f"https://api.example.com/api/bots/{bot_slug}"
headers = {
"x-api-key": api_key
}
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
# Example usage
bot_info = get_bot_info("my-trading-bot", "your-api-key")
# Iterate through accounts and tickers
for account in bot_info["userBrokerAccounts"]:
print(f"Account: {account['accountNumber']}")
print(f"User: {account['user']['email']}")
# Iterate through tickers for this account
for symbol, ticker_config in account["userBotTickers"].items():
print(f" Ticker: {symbol}")
print(f" Status: {ticker_config['status']}")
print(f" Quantity: {ticker_config['quantity']}")
# Get bot state for this ticker
state = account["botState"].get(symbol, {})
print(f" State: {state}")Use Cases
Initialize Bot with Configuration
// Get bot configuration on startup
const botInfo = await getBotInfo("my-bot", apiKey);
// Store configuration for later use
const accounts = botInfo.userBrokerAccounts;
const botId = botInfo.botId;
// Process each account
for (const account of accounts) {
const accountId = account.id;
const broker = account.authorization.broker;
// Get all active tickers for this account
const activeTickers = Object.entries(account.userBotTickers)
.filter(([_, config]) => config.status === "active")
.map(([symbol, config]) => ({
symbol,
quantity: config.quantity,
extraConfig: config.extraConfig,
state: account.botState[symbol] || {}
}));
console.log(`Account ${accountId} has ${activeTickers.length} active tickers`);
}Restore Bot State
# Restore bot state from previous session
bot_info = get_bot_info("my-bot", api_key)
for account in bot_info["userBrokerAccounts"]:
account_id = account["id"]
# Restore state for each ticker
for symbol, state in account["botState"].items():
if state: # Only restore if state exists
print(f"Restoring state for {symbol} on account {account_id}")
# Restore your bot's internal state from the state object
restore_ticker_state(symbol, account_id, state)Check Active Tickers
// Check which tickers are active for monitoring
const botInfo = await getBotInfo("my-bot", apiKey);
const allActiveTickers = new Set<string>();
for (const account of botInfo.userBrokerAccounts) {
for (const [symbol, config] of Object.entries(account.userBotTickers)) {
if (config.status === "active") {
allActiveTickers.add(symbol);
}
}
}
console.log(`Monitoring ${allActiveTickers.size} unique tickers:`, Array.from(allActiveTickers));