///
import WebSocket from 'isomorphic-ws';
import { transformWebsocketShortResponseMessage } from '#client/webSocket/transform';
import type * as kuma from '#index';
import type { WebSocketRequestUnsubscribeShortNames, KumaMessageEvent, KumaSubscribeTypeAuthenticated, KumaSubscribeTypePublic, KumaSubscribeType, WebSocketRequestUnsubscribeSubscription } from '#types/webSocket/index';
export * from '#client/webSocket/guards';
export { transformWebsocketShortResponseMessage };
/**
* This is the doc comment for file1.ts
*
* Specify this is a module comment and rename it to my-module:
* @module my-module
*/
/**
* @internal
*
* How often to send `ping` messages to the server (in milliseconds).
*/
export declare const WEBSOCKET_PING_TIMEOUT_MS = 30000;
/**
* WebSocket Client handler for the `onConnect` method
*/
export type WebSocketHandlerConnect = () => unknown;
/**
* WebSocket Client handler for the `onDisconnect` method
*/
export type WebSocketHandlerDisconnect = (code: number, reason: string) => unknown;
/**
* WebSocket Client handler for the `onError` method
*/
export type WebSocketHandlerError = (error: WebSocket.ErrorEvent) => unknown;
/**
* WebSocket Client handler for the `onMessage` method
*/
export type WebSocketHandlerMessage = (message: KumaMessageEvent) => unknown;
/**
* ### WebSocket API client
*
* You must provide constructor options that match either:
*
* - If you only need {@link KumaSubscribeTypePublic public subscriptions}, all options are optional.
* - If you want to make {@link KumaSubscribeTypeAuthenticated authenticated subscriptions}:
* - You must provide a valid {@link WebSocketClientOptions.auth auth}
* property in the {@link WebSocketClientOptions constructor options} which includes:
* - {@link kuma.WebSocketClientAuthOptions.apiKey apiKey}
* - {@link kuma.WebSocketClientAuthOptions.apiSecret apiSecret}
* - {@link kuma.WebSocketClientAuthOptions.wallet wallet}
*
* @example
* ```typescript
* import {
* WebSocketClient,
* SubscriptionNameAuthenticated,
* SubscriptionNamePublic
* } from '@kumabid/kuma-sdk';
*
* const webSocketClientPublicOnly = new WebSocketClient();
*
* // or ... to enable both public and authenticated subscriptions:
*
* const client = new WebSocketClient({
* // Edit the values before for your environment
* auth: {
* apiKey: '1f7c4f52-4af7-4e1b-aa94-94fac8d931aa',
* apiSecret: 'axuh3ywgg854aq7m73oy6gnnpj5ar9a67szuw5lclbz77zqu0j',
* wallet: '0x...',
* }
* // sandbox: true,
* // logger: console.log
* });
*
* client.onConnect(() => {
* // [see onConnect docs for full example and information]
* })
*
* client.onDisconnect((code, reason) => {
* // [see onDisconnect docs for full example and information]
* })
*
* client.onError(errorEvent => {
* // [see onError docs for full example and information]
* })
*
* client.onMessage(message => {
* console.log('Receiving Message: ', message)
* switch(message.type) {
* case MessageEventType.subscriptions:
* return handleSubscriptions(message.subscriptions);
* case MessageEventType.error:
* return handleAPIError(message.data);
* case MessageEventType.candles:
* return handleCandles(message.data);
* default:
* break;
* })
*
* await client.connect();
*
* // subscribe as needed!
*
* await client
* .subscribePublic([
* {
* name: SubscriptionNamePublic.tickers,
* markets: ['ETH-USD']
* },
* ])
* .subscribeAuthenticated([
* { name: SubscriptionNameAuthenticated.positions },
* { name: SubscriptionNameAuthenticated.orders },
* ]);
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html)
*
* @category API Clients
* @category Kuma - Get Candles
* @category Kuma - Get Deposits
* @category Kuma - Get Funding Payments
* @category Kuma - Get Liquidations
* @category Kuma - Get OrderBook
* @category Kuma - Get Orders
* @category Kuma - Get Positions
* @category Kuma - Get Tickers
* @category Kuma - Get Trades
* @category Kuma - Get Withdrawals
*/
export declare class WebSocketClient {
#private;
/**
* If `true`, this client will throw an error if it attempts to subscribe to
* an {@link KumaSubscribeTypeAuthenticated authenticated subscription}.
*
* - This is determined by whether or not the {@link kuma.WebSocketClientOptions.auth auth}
* property was provided during construction.
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#isPublicOnly)
*
* @category Accessors
*/
get isPublicOnly(): boolean;
/**
* When a client is terminated, it will cease to function and a new WebSocketClient must be created
* to start a new connection.
*/
get terminated(): boolean;
/**
* You can access the current {@link WebSocket}
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#ws)
*
* @category Accessors
*/
get ws(): null | WebSocket;
/**
* A boolean indicating whether the WebSocket client is currently connected to the Kuma WebSocket API.
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#isConnected)
*
* @category Accessors
*/
get isConnected(): boolean;
/**
* ### WebSocket API client
*
* You must provide constructor options that match either:
*
* - If you only need {@link KumaSubscribeTypePublic public subscriptions}, all options are optional.
* - If you want to make {@link KumaSubscribeTypeAuthenticated authenticated subscriptions}:
* - You must provide a valid {@link WebSocketClientOptions.auth auth}
* property in the {@link WebSocketClientOptions constructor options} which includes:
* - {@link kuma.WebSocketClientAuthOptions.apiKey apiKey}
* - {@link kuma.WebSocketClientAuthOptions.apiSecret apiSecret}
* - {@link kuma.WebSocketClientAuthOptions.wallet wallet}
*
* @example
* ```typescript
* import {
* WebSocketClient,
* SubscriptionNameAuthenticated,
* SubscriptionNamePublic
* } from '@kumabid/kuma-sdk';
*
* const webSocketClientPublicOnly = new WebSocketClient();
*
* // or ... to enable both public and authenticated subscriptions:
*
* const client = new WebSocketClient({
* // Edit the values before for your environment
* auth: {
* apiKey: '1f7c4f52-4af7-4e1b-aa94-94fac8d931aa',
* apiSecret: 'axuh3ywgg854aq7m73oy6gnnpj5ar9a67szuw5lclbz77zqu0j',
* wallet: '0x...',
* }
* // sandbox: true,
* // logger: console.log
* });
*
* client.onConnect(() => {
* // [see onConnect docs for full example and information]
* })
*
* client.onDisconnect((code, reason) => {
* // [see onDisconnect docs for full example and information]
* })
*
* client.onError(errorEvent => {
* // [see onError docs for full example and information]
* })
*
* client.onMessage(message => {
* console.log('Receiving Message: ', message)
* switch(message.type) {
* case MessageEventType.subscriptions:
* return handleSubscriptions(message.subscriptions);
* case MessageEventType.error:
* return handleAPIError(message.data);
* case MessageEventType.candles:
* return handleCandles(message.data);
* default:
* break;
* })
*
* await client.connect();
*
* // subscribe as needed!
*
* await client
* .subscribePublic([
* {
* name: SubscriptionNamePublic.tickers,
* markets: ['ETH-USD']
* },
* ])
* .subscribeAuthenticated([
* { name: SubscriptionNameAuthenticated.positions },
* { name: SubscriptionNameAuthenticated.orders },
* ]);
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html)
*/
constructor(options?: kuma.WebSocketClientOptions);
private throwIfTerminated;
/**
* Connect to the [Kuma WebSocket API](https://api-docs-v1.kuma.bid/#websocket-api-interaction)
*
* ---
* @param awaitConnected
* - If `true`, the promise will not resolve until the connection is established
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#connect)
*
* @category Connection Management
*/
connect(awaitConnected?: boolean): Promise;
/**
* Disconnect from the WebSocket if connected.
*
* - If `terminate` is `true`, the WebSocket will be disconnected immediately and this client will
* cease to work or connect.
* - All listeners will be cleared and all methods will throw errors once terminated.
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#disconnect)
*
* @category Connection Management
*/
disconnect(terminate?: boolean): this;
/**
* Subscribe a handler to all WebSocket disconnect events.
*
* - Calling multiple times will add multiple subscribers to the given event
*
* ---
* @param handler
* - A handler function matching {@link WebSocketHandlerConnect} that will receive events.
* @param replaceAll
* - Replaces all current handlers with the provided handler.
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @example
* ```typescript
* websocketClient.onConnect(() => {
* console.warn('WebSocket Connection Connects')
* })
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#onConnect)
*
* @category Event Handling
*/
onConnect(handler: WebSocketHandlerConnect, replaceAll?: boolean): this;
/**
* Subscribe a handler to all WebSocket disconnect events.
*
* ---
* @param handler
* - A handler function matching {@link WebSocketHandlerDisconnect} that will receive events.
* @param replaceAll
* - Replaces all current handlers with the provided handler.
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @example
* ```typescript
* websocketClient.onDisconnect((code, reason) => {
* console.warn('WebSocket Connection Disconnects: ', code, reason)
* })
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#onDisconnect)
*
* @category Event Handling
*/
onDisconnect(handler: WebSocketHandlerDisconnect, replaceAll?: boolean): this;
/**
* Subscribe a handler to all WebSocket connection errors that may occur during
* your requests.
*
* - **Note:** These errors will be coming from the `ws` library itself and provide
* its {@link ErrorEvent} errors.
* - Errors coming from the Kuma WebSocket client will be present as a {@link kuma.KumaErrorEvent KumaErrorEvent}
* message to the {@link onMessage} handler.
*
* ---
* @param handler
* - A handler function matching {@link WebSocketHandlerError} that will receive events.
* @param replaceAll
* - Replaces all current handlers with the provided handler.
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @example
* ```typescript
* websocketClient.onError(errorEvent => {
* console.error('Connection Error on WebSocket: ', errorEvent.error)
* })
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#onError)
*
* @category Event Handling
*/
onError(handler: WebSocketHandlerError, replaceAll?: boolean): this;
/**
* Subscribe a handler to all subscription responses.
*
* - Your handler will receive updates when available matching the {@link KumaMessageEvent}
* interface.
* - Use the {@link kuma.MessageEventType MessageEventType} enum to get an enum
* defining all possible `type` values that can be received on the WebSocket message (see example).
*
* ---
* @param handler
* - A handler function matching {@link WebSocketHandlerMessage} that will receive events.
* @param replaceAll
* - Replaces all current handlers with the provided handler.
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @example
* ```typescript
* import { MessageEventType } from '@kumabid/kuma-sdk';
*
* // ... client setup
*
* websocketClient.onMessage(message => {
* console.log('Receiving Message: ', message)
* switch(message.type) {
* case MessageEventType.subscriptions:
* return handleSubscriptions(message.subscriptions);
* case MessageEventType.error:
* return handleAPIError(message.data);
* case MessageEventType.candles:
* return handleCandles(message.data);
* default:
* break;
* }
* })
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#onMessage)
* @see enum {@link kuma.MessageEventType MessageEventType}
* @see type {@link KumaMessageEvent}
*
* @category Event Handling
*/
onMessage(handler: WebSocketHandlerMessage, replaceAll?: boolean): this;
/**
* Creates new {@link KumaSubscribeTypeAuthenticated authenticated subscriptions} based on the provided parameters.
*
* - Use the {@link kuma.SubscriptionNameAuthenticated SubscriptionNameAuthenticated} enum for IDE
* inline documentation and auto completion (see example)
*
* ---
*
* **Subscription Update Events:**
*
* - Receives a {@link kuma.KumaSubscriptionsListEvent KumaSubscriptionsListEvent} WebSocket response via
* the {@link kuma.WebSocketClient.onMessage WebSocketClient.onMessage} handler listing all active
* subscriptions.
* - Begins receiving {@link kuma.KumaSubscriptionEvent KumaSubscriptionEvent}'s for all subscribed
* subscriptions via the {@link kuma.WebSocketClient.onMessage WebSocketClient.onMessage} handler.
*
* ---
* @param subscriptions
* - An array of {@link KumaSubscribeTypeAuthenticated} subscription objects.
* @param cid
* - Optionally provide a `cid` property which will be returned in the response
* so that you can correlate the response to the request.
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @throws
* > This method will **throw an error** if you did not provide the {@link kuma.WebSocketClientOptionsWithAPIKey.auth auth} option
* to the constructor in order to handle authenticated subscriptions.
*
* ---
*
* @example
* ```typescript
* import {
* WebSocketClient,
* SubscriptionNameAuthenticated,
* } from '@kumabid/kuma-sdk';
*
* const client = new WebSocketClient({
* auth: {
* apiKey: '...',
* apiSecret: '...',
* wallet: '0x...'
* }
* })
*
* client.onMessage(message => {
* console.log('Received WebSocket Message: ', message)
* })
*
* await client.subscribeAuthenticated([
* { name: SubscriptionNameAuthenticated.positions },
* { name: SubscriptionNameAuthenticated.orders },
* ])
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#subscribeAuthenticated)
* @see related {@link subscribePublic client.subscribePublic}
*
* @category Subscription Management
*/
subscribeAuthenticated(
/**
* An array of {@link KumaSubscribeTypeAuthenticated} subscription
* objects.
*/
subscriptions: KumaSubscribeTypeAuthenticated[],
/**
* Optionally provide a `cid` property which will be returned in the response
* so that you can correlate the response to the request.
*/
cid?: string): this;
/**
* This method allows subscribing to Kuma's {@link KumaSubscribeTypePublic public subscriptions}.
*
* - Use the {@link kuma.SubscriptionNamePublic SubscriptionNamePublic} enum for IDE
* inline documentation and auto completion (see example)
*
* ---
*
* **Subscription Update Events:**
*
* - Receives a {@link kuma.KumaSubscriptionsListEvent KumaSubscriptionsListEvent} WebSocket response via
* the {@link kuma.WebSocketClient.onMessage WebSocketClient.onMessage} handler listing all active
* subscriptions.
* - Begins receiving {@link kuma.KumaSubscriptionEvent KumaSubscriptionEvent}'s for all subscribed
* subscriptions via the {@link kuma.WebSocketClient.onMessage WebSocketClient.onMessage} handler.
*
* ---
* @param subscriptions
* - An array of {@link KumaSubscribeTypePublic} subscription objects.
* @param markets
* - Optionally provide top-level markets.
* - Any {@link subscriptions} that **require but do not define** their own `markets`
* array will inherit this set of markets.
* - If a subscription in your {@link subscriptions} array defines its own
* {@link KumaSubscribeType.markets markets} array, the top-level markets
* **will not be inherited**
* @param cid
* - Optionally provide a `cid` property which will be returned in the response
* so that you can correlate the response to the request.
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @example
* ```typescript
* import {
* WebSocketClient,
* SubscriptionNamePublic,
* CandleInterval
* } from '@kumabid/kuma-sdk';
*
* const client = new WebSocketClient();
*
* await client.subscribePublic([
* // will inherit markets from the markets array
* { name: SubscriptionNamePublic.tickers },
* // overrides the top level markets array with its own
* {
* name: SubscriptionNamePublic.candles,
* interval: CandleInterval.ONE_MINUTE,
* // replaces the top-level markets when provided
* markets: ['ETH-USD', 'BTC-USD'],
* },
* ], ['ETH-USD'])
* ```
*
*
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#subscribePublic)
* @see related {@link subscribeAuthenticated client.subscribeAuthenticated}
*
* @category Subscription Management
*/
subscribePublic(subscriptions: KumaSubscribeTypePublic[], markets?: string[], cid?: string): this;
/**
* Unsubscribes from a subscription or subscriptions
*
* ---
*
* **Subscription Update Events:**
*
* - Receives a {@link kuma.KumaSubscriptionsListEvent KumaSubscriptionsListEvent} WebSocket response via
* the {@link kuma.WebSocketClient.onMessage WebSocketClient.onMessage} handler listing all active
* subscriptions.
*
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#unsubscribe)
* @see related {@link WebSocketRequestUnsubscribeSubscription}
*
* @category Subscription Management
*/
unsubscribe(subscriptions?: Array, markets?: string[], cid?: string): this;
/**
* List all active subscriptions
*
* ---
*
* **Subscription Update Events:**
*
* - Receives a {@link kuma.KumaSubscriptionsListEvent KumaSubscriptionsListEvent} WebSocket response via
* the {@link kuma.WebSocketClient.onMessage WebSocketClient.onMessage} handler listing all active
* subscriptions.
*
* ---
* @param cid
* - Optionally provide a `cid` property which will be returned in the response
* so that you can correlate the response to the request.
* @returns
* - `this` to allow chaining with other methods or requests.
* ---
*
* @see typedoc [Reference Documentation](https://sdk-js-docs-v1.kuma.bid/classes/WebSocketClient.html#listSubscriptions)
*
* @category Subscription Management
*/
listSubscriptions(cid?: string): this;
/**
* @internal
*/
protected subscribe(subscriptions: KumaSubscribeType[], markets?: string[], cid?: string): this;
private subscribeRequest;
private createWebSocketIfNeeded;
/**
* Waits until the WebSocket is connected before returning
*
* @internal
*/
private resolveWhenConnected;
private handleWebSocketConnect;
private startPinging;
private stopPinging;
private handleWebSocketClose;
private handleWebSocketError;
private handleWebSocketMessage;
private cancelReconnect;
private reconnect;
private log;
private resetReconnectionState;
private sendMessage;
private throwIfDisconnected;
}
//# sourceMappingURL=index.d.ts.map