Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cryptorobot.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Cryptorobot.ai uses WebSockets for real-time bidirectional communication. This enables:
  • Live price ticker updates
  • Trading bot event streams
  • Order execution notifications
  • System alerts and status changes

Connecting

import { createClient } from '@cryptorobot.ai/client';

const client = createClient('https://api.cryptorobot.ai');

await client.authenticate({
  strategy: 'local',
  email: 'you@example.com',
  password: 'your-password'
});

// Listen for events
client.service('traders/pods/events').on('created', (event) => {
  console.log('Pod event:', event);
});

client.service('exchanges/ticker').on('patched', (ticker) => {
  console.log('Price update:', ticker);
});

Event Types

Events follow the naming pattern: <service> <method>
Event NameTriggerPayload
strategies createdNew strategy createdStrategy object
strategies patchedStrategy updatedStrategy object
strategies removedStrategy deleted{ _id }
traders createdBot createdTrader object
traders patchedBot status changedTrader object
traders pods events createdPod lifecycle eventEvent object
exchanges ticker patchedPrice updateTicker data
trades createdTrade executedTrade object
models signals createdNew signal firedSignal object
messages createdNew notificationMessage object
events createdSystem eventEvent object

Listening to Events

Trading Bot Events

// Listen for all pod events (trades, errors, status changes)
client.service('traders/pods/events').on('created', (event) => {
  console.log(`[${event.type}] ${event.message}`);
  // { type: "trade_executed", podId: "pod-123", message: "Bought 0.1 BTC @ 42400", ... }
});

// Bot status changes
client.service('traders').on('patched', (trader) => {
  console.log(`Bot ${trader.name} is now ${trader.status}`);
  // status: "running" | "stopped" | "error"
});

Price Updates

// Real-time ticker updates
client.service('exchanges/ticker').on('patched', (ticker) => {
  console.log(`${ticker.symbol}: ${ticker.last}`);
});

Trade Notifications

// New trades executed by your bots
client.service('trades').on('created', (trade) => {
  console.log(`${trade.side} ${trade.amount} ${trade.symbol} @ ${trade.price}`);
});

Signal Alerts

// ML model signal alerts
client.service('models/signals').on('created', (signal) => {
  console.log(`Signal: ${signal.type} ${signal.pair} - confidence: ${signal.confidence}`);
});

Service Methods via WebSocket

You can also call API methods through the WebSocket connection (instead of REST):
import { createClient } from '@cryptorobot.ai/client';

const client = createClient('https://api.cryptorobot.ai');

await client.authenticate({
  strategy: 'local',
  email: 'you@example.com',
  password: 'your-password'
});

// Find strategies (equivalent to GET /strategies)
const strategies = await client.service('strategies').find({
  query: { type: 'momentum' }
});
console.log(strategies.data);

// Create a resource (equivalent to POST /strategies)
const newStrategy = await client.service('strategies').create({
  name: 'New Strategy',
  type: 'momentum',
  pair: 'BTC/USDT'
});
console.log(newStrategy._id);

// Patch a resource (equivalent to PATCH /strategies/:id)
const updated = await client.service('strategies').patch('strat-456', {
  name: 'Updated Name'
});
console.log(updated);

Channel Subscription

By default, you receive events for resources you own. The server automatically subscribes authenticated users to their personal channel.
You don’t need to manually subscribe to channels. Authentication handles channel membership automatically based on your user ID and permissions.

Reconnection Handling

The client SDK handles reconnection automatically. You can listen for connection status changes:
client.on('disconnect', () => {
  console.log('Connection lost — attempting to reconnect...');
});

client.on('reconnect', () => {
  console.log('Reconnected successfully');
});
The client SDK automatically re-authenticates after reconnection using the stored JWT token.

Best Practices

Set transports: ['websocket'] to skip the HTTP long-polling upgrade handshake and connect faster.
Always implement reconnection logic. Network interruptions are normal in long-lived connections.
Instead of polling REST endpoints for updates, listen to WebSocket events. This reduces latency and API load.
Fetch the initial state via REST (GET /traders), then subscribe to real-time updates via WebSocket (traders patched).
High-frequency events (like ticker updates) can fire many times per second. Throttle or debounce your handlers if updating UI.