forked from binance/binance-connector-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest-api.ts
More file actions
342 lines (324 loc) · 16 KB
/
rest-api.ts
File metadata and controls
342 lines (324 loc) · 16 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/**
* Binance Algo REST API
*
* OpenAPI Specification for the Binance Algo REST API
*
* 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 { ConfigurationRestAPI, RestApiResponse, sendRequest } from '@binance/common';
import { FutureAlgoApi } from './modules/future-algo-api';
import { SpotAlgoApi } from './modules/spot-algo-api';
import type {
CancelAlgoOrderFutureAlgoRequest,
QueryCurrentAlgoOpenOrdersFutureAlgoRequest,
QueryHistoricalAlgoOrdersFutureAlgoRequest,
QuerySubOrdersFutureAlgoRequest,
TimeWeightedAveragePriceFutureAlgoRequest,
VolumeParticipationFutureAlgoRequest,
} from './modules/future-algo-api';
import type {
CancelAlgoOrderSpotAlgoRequest,
QueryCurrentAlgoOpenOrdersSpotAlgoRequest,
QueryHistoricalAlgoOrdersSpotAlgoRequest,
QuerySubOrdersSpotAlgoRequest,
TimeWeightedAveragePriceSpotAlgoRequest,
} from './modules/spot-algo-api';
import type {
CancelAlgoOrderFutureAlgoResponse,
QueryCurrentAlgoOpenOrdersFutureAlgoResponse,
QueryHistoricalAlgoOrdersFutureAlgoResponse,
QuerySubOrdersFutureAlgoResponse,
TimeWeightedAveragePriceFutureAlgoResponse,
VolumeParticipationFutureAlgoResponse,
} from './types';
import type {
CancelAlgoOrderSpotAlgoResponse,
QueryCurrentAlgoOpenOrdersSpotAlgoResponse,
QueryHistoricalAlgoOrdersSpotAlgoResponse,
QuerySubOrdersSpotAlgoResponse,
TimeWeightedAveragePriceSpotAlgoResponse,
} from './types';
export class RestAPI {
private configuration: ConfigurationRestAPI;
private futureAlgoApi: FutureAlgoApi;
private spotAlgoApi: SpotAlgoApi;
constructor(configuration: ConfigurationRestAPI) {
this.configuration = configuration;
this.futureAlgoApi = new FutureAlgoApi(configuration);
this.spotAlgoApi = new SpotAlgoApi(configuration);
}
/**
* Generic function to send a request.
* @param endpoint - The API endpoint to call.
* @param method - HTTP method to use (GET, POST, DELETE, etc.).
* @param queryParams - Query parameters for the request.
* @param bodyParams - Body parameters for the request.
*
* @returns A promise resolving to the response data object.
*/
sendRequest<T>(
endpoint: string,
method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH',
queryParams: Record<string, unknown> = {},
bodyParams: Record<string, unknown> = {}
): Promise<RestApiResponse<T>> {
return sendRequest<T>(
this.configuration,
endpoint,
method,
queryParams,
bodyParams,
undefined
);
}
/**
* Generic function to send a signed request.
* @param endpoint - The API endpoint to call.
* @param method - HTTP method to use (GET, POST, DELETE, etc.).
* @param queryParams - Query parameters for the request.
* @param bodyParams - Body parameters for the request.
*
* @returns A promise resolving to the response data object.
*/
sendSignedRequest<T>(
endpoint: string,
method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH',
queryParams: Record<string, unknown> = {},
bodyParams: Record<string, unknown> = {}
): Promise<RestApiResponse<T>> {
return sendRequest<T>(
this.configuration,
endpoint,
method,
queryParams,
bodyParams,
undefined,
{ isSigned: true }
);
}
/**
* Cancel an active order.
*
* You need to enable `Futures Trading Permission` for the api key which requests this endpoint.
* Base URL: https://api.binance.com
*
* Weight: 1
*
* @summary Cancel Algo Order(TRADE)
* @param {CancelAlgoOrderFutureAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<CancelAlgoOrderFutureAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/future-algo/Cancel-Algo-Order Binance API Documentation}
*/
cancelAlgoOrderFutureAlgo(
requestParameters: CancelAlgoOrderFutureAlgoRequest
): Promise<RestApiResponse<CancelAlgoOrderFutureAlgoResponse>> {
return this.futureAlgoApi.cancelAlgoOrderFutureAlgo(requestParameters);
}
/**
* Query Current Algo Open Orders
*
* You need to enable `Futures Trading Permission` for the api key which requests this endpoint.
* Base URL: https://api.binance.com
*
* Weight: 1
*
* @summary Query Current Algo Open Orders(USER_DATA)
* @param {QueryCurrentAlgoOpenOrdersFutureAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<QueryCurrentAlgoOpenOrdersFutureAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/future-algo/Query-Current-Algo-Open-Orders Binance API Documentation}
*/
queryCurrentAlgoOpenOrdersFutureAlgo(
requestParameters: QueryCurrentAlgoOpenOrdersFutureAlgoRequest = {}
): Promise<RestApiResponse<QueryCurrentAlgoOpenOrdersFutureAlgoResponse>> {
return this.futureAlgoApi.queryCurrentAlgoOpenOrdersFutureAlgo(requestParameters);
}
/**
* Query Historical Algo Order
*
* You need to enable `Futures Trading Permission` for the api key which requests this endpoint.
* Base URL: https://api.binance.com
*
* Weight: 1
*
* @summary Query Historical Algo Orders(USER_DATA)
* @param {QueryHistoricalAlgoOrdersFutureAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<QueryHistoricalAlgoOrdersFutureAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/future-algo/Query-Historical-Algo-Orders Binance API Documentation}
*/
queryHistoricalAlgoOrdersFutureAlgo(
requestParameters: QueryHistoricalAlgoOrdersFutureAlgoRequest = {}
): Promise<RestApiResponse<QueryHistoricalAlgoOrdersFutureAlgoResponse>> {
return this.futureAlgoApi.queryHistoricalAlgoOrdersFutureAlgo(requestParameters);
}
/**
* Get respective sub orders for a specified algoId
*
* You need to enable `Futures Trading Permission` for the api key which requests this endpoint.
* Base URL: https://api.binance.com
*
* Weight: 1
*
* @summary Query Sub Orders(USER_DATA)
* @param {QuerySubOrdersFutureAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<QuerySubOrdersFutureAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/future-algo/Query-Sub-Orders Binance API Documentation}
*/
querySubOrdersFutureAlgo(
requestParameters: QuerySubOrdersFutureAlgoRequest
): Promise<RestApiResponse<QuerySubOrdersFutureAlgoResponse>> {
return this.futureAlgoApi.querySubOrdersFutureAlgo(requestParameters);
}
/**
* Send in a Twap new order.
* Only support on USDⓈ-M Contracts.
*
* Total Algo open orders max allowed: `30` orders.
* Leverage of symbols and position mode will be the same as your futures account settings. You can set up through the trading page or fapi.
* Receiving `"success": true` does not mean that your order will be executed. Please use the query order endpoints(`GET sapi/v1/algo/futures/openOrders` or `GET sapi/v1/algo/futures/historicalOrders`) to check the order status.
* For example: Your futures balance is insufficient, or open position with reduce only or position side is inconsistent with your own setting. In these cases you will receive `"success": true`, but the order status will be `expired` after we check it.
* `quantity` * 60 / `duration` should be larger than minQty
* `duration` cannot be less than 5 mins or more than 24 hours.
* For delivery contracts, TWAP end time should be one hour earlier than the delivery time of the symbol.
* You need to enable `Futures Trading Permission` for the api key which requests this endpoint.
* Base URL: https://api.binance.com
*
* Weight: 3000
*
* @summary Time-Weighted Average Price(Twap) New Order(TRADE)
* @param {TimeWeightedAveragePriceFutureAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<TimeWeightedAveragePriceFutureAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/future-algo/Time-Weighted-Average-Price-New-Order Binance API Documentation}
*/
timeWeightedAveragePriceFutureAlgo(
requestParameters: TimeWeightedAveragePriceFutureAlgoRequest
): Promise<RestApiResponse<TimeWeightedAveragePriceFutureAlgoResponse>> {
return this.futureAlgoApi.timeWeightedAveragePriceFutureAlgo(requestParameters);
}
/**
* Send in a VP new order.
* Only support on USDⓈ-M Contracts.
*
* Total Algo open orders max allowed: `10` orders.
* Leverage of symbols and position mode will be the same as your futures account settings. You can set up through the trading page or fapi.
* Receiving `"success": true` does not mean that your order will be executed. Please use the query order endpoints(`GET sapi/v1/algo/futures/openOrders` or `GET sapi/v1/algo/futures/historicalOrders`) to check the order status.
* For example: Your futures balance is insufficient, or open position with reduce only or position side is inconsistent with your own setting. In these cases you will receive `"success": true`, but the order status will be `expired` after we check it.
* You need to enable `Futures Trading Permission` for the api key which requests this endpoint.
* Base URL: https://api.binance.com
*
* Weight: 300
*
* @summary Volume Participation(VP) New Order (TRADE)
* @param {VolumeParticipationFutureAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<VolumeParticipationFutureAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/future-algo/Volume-Participation-New-Order Binance API Documentation}
*/
volumeParticipationFutureAlgo(
requestParameters: VolumeParticipationFutureAlgoRequest
): Promise<RestApiResponse<VolumeParticipationFutureAlgoResponse>> {
return this.futureAlgoApi.volumeParticipationFutureAlgo(requestParameters);
}
/**
* Cancel an open TWAP order
*
* Weight: 1
*
* @summary Cancel Algo Order(TRADE)
* @param {CancelAlgoOrderSpotAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<CancelAlgoOrderSpotAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/spot-algo/Cancel-Algo-Order Binance API Documentation}
*/
cancelAlgoOrderSpotAlgo(
requestParameters: CancelAlgoOrderSpotAlgoRequest
): Promise<RestApiResponse<CancelAlgoOrderSpotAlgoResponse>> {
return this.spotAlgoApi.cancelAlgoOrderSpotAlgo(requestParameters);
}
/**
* Get all open SPOT TWAP orders
*
* Weight: 1
*
* @summary Query Current Algo Open Orders(USER_DATA)
* @param {QueryCurrentAlgoOpenOrdersSpotAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<QueryCurrentAlgoOpenOrdersSpotAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/spot-algo/Query-Current-Algo-Open-Orders Binance API Documentation}
*/
queryCurrentAlgoOpenOrdersSpotAlgo(
requestParameters: QueryCurrentAlgoOpenOrdersSpotAlgoRequest = {}
): Promise<RestApiResponse<QueryCurrentAlgoOpenOrdersSpotAlgoResponse>> {
return this.spotAlgoApi.queryCurrentAlgoOpenOrdersSpotAlgo(requestParameters);
}
/**
* Get all historical SPOT TWAP orders
*
* Weight: 1
*
* @summary Query Historical Algo Orders(USER_DATA)
* @param {QueryHistoricalAlgoOrdersSpotAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<QueryHistoricalAlgoOrdersSpotAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/spot-algo/Query-Historical-Algo-Orders Binance API Documentation}
*/
queryHistoricalAlgoOrdersSpotAlgo(
requestParameters: QueryHistoricalAlgoOrdersSpotAlgoRequest = {}
): Promise<RestApiResponse<QueryHistoricalAlgoOrdersSpotAlgoResponse>> {
return this.spotAlgoApi.queryHistoricalAlgoOrdersSpotAlgo(requestParameters);
}
/**
* Get respective sub orders for a specified algoId
*
* Weight: 1
*
* @summary Query Sub Orders(USER_DATA)
* @param {QuerySubOrdersSpotAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<QuerySubOrdersSpotAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/spot-algo/Query-Sub-Orders Binance API Documentation}
*/
querySubOrdersSpotAlgo(
requestParameters: QuerySubOrdersSpotAlgoRequest
): Promise<RestApiResponse<QuerySubOrdersSpotAlgoResponse>> {
return this.spotAlgoApi.querySubOrdersSpotAlgo(requestParameters);
}
/**
* Place a new spot TWAP order with Algo service.
*
* Total Algo open orders max allowed: `20` orders.
*
* Weight: 3000
*
* @summary Time-Weighted Average Price(Twap) New Order(TRADE)
* @param {TimeWeightedAveragePriceSpotAlgoRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<TimeWeightedAveragePriceSpotAlgoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/algo/spot-algo/Time-Weighted-Average-Price-New-Order Binance API Documentation}
*/
timeWeightedAveragePriceSpotAlgo(
requestParameters: TimeWeightedAveragePriceSpotAlgoRequest
): Promise<RestApiResponse<TimeWeightedAveragePriceSpotAlgoResponse>> {
return this.spotAlgoApi.timeWeightedAveragePriceSpotAlgo(requestParameters);
}
}