import { PolyNode, perpsChannels } from 'polynode-sdk';
const apiKey = process.env.POLYNODE_API_KEY;
if (!apiKey) throw new Error('Set POLYNODE_API_KEY');
const pn = new PolyNode({ apiKey });
const perps = pn.configurePerps({ queueCapacity: 4096 });
perps.onReconnect((notice) => console.warn('gap possible', notice));
perps.onOverflow((notice) => console.error('local overflow', notice));
const ack = await perps.subscribe([
perpsChannels.tickers,
perpsChannels.bbo('BTC-USD'),
perpsChannels.book('BTC-USD'),
perpsChannels.trades('BTC-USD'),
perpsChannels.klines('BTC-USD', '1m'),
]);
if (ack.rejected.length) console.warn('rejected channels', ack.rejected);
perps.onMessage((message) => {
if (message.type === 'event') {
console.log(message.channel, message.data);
}
});