|
| 1 | +import { RestClientOptions } from '../../util/requestUtils'; |
| 2 | +import { WS_KEY_MAP } from '../../util/websockets/websocket-util'; |
| 3 | + |
| 4 | +/** For spot markets, spotV3 is recommended */ |
| 5 | +export type APIMarket = 'v5'; |
| 6 | + |
| 7 | +// Same as inverse futures |
| 8 | +export type WsPublicInverseTopic = |
| 9 | + | 'orderBookL2_25' |
| 10 | + | 'orderBookL2_200' |
| 11 | + | 'trade' |
| 12 | + | 'insurance' |
| 13 | + | 'instrument_info' |
| 14 | + | 'klineV2'; |
| 15 | + |
| 16 | +export type WsPublicUSDTPerpTopic = |
| 17 | + | 'orderBookL2_25' |
| 18 | + | 'orderBookL2_200' |
| 19 | + | 'trade' |
| 20 | + | 'insurance' |
| 21 | + | 'instrument_info' |
| 22 | + | 'kline'; |
| 23 | + |
| 24 | +export type WsPublicSpotV1Topic = |
| 25 | + | 'trade' |
| 26 | + | 'realtimes' |
| 27 | + | 'kline' |
| 28 | + | 'depth' |
| 29 | + | 'mergedDepth' |
| 30 | + | 'diffDepth'; |
| 31 | + |
| 32 | +export type WsPublicSpotV2Topic = |
| 33 | + | 'depth' |
| 34 | + | 'kline' |
| 35 | + | 'trade' |
| 36 | + | 'bookTicker' |
| 37 | + | 'realtimes'; |
| 38 | + |
| 39 | +export type WsPublicTopics = |
| 40 | + | WsPublicInverseTopic |
| 41 | + | WsPublicUSDTPerpTopic |
| 42 | + | WsPublicSpotV1Topic |
| 43 | + | WsPublicSpotV2Topic |
| 44 | + | string; |
| 45 | + |
| 46 | +// Same as inverse futures |
| 47 | +export type WsPrivateInverseTopic = |
| 48 | + | 'position' |
| 49 | + | 'execution' |
| 50 | + | 'order' |
| 51 | + | 'stop_order'; |
| 52 | + |
| 53 | +export type WsPrivateUSDTPerpTopic = |
| 54 | + | 'position' |
| 55 | + | 'execution' |
| 56 | + | 'order' |
| 57 | + | 'stop_order' |
| 58 | + | 'wallet'; |
| 59 | + |
| 60 | +export type WsPrivateSpotTopic = |
| 61 | + | 'outboundAccountInfo' |
| 62 | + | 'executionReport' |
| 63 | + | 'ticketInfo'; |
| 64 | + |
| 65 | +export type WsPrivateTopic = |
| 66 | + | WsPrivateInverseTopic |
| 67 | + | WsPrivateUSDTPerpTopic |
| 68 | + | WsPrivateSpotTopic |
| 69 | + | string; |
| 70 | + |
| 71 | +export type WsTopic = WsPublicTopics | WsPrivateTopic; |
| 72 | + |
| 73 | +/** This is used to differentiate between each of the available websocket streams (as bybit has multiple websockets) */ |
| 74 | +export type WsKey = (typeof WS_KEY_MAP)[keyof typeof WS_KEY_MAP]; |
| 75 | +export type WsMarket = 'all'; |
| 76 | + |
| 77 | +export interface WSClientConfigurableOptions { |
| 78 | + /** Your API key */ |
| 79 | + key?: string; |
| 80 | + |
| 81 | + /** Your API secret */ |
| 82 | + secret?: string; |
| 83 | + |
| 84 | + /** |
| 85 | + * Set to `true` to connect to Bybit's testnet environment. |
| 86 | + * |
| 87 | + * Notes: |
| 88 | + * |
| 89 | + * - If demo trading, `testnet` should be set to false! |
| 90 | + * - If testing a strategy, use demo trading instead. Testnet market data is very different from real market conditions. |
| 91 | + */ |
| 92 | + testnet?: boolean; |
| 93 | + |
| 94 | + /** |
| 95 | + * Set to `true` to connect to Bybit's V5 demo trading: https://bybit-exchange.github.io/docs/v5/demo |
| 96 | + * |
| 97 | + * Only the "V5" "market" is supported here. |
| 98 | + */ |
| 99 | + demoTrading?: boolean; |
| 100 | + |
| 101 | + /** |
| 102 | + * The API group this client should connect to. The V5 market is currently used by default. |
| 103 | + * |
| 104 | + * Only the "V5" "market" is supported here. |
| 105 | + */ |
| 106 | + market?: APIMarket; |
| 107 | + |
| 108 | + /** Define a recv window when preparing a private websocket signature. This is in milliseconds, so 5000 == 5 seconds */ |
| 109 | + recvWindow?: number; |
| 110 | + |
| 111 | + /** How often to check if the connection is alive */ |
| 112 | + pingInterval?: number; |
| 113 | + |
| 114 | + /** How long to wait for a pong (heartbeat reply) before assuming the connection is dead */ |
| 115 | + pongTimeout?: number; |
| 116 | + |
| 117 | + /** Delay in milliseconds before respawning the connection */ |
| 118 | + reconnectTimeout?: number; |
| 119 | + |
| 120 | + restOptions?: RestClientOptions; |
| 121 | + |
| 122 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 123 | + requestOptions?: any; |
| 124 | + |
| 125 | + wsUrl?: string; |
| 126 | + |
| 127 | + /** |
| 128 | + * Allows you to provide a custom "signMessage" function, e.g. to use node's much faster createHmac method |
| 129 | + * |
| 130 | + * Look in the examples folder for a demonstration on using node's createHmac instead. |
| 131 | + */ |
| 132 | + customSignMessageFn?: (message: string, secret: string) => Promise<string>; |
| 133 | +} |
| 134 | + |
| 135 | +/** |
| 136 | + * WS configuration that's always defined, regardless of user configuration |
| 137 | + * (usually comes from defaults if there's no user-provided values) |
| 138 | + */ |
| 139 | +export interface WebsocketClientOptions extends WSClientConfigurableOptions { |
| 140 | + market: APIMarket; |
| 141 | + pongTimeout: number; |
| 142 | + pingInterval: number; |
| 143 | + reconnectTimeout: number; |
| 144 | + recvWindow: number; |
| 145 | + authPrivateConnectionsOnConnect: boolean; |
| 146 | + authPrivateRequests: boolean; |
| 147 | +} |
0 commit comments