polygon.io
Version:
Isomorphic Javascript client for Polygon.io Stocks, Forex, and Crypto APIs
16 lines (11 loc) • 340 B
text/typescript
import { w3cwebsocket as Websocket } from "websocket";
export const getWsClient = (url: string, apiKey: string): Websocket => {
if (!apiKey) {
throw new Error("api key not provided.");
}
const ws = new Websocket(url);
ws.onopen = () => {
ws.send(JSON.stringify({ action: "auth", params: apiKey }));
};
return ws;
};