-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathwebsocket-streams.ts
More file actions
56 lines (52 loc) · 2.14 KB
/
Copy pathwebsocket-streams.ts
File metadata and controls
56 lines (52 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Binance Derivatives Trading Options WebSocket Market Streams
*
* OpenAPI Specification for the Binance Derivatives Trading Options WebSocket Market Streams
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { ConfigurationWebsocketStreams, WebsocketStreamsBase } from '@binance/common';
import { WebsocketStreamsConnection } from './websocket-streams-connection';
export class WebsocketStreams {
private configuration: ConfigurationWebsocketStreams;
constructor(configuration: ConfigurationWebsocketStreams) {
this.configuration = configuration;
}
/**
* Connects to the Binance WebSocket streams and returns a `WebsocketStreamsConnection` instance.
*
* @param {object} [options] - Optional connection options.
* @param {string|string[]} [options.stream] - The stream(s) to connect to.
* @param {'single'|'pool'} [options.mode] - The connection mode, either 'single' or 'pool'. Overwrite the `mode` option in the configuration.
* @param {number} [options.poolSize] - The number of connections to use in pool mode. Overwrite the `poolSize` option in the configuration.
* @returns {Promise<WebsocketStreamsConnection>} - A promise that resolves to a `WebsocketStreamsConnection` instance.
*/
async connect({
stream,
mode,
poolSize,
}: {
stream?: string | string[];
mode?: 'single' | 'pool';
poolSize?: number;
} = {}): Promise<WebsocketStreamsConnection> {
const websocketBase = new WebsocketStreamsBase(
{
...this.configuration,
...(mode && { mode }),
...(poolSize && { poolSize }),
},
[],
['market', 'public', 'private']
);
websocketBase.streamIdIsStrictlyNumber = true;
const websocketStreamsConnection = new WebsocketStreamsConnection(websocketBase);
await websocketBase.connect(stream);
return websocketStreamsConnection;
}
}