Managed rotation
Explicit Chainlink selection
Use one Chainlink subscription per event socket. Combine feeds and windows in the same subscription when you need several:PolyNodeWS. Use another client connection if the selections must be isolated.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Rotate TypeScript subscriptions across short-form crypto markets with the correct Chainlink TWAP window.
| Market interval | Chainlink selection |
|---|---|
5m | 30 seconds |
15m | 60 seconds |
1h | default spot feed |
4h | 60 seconds |
import { PolyNode } 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 stream = pn.ws.shortForm('5m', {
coins: ['btc', 'eth', 'sol'],
});
stream.on('rotation', (rotation) => {
console.log({
windowStart: rotation.windowStart,
windowEnd: rotation.windowEnd,
markets: rotation.markets.map((market) => ({
coin: market.coin,
slug: market.slug,
feed: market.chainlinkFeed,
twapWindowSeconds: market.twapWindowSeconds,
priceToBeat: market.priceToBeat,
})),
});
});
stream.on('settlement', (event) => console.log(event));
stream.on('error', (error) => console.error(error));
const prices = await pn.ws
.subscribe('chainlink')
.feeds(['BTC/USD', 'ETH/USD'])
.twapWindows([30, 60])
.send();
console.log({ source: prices.priceSource, windows: prices.twapWindows });
prices.on('price_feed', (event) => {
console.log(event.feed, event.price, event.is_twap, event.twap_window_seconds);
});
PolyNodeWS. Use another client connection if the selections must be isolated.
stream.stop();
pn.ws.disconnect();
