@binance/margin-trading 5.0.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -0
- package/dist/index.d.mts +1087 -202
- package/dist/index.d.ts +1087 -202
- package/dist/index.js +172 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -20,28 +20,31 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
BadRequestError: () =>
|
|
24
|
-
ConnectorClientError: () =>
|
|
25
|
-
ForbiddenError: () =>
|
|
26
|
-
MARGIN_TRADING_REST_API_PROD_URL: () =>
|
|
23
|
+
BadRequestError: () => import_common12.BadRequestError,
|
|
24
|
+
ConnectorClientError: () => import_common12.ConnectorClientError,
|
|
25
|
+
ForbiddenError: () => import_common12.ForbiddenError,
|
|
26
|
+
MARGIN_TRADING_REST_API_PROD_URL: () => import_common12.MARGIN_TRADING_REST_API_PROD_URL,
|
|
27
|
+
MARGIN_TRADING_RISK_WS_STREAMS_PROD_URL: () => import_common12.MARGIN_TRADING_RISK_WS_STREAMS_PROD_URL,
|
|
28
|
+
MARGIN_TRADING_WS_STREAMS_PROD_URL: () => import_common12.MARGIN_TRADING_WS_STREAMS_PROD_URL,
|
|
27
29
|
MarginTrading: () => MarginTrading,
|
|
28
30
|
MarginTradingRestAPI: () => rest_api_exports,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
MarginTradingWebsocketStreams: () => websocket_streams_exports,
|
|
32
|
+
NetworkError: () => import_common12.NetworkError,
|
|
33
|
+
NotFoundError: () => import_common12.NotFoundError,
|
|
34
|
+
RateLimitBanError: () => import_common12.RateLimitBanError,
|
|
35
|
+
RequiredError: () => import_common12.RequiredError,
|
|
36
|
+
ServerError: () => import_common12.ServerError,
|
|
37
|
+
TooManyRequestsError: () => import_common12.TooManyRequestsError,
|
|
38
|
+
UnauthorizedError: () => import_common12.UnauthorizedError
|
|
36
39
|
});
|
|
37
40
|
module.exports = __toCommonJS(index_exports);
|
|
38
41
|
|
|
39
42
|
// src/margin-trading.ts
|
|
40
|
-
var
|
|
43
|
+
var import_common11 = require("@binance/common");
|
|
41
44
|
|
|
42
45
|
// package.json
|
|
43
46
|
var name = "@binance/margin-trading";
|
|
44
|
-
var version = "
|
|
47
|
+
var version = "6.0.0";
|
|
45
48
|
|
|
46
49
|
// src/rest-api/index.ts
|
|
47
50
|
var rest_api_exports = {};
|
|
@@ -5570,15 +5573,156 @@ var RestAPI = class {
|
|
|
5570
5573
|
}
|
|
5571
5574
|
};
|
|
5572
5575
|
|
|
5576
|
+
// src/websocket-streams/index.ts
|
|
5577
|
+
var websocket_streams_exports = {};
|
|
5578
|
+
__export(websocket_streams_exports, {
|
|
5579
|
+
WebsocketStreams: () => WebsocketStreams,
|
|
5580
|
+
WebsocketStreamsConnection: () => WebsocketStreamsConnection
|
|
5581
|
+
});
|
|
5582
|
+
|
|
5583
|
+
// src/websocket-streams/websocket-streams.ts
|
|
5584
|
+
var import_common10 = require("@binance/common");
|
|
5585
|
+
|
|
5586
|
+
// src/websocket-streams/websocket-streams-connection.ts
|
|
5587
|
+
var import_common9 = require("@binance/common");
|
|
5588
|
+
var WebsocketStreamsConnection = class {
|
|
5589
|
+
constructor(websocketBase) {
|
|
5590
|
+
this.websocketBase = websocketBase;
|
|
5591
|
+
}
|
|
5592
|
+
/**
|
|
5593
|
+
* Adds an event listener for the specified WebSocket event.
|
|
5594
|
+
* @param event - The WebSocket event to listen for, such as 'open', 'message', 'error', 'close', 'ping', or 'pong'.
|
|
5595
|
+
* @param listener - The callback function to be executed when the event is triggered. The function can accept any number of arguments.
|
|
5596
|
+
*/
|
|
5597
|
+
on(event, listener) {
|
|
5598
|
+
this.websocketBase.on(event, listener);
|
|
5599
|
+
}
|
|
5600
|
+
/**
|
|
5601
|
+
* Removes an event listener for the specified WebSocket event.
|
|
5602
|
+
* @param event - The WebSocket event to stop listening for, such as 'open', 'message', 'error', 'close', 'ping', or 'pong'.
|
|
5603
|
+
* @param listener - The callback function that was previously added as the event listener.
|
|
5604
|
+
*/
|
|
5605
|
+
off(event, listener) {
|
|
5606
|
+
this.websocketBase.off(event, listener);
|
|
5607
|
+
}
|
|
5608
|
+
/**
|
|
5609
|
+
* Disconnects from the WebSocket server.
|
|
5610
|
+
* If there is no active connection, a warning is logged.
|
|
5611
|
+
* Otherwise, all connections in the connection pool are closed gracefully,
|
|
5612
|
+
* and a message is logged indicating that the connection has been disconnected.
|
|
5613
|
+
* @returns A Promise that resolves when all connections have been closed.
|
|
5614
|
+
* @throws Error if the WebSocket client is not set.
|
|
5615
|
+
*/
|
|
5616
|
+
disconnect() {
|
|
5617
|
+
return this.websocketBase.disconnect();
|
|
5618
|
+
}
|
|
5619
|
+
/**
|
|
5620
|
+
* Checks if the WebSocket connection is currently open.
|
|
5621
|
+
* @returns `true` if the connection is open, `false` otherwise.
|
|
5622
|
+
*/
|
|
5623
|
+
isConnected() {
|
|
5624
|
+
return this.websocketBase.isConnected();
|
|
5625
|
+
}
|
|
5626
|
+
/**
|
|
5627
|
+
* Sends a ping message to all connected Websocket servers in the pool.
|
|
5628
|
+
* If no connections are ready, a warning is logged.
|
|
5629
|
+
* For each active connection, the ping message is sent, and debug logs provide details.
|
|
5630
|
+
* @throws Error if a Websocket client is not set for a connection.
|
|
5631
|
+
*/
|
|
5632
|
+
pingServer() {
|
|
5633
|
+
this.websocketBase.pingServer();
|
|
5634
|
+
}
|
|
5635
|
+
/**
|
|
5636
|
+
* Subscribes to one or multiple WebSocket streams
|
|
5637
|
+
* Handles both single and pool modes
|
|
5638
|
+
* @param stream Single stream name or array of stream names to subscribe to
|
|
5639
|
+
* @param id Optional subscription ID
|
|
5640
|
+
* @returns void
|
|
5641
|
+
*/
|
|
5642
|
+
subscribe(stream, id) {
|
|
5643
|
+
this.websocketBase.subscribe(stream, id);
|
|
5644
|
+
}
|
|
5645
|
+
/**
|
|
5646
|
+
* Unsubscribes from one or multiple WebSocket streams
|
|
5647
|
+
* Handles both single and pool modes
|
|
5648
|
+
* @param stream Single stream name or array of stream names to unsubscribe from
|
|
5649
|
+
* @param id Optional unsubscription ID
|
|
5650
|
+
* @returns void
|
|
5651
|
+
*/
|
|
5652
|
+
unsubscribe(stream, id) {
|
|
5653
|
+
this.websocketBase.unsubscribe(stream, id);
|
|
5654
|
+
}
|
|
5655
|
+
/**
|
|
5656
|
+
* Checks if the WebSocket connection is subscribed to the specified stream.
|
|
5657
|
+
* @param stream The name of the WebSocket stream to check.
|
|
5658
|
+
* @returns `true` if the connection is subscribed to the stream, `false` otherwise.
|
|
5659
|
+
*/
|
|
5660
|
+
isSubscribed(stream) {
|
|
5661
|
+
return this.websocketBase.isSubscribed(stream);
|
|
5662
|
+
}
|
|
5663
|
+
/**
|
|
5664
|
+
* Subscribes to the risk data WebSocket stream using the provided listen key.
|
|
5665
|
+
* @param listenKey - The listen key for the risk data WebSocket stream.
|
|
5666
|
+
* @param id - Optional risk data stream ID
|
|
5667
|
+
* @returns A WebSocket stream handler for the risk data stream.
|
|
5668
|
+
*/
|
|
5669
|
+
riskData(listenKey, id) {
|
|
5670
|
+
return (0, import_common9.createStreamHandler)(this.websocketBase, listenKey, id);
|
|
5671
|
+
}
|
|
5672
|
+
/**
|
|
5673
|
+
* Subscribes to the trade data WebSocket stream using the provided listen key.
|
|
5674
|
+
* @param listenKey - The listen key for the trade data WebSocket stream.
|
|
5675
|
+
* @param id - Optional trade data stream ID
|
|
5676
|
+
* @returns A WebSocket stream handler for the trade data stream.
|
|
5677
|
+
*/
|
|
5678
|
+
tradeData(listenKey, id) {
|
|
5679
|
+
return (0, import_common9.createStreamHandler)(
|
|
5680
|
+
this.websocketBase,
|
|
5681
|
+
listenKey,
|
|
5682
|
+
id
|
|
5683
|
+
);
|
|
5684
|
+
}
|
|
5685
|
+
};
|
|
5686
|
+
|
|
5687
|
+
// src/websocket-streams/websocket-streams.ts
|
|
5688
|
+
var WebsocketStreams = class {
|
|
5689
|
+
constructor(configuration) {
|
|
5690
|
+
this.configuration = configuration;
|
|
5691
|
+
}
|
|
5692
|
+
/**
|
|
5693
|
+
* Connects to the Binance WebSocket streams and returns a `WebsocketStreamsConnection` instance.
|
|
5694
|
+
*
|
|
5695
|
+
* @param {object} [options] - Optional connection options.
|
|
5696
|
+
* @param {string|string[]} [options.stream] - The stream(s) to connect to.
|
|
5697
|
+
* @param {'single'|'pool'} [options.mode] - The connection mode, either 'single' or 'pool'. Overwrite the `mode` option in the configuration.
|
|
5698
|
+
* @param {number} [options.poolSize] - The number of connections to use in pool mode. Overwrite the `poolSize` option in the configuration.
|
|
5699
|
+
* @returns {Promise<WebsocketStreamsConnection>} - A promise that resolves to a `WebsocketStreamsConnection` instance.
|
|
5700
|
+
*/
|
|
5701
|
+
async connect({
|
|
5702
|
+
stream,
|
|
5703
|
+
mode,
|
|
5704
|
+
poolSize
|
|
5705
|
+
} = {}) {
|
|
5706
|
+
const websocketBase = new import_common10.WebsocketStreamsBase({
|
|
5707
|
+
...this.configuration,
|
|
5708
|
+
...mode && { mode },
|
|
5709
|
+
...poolSize && { poolSize }
|
|
5710
|
+
});
|
|
5711
|
+
const websocketStreamsConnection = new WebsocketStreamsConnection(websocketBase);
|
|
5712
|
+
await websocketBase.connect(stream);
|
|
5713
|
+
return websocketStreamsConnection;
|
|
5714
|
+
}
|
|
5715
|
+
};
|
|
5716
|
+
|
|
5573
5717
|
// src/margin-trading.ts
|
|
5574
5718
|
var MarginTrading = class {
|
|
5575
5719
|
constructor(config) {
|
|
5576
|
-
const userAgent = (0,
|
|
5720
|
+
const userAgent = (0, import_common11.buildUserAgent)(name, version);
|
|
5577
5721
|
if (config?.configurationRestAPI) {
|
|
5578
|
-
const configRestAPI = new
|
|
5722
|
+
const configRestAPI = new import_common11.ConfigurationRestAPI(
|
|
5579
5723
|
config.configurationRestAPI
|
|
5580
5724
|
);
|
|
5581
|
-
configRestAPI.basePath = configRestAPI.basePath ||
|
|
5725
|
+
configRestAPI.basePath = configRestAPI.basePath || import_common11.MARGIN_TRADING_REST_API_PROD_URL;
|
|
5582
5726
|
configRestAPI.baseOptions = configRestAPI.baseOptions || {};
|
|
5583
5727
|
configRestAPI.baseOptions.headers = {
|
|
5584
5728
|
...configRestAPI.baseOptions.headers || {},
|
|
@@ -5586,19 +5730,30 @@ var MarginTrading = class {
|
|
|
5586
5730
|
};
|
|
5587
5731
|
this.restAPI = new RestAPI(configRestAPI);
|
|
5588
5732
|
}
|
|
5733
|
+
if (config?.configurationWebsocketStreams) {
|
|
5734
|
+
const configWebsocketStreams = new import_common11.ConfigurationWebsocketStreams(
|
|
5735
|
+
config.configurationWebsocketStreams
|
|
5736
|
+
);
|
|
5737
|
+
configWebsocketStreams.wsURL = configWebsocketStreams.wsURL || import_common11.MARGIN_TRADING_WS_STREAMS_PROD_URL;
|
|
5738
|
+
configWebsocketStreams.userAgent = userAgent;
|
|
5739
|
+
this.websocketStreams = new WebsocketStreams(configWebsocketStreams);
|
|
5740
|
+
}
|
|
5589
5741
|
}
|
|
5590
5742
|
};
|
|
5591
5743
|
|
|
5592
5744
|
// src/index.ts
|
|
5593
|
-
var
|
|
5745
|
+
var import_common12 = require("@binance/common");
|
|
5594
5746
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5595
5747
|
0 && (module.exports = {
|
|
5596
5748
|
BadRequestError,
|
|
5597
5749
|
ConnectorClientError,
|
|
5598
5750
|
ForbiddenError,
|
|
5599
5751
|
MARGIN_TRADING_REST_API_PROD_URL,
|
|
5752
|
+
MARGIN_TRADING_RISK_WS_STREAMS_PROD_URL,
|
|
5753
|
+
MARGIN_TRADING_WS_STREAMS_PROD_URL,
|
|
5600
5754
|
MarginTrading,
|
|
5601
5755
|
MarginTradingRestAPI,
|
|
5756
|
+
MarginTradingWebsocketStreams,
|
|
5602
5757
|
NetworkError,
|
|
5603
5758
|
NotFoundError,
|
|
5604
5759
|
RateLimitBanError,
|