Skip to content
Velo

Subscribe to Live Market Data

Use the velo.channels namespace to subscribe to live market data. Build a channel, attach its listeners with .on(), and pass it to velo.channels.feed(). Execute the feed with velo.watch() to start receiving updates.

Example

Use the catalog to find its exchange, coin, and product.

Each channel needs a data listener before it can be added to a feed. Building the channel and feed sends nothing, velo.watch() opens the connection and resolves to a watcher. Updates arrive through the channel's listener.

import { Velo, catalog } from 'velo-sdk';
 
const velo = new Velo({
  apiKey: process.env.VELO_API_KEY!,
});
 
const [product] = await velo.query(
  catalog.futures({
    exchange: 'binance-futures',
    product: 'BTCUSDT',
  }),
);
 
if (!product) {
  throw new Error('Failed to find a product');
}
 
const price = velo.channels.price(product).on({
  data: (row) => console.log(row.time, row.close_price),
  error: ({ reason }) => console.error('Price channel error:', reason),
});
 
const openInterest = velo.channels.openInterest({ coin: product.coin }, { metric: 'coins' }).on({
  data: (entries) => console.table(entries),
  error: ({ reason }) => console.error('Open interest channel error:', reason),
});
 
const watcher = await velo.watch(velo.channels.feed([price, openInterest]), {
  on: {
    error: (error) => console.error('Connection error:', error),
  },
});

See the Channels reference for available channels, scopes, and markets.

Manage the subscription

Keep the channel value returned by .on() to stop following it later:

watcher.unsubscribe(openInterest);

Adding or removing a channel keeps the other subscriptions running. To stop the last channel, close the watcher:

watcher.close();

Connection failures retry automatically by default. Reconnecting subscribes to the channels the watcher currently follows, but does not replay updates missed during the gap. Refresh historical data if your application needs to fill those gaps. See velo.watch() for reconnection options, timeouts, and cancellation.

Errors on one channel go to its own error listener while the other channels continue. Connection errors go to the watcher's error listener.