UNPKG

okx-api

Version:

Complete Node.js SDK for OKX's REST APIs and WebSockets, with TypeScript & end-to-end tests

147 lines (146 loc) 6.59 kB
import { APIMarket } from '../types/shared.js'; import { WSAPIOperation, WSAPIRequestOKX } from '../types/websockets/ws-api.js'; import { WebsocketClientOptions } from '../types/websockets/ws-general.js'; import { WsChannel } from '../types/websockets/ws-request.js'; import { DefaultLogger } from './logger.js'; export declare const WS_LOGGER_CATEGORY: { category: string; }; export declare const WS_BASE_URL_MAP: Record<APIMarket, Record<'live' | 'demo', Record<'public' | 'private' | 'business', string>>>; export declare const WS_KEY_MAP: { /** * Public WS connection for OKX Global (www.okx.com), does not require auth. */ readonly prodPublic: "prodPublic"; /** * Private WS connection for OKX Global (www.okx.com), requires auth. */ readonly prodPrivate: "prodPrivate"; /** * Business WS connection for OKX Global (www.okx.com), sometimes requires auth. */ readonly prodBusiness: "prodBusiness"; /** * Public DEMO WS connection for OKX Global (www.okx.com), does not require auth. */ readonly prodDemoPublic: "prodDemoPublic"; /** * Private DEMO WS connection for OKX Global (www.okx.com), requires auth. */ readonly prodDemoPrivate: "prodDemoPrivate"; /** * Business DEMO WS connection for OKX Global (www.okx.com), sometimes requires auth. */ readonly prodDemoBusiness: "prodDemoBusiness"; /** * Public WS connection for OKX EEA (my.okx.com), does not require auth. */ readonly eeaLivePublic: "eeaLivePublic"; /** * Private WS connection for OKX EEA (my.okx.com), requires auth. */ readonly eeaLivePrivate: "eeaLivePrivate"; /** * Business WS connection for OKX EEA (my.okx.com), sometimes requires auth. */ readonly eeaLiveBusiness: "eeaLiveBusiness"; /** * Public DEMO WS connection for OKX EEA (my.okx.com), does not require auth. */ readonly eeaDemoPublic: "eeaDemoPublic"; /** * Private DEMO WS connection for OKX EEA (my.okx.com), requires auth. */ readonly eeaDemoPrivate: "eeaDemoPrivate"; /** * Business DEMO WS connection for OKX EEA (my.okx.com), sometimes requires auth. */ readonly eeaDemoBusiness: "eeaDemoBusiness"; /** * Public WS connection for OKX US (app.okx.com), does not require auth. */ readonly usLivePublic: "usLivePublic"; /** * Private WS connection for OKX US (app.okx.com), requires auth. */ readonly usLivePrivate: "usLivePrivate"; /** * Business WS connection for OKX US (app.okx.com), sometimes requires auth. */ readonly usLiveBusiness: "usLiveBusiness"; readonly usDemoPublic: "usDemoPublic"; readonly usDemoPrivate: "usDemoPrivate"; readonly usDemoBusiness: "usDemoBusiness"; }; /** This is used to differentiate between each of the available websocket streams (as bybit has multiple websockets) */ export type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP]; export declare const PRIVATE_WS_KEYS: WsKey[]; export declare const MIXED_WS_KEYS: WsKey[]; export declare const PUBLIC_WS_KEYS: WsKey[]; /** * Returns the DEMO connection WsKey for the provided WsKey */ export declare function getDemoWsKey(wsKey: WsKey): WsKey; /** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */ export declare const PRIVATE_CHANNELS: string[]; export declare const PUBLIC_CHANNELS_WITH_AUTH: string[]; /** Determine which WsKey (ws connection) to route an event to */ export declare function getWsKeyForTopicChannel(market: APIMarket, channel: WsChannel, isPrivate?: boolean): WsKey; /** * Returns wsKey for product group. Demo resolution is handled in URL lookup function, separately. */ export declare function getWsKeyForMarket(market: APIMarket, isPrivate: boolean, isBusinessChannel: boolean): WsKey; export declare function requiresWSAPITag(operation: WSAPIOperation, wsKey: WsKey): boolean; export declare function validateWSAPITag(request: WSAPIRequestOKX<any>, wsKey: WsKey): void; /** * Maps a WS key back to a WS URL. Resolves to demo wsKey automatically, if configured. */ export declare function getWsUrlForWsKey(wsKey: WsKey, wsClientOptions: WebsocketClientOptions, logger: typeof DefaultLogger): string; export declare function getMaxTopicsPerSubscribeEventForMarket(market: APIMarket): number | null; export declare function isWsPong(event: unknown): boolean; export declare const WS_EVENT_CODE_ENUM: { OK: string; LOGIN_FAILED: string; LOGIN_PARTIALLY_FAILED: string; }; /** * #305: ws.terminate() is undefined in browsers. * This only works in node.js, not in browsers. * Does nothing if `ws` is undefined. Does nothing in browsers. */ export declare function safeTerminateWs(ws?: WebSocket | any, fallbackToClose?: boolean): boolean; /** * Normalised internal format for a request (subscribe/unsubscribe/etc) on a topic, with optional parameters. * * - Topic: the topic this event is for * - Payload: the parameters to include, optional. E.g. auth requires key + sign. Some topics allow configurable parameters. */ export interface WsTopicRequest<TWSTopic extends string = string, TWSPayload = unknown> { topic: TWSTopic; payload?: TWSPayload; } /** * Conveniently allow users to request a topic either as string topics or objects (containing string topic + params) */ export type WsTopicRequestOrStringTopic<TWSTopic extends string, TWSPayload = unknown> = WsTopicRequest<TWSTopic, TWSPayload> | string; /** * Users can conveniently pass topics as strings or objects (object has topic name + optional params). * * This method normalises topics into objects (object has topic name + optional params). */ export declare function getNormalisedTopicRequests(wsTopicRequests: WsTopicRequestOrStringTopic<string>[]): WsTopicRequest<string>[]; /** * WebSocket.ping() is not available in browsers. This is a simple check used to * disable heartbeats in browers, for exchanges that use native WebSocket ping/pong frames. */ export declare function isWSPingFrameAvailable(): boolean; /** * WebSocket.pong() is not available in browsers. This is a simple check used to * disable heartbeats in browers, for exchanges that use native WebSocket ping/pong frames. */ export declare function isWSPongFrameAvailable(): boolean; /** * WS API promises are stored using a primary key. This key is constructed using * properties found in every request & reply. */ export declare function getPromiseRefForWSAPIRequest(requestEvent: WSAPIRequestOKX<unknown>): string;