WebSocket
Stream live data (trades, order books, mempool, social feeds) through the same key and balance. Pikeway proxies the socket and bills the session when it closes.
Connect
Streaming endpoints are marked WS on an API's marketplace page. Connect to the gateway instead of the provider, keeping the provider's path and query:
import WebSocket from 'ws';
// Server-side: send the key as a header
const ws = new WebSocket('wss://gw.pikeway.ai/ws/<slug>/<path>', {
headers: { Authorization: `Bearer ${process.env.PIKEWAY_KEY}` },
});
ws.on('open', () => ws.send(JSON.stringify({ op: 'subscribe', channel: 'trades' })));
ws.on('message', (data) => console.log(data.toString()));
ws.on('close', (code, reason) => {
if (code === 4402) console.log('balance or key limit ran out');
if (code === 4408) console.log('max session length reached, reconnect');
});Authorization: Bearer pk-…?key=pk-…Subprotocols you request are passed through to the provider. The handshake response includes X-Pikeway-Call-Id, which identifies the session in your call log.
Pricing
A session can have up to three price components, set by the provider and shown on the endpoint:
per connectionUSDper messageUSDper minuteUSDThe running cost is tracked live and the whole session is charged once, when it closes. If the provider's server refuses the connection, you get an HTTP error from the handshake and nothing is charged.
Limits and close codes
- Before connecting, your balance (or the key's remaining limit, whichever is lower) must cover the connection fee, otherwise the handshake fails with
402. - At most 10 concurrent connections per key; the 11th gets
429. - Sessions last up to 60 minutes unless the provider sets a different maximum (up to 24 hours). Reconnect when they end.
44024408Handshake errors
401403404426429?key= with a browser key and a spending limit, so a key copied from your page can't be used elsewhere.