-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathwebsocket-streams.ts
More file actions
57 lines (52 loc) · 2.23 KB
/
Copy pathwebsocket-streams.ts
File metadata and controls
57 lines (52 loc) · 2.23 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
57
/**
* Binance Spot WebSocket Streams
*
* OpenAPI Specifications for the Binance Spot WebSocket Streams
*
* API documents:
* - [Github web-socket-streams documentation file](https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md)
* - [General API information for web-socket-streams on website](https://developers.binance.com/docs/binance-spot-api-docs/web-socket-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 }),
});
const websocketStreamsConnection = new WebsocketStreamsConnection(websocketBase);
await websocketBase.connect(stream);
return websocketStreamsConnection;
}
}