ccxt 4.0.89 → 4.0.90
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 +3 -3
- package/dist/ccxt.browser.js +1012 -47
- package/dist/ccxt.browser.min.js +10 -10
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/base/Exchange.js +62 -0
- package/dist/cjs/src/bitmex.js +1 -0
- package/dist/cjs/src/pro/binance.js +190 -15
- package/dist/cjs/src/pro/bitget.js +127 -0
- package/dist/cjs/src/pro/bitmex.js +46 -0
- package/dist/cjs/src/pro/bybit.js +129 -2
- package/dist/cjs/src/pro/coinbasepro.js +70 -0
- package/dist/cjs/src/pro/cryptocom.js +71 -0
- package/dist/cjs/src/pro/gate.js +29 -0
- package/dist/cjs/src/pro/kucoin.js +92 -3
- package/dist/cjs/src/pro/kucoinfutures.js +91 -5
- package/dist/cjs/src/pro/okx.js +82 -0
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/base/Exchange.d.ts +17 -0
- package/js/src/base/Exchange.js +62 -0
- package/js/src/bitmex.js +1 -0
- package/js/src/pro/binance.d.ts +3 -0
- package/js/src/pro/binance.js +190 -15
- package/js/src/pro/bitget.d.ts +4 -0
- package/js/src/pro/bitget.js +127 -0
- package/js/src/pro/bitmex.d.ts +1 -0
- package/js/src/pro/bitmex.js +46 -0
- package/js/src/pro/bybit.d.ts +3 -0
- package/js/src/pro/bybit.js +130 -3
- package/js/src/pro/coinbasepro.d.ts +2 -0
- package/js/src/pro/coinbasepro.js +71 -1
- package/js/src/pro/cryptocom.d.ts +3 -0
- package/js/src/pro/cryptocom.js +71 -0
- package/js/src/pro/gate.d.ts +1 -0
- package/js/src/pro/gate.js +29 -0
- package/js/src/pro/kucoin.d.ts +2 -0
- package/js/src/pro/kucoin.js +93 -4
- package/js/src/pro/kucoinfutures.d.ts +2 -0
- package/js/src/pro/kucoinfutures.js +92 -6
- package/js/src/pro/okx.d.ts +2 -0
- package/js/src/pro/okx.js +83 -1
- package/package.json +1 -1
|
@@ -17,6 +17,8 @@ class kucoin extends kucoin$1 {
|
|
|
17
17
|
'watchTickers': false,
|
|
18
18
|
'watchTicker': true,
|
|
19
19
|
'watchTrades': true,
|
|
20
|
+
'watchTradesForSymbols': true,
|
|
21
|
+
'watchOrderBookForSymbols': true,
|
|
20
22
|
'watchBalance': true,
|
|
21
23
|
'watchOHLCV': true,
|
|
22
24
|
},
|
|
@@ -291,6 +293,36 @@ class kucoin extends kucoin$1 {
|
|
|
291
293
|
}
|
|
292
294
|
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
293
295
|
}
|
|
296
|
+
async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
|
|
297
|
+
/**
|
|
298
|
+
* @method
|
|
299
|
+
* @name kucoin#watchTrades
|
|
300
|
+
* @description get the list of most recent trades for a particular symbol
|
|
301
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
302
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
303
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
304
|
+
* @param {object} [params] extra parameters specific to the kucoin api endpoint
|
|
305
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
|
|
306
|
+
*/
|
|
307
|
+
const symbolsLength = symbols.length;
|
|
308
|
+
if (symbolsLength === 0) {
|
|
309
|
+
throw new errors.ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
|
|
310
|
+
}
|
|
311
|
+
await this.loadMarkets();
|
|
312
|
+
symbols = this.marketSymbols(symbols);
|
|
313
|
+
const url = await this.negotiate(false);
|
|
314
|
+
symbols = this.marketSymbols(symbols);
|
|
315
|
+
const marketIds = this.marketIds(symbols);
|
|
316
|
+
const topic = '/market/match:' + marketIds.join(',');
|
|
317
|
+
const messageHash = 'multipleTrades::' + symbols.join(',');
|
|
318
|
+
const trades = await this.subscribe(url, messageHash, topic, params);
|
|
319
|
+
if (this.newUpdates) {
|
|
320
|
+
const first = this.safeValue(trades, 0);
|
|
321
|
+
const tradeSymbol = this.safeString(first, 'symbol');
|
|
322
|
+
limit = trades.getLimit(tradeSymbol, limit);
|
|
323
|
+
}
|
|
324
|
+
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
325
|
+
}
|
|
294
326
|
handleTrade(client, message) {
|
|
295
327
|
//
|
|
296
328
|
// {
|
|
@@ -323,6 +355,8 @@ class kucoin extends kucoin$1 {
|
|
|
323
355
|
}
|
|
324
356
|
trades.append(trade);
|
|
325
357
|
client.resolve(trades, messageHash);
|
|
358
|
+
// watchMultipleTrades
|
|
359
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleTrades::', symbol, trades);
|
|
326
360
|
}
|
|
327
361
|
async watchOrderBook(symbol, limit = undefined, params = {}) {
|
|
328
362
|
/**
|
|
@@ -368,6 +402,39 @@ class kucoin extends kucoin$1 {
|
|
|
368
402
|
const orderbook = await this.subscribe(url, messageHash, topic, params, subscription);
|
|
369
403
|
return orderbook.limit();
|
|
370
404
|
}
|
|
405
|
+
async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
|
|
406
|
+
/**
|
|
407
|
+
* @method
|
|
408
|
+
* @name kucoin#watchOrderBookForSymbols
|
|
409
|
+
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
410
|
+
* @param {string[]} symbols unified array of symbols
|
|
411
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
412
|
+
* @param {object} [params] extra parameters specific to the kucoin api endpoint
|
|
413
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
414
|
+
*/
|
|
415
|
+
const symbolsLength = symbols.length;
|
|
416
|
+
if (symbolsLength === 0) {
|
|
417
|
+
throw new errors.ArgumentsRequired(this.id + ' watchOrderBookForSymbols() requires a non-empty array of symbols');
|
|
418
|
+
}
|
|
419
|
+
if (limit !== undefined) {
|
|
420
|
+
if ((limit !== 20) && (limit !== 100)) {
|
|
421
|
+
throw new errors.ExchangeError(this.id + " watchOrderBook 'limit' argument must be undefined, 20 or 100");
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
await this.loadMarkets();
|
|
425
|
+
symbols = this.marketSymbols(symbols);
|
|
426
|
+
const marketIds = this.marketIds(symbols);
|
|
427
|
+
const url = await this.negotiate(false);
|
|
428
|
+
const topic = '/market/level2:' + marketIds.join(',');
|
|
429
|
+
const messageHash = 'multipleOrderbook::' + symbols.join(',');
|
|
430
|
+
const subscription = {
|
|
431
|
+
'method': this.handleOrderBookSubscription,
|
|
432
|
+
'symbols': symbols,
|
|
433
|
+
'limit': limit,
|
|
434
|
+
};
|
|
435
|
+
const orderbook = await this.subscribe(url, messageHash, topic, params, subscription);
|
|
436
|
+
return orderbook.limit();
|
|
437
|
+
}
|
|
371
438
|
handleOrderBook(client, message) {
|
|
372
439
|
//
|
|
373
440
|
// initial snapshot is fetched with ccxt's fetchOrderBook
|
|
@@ -398,7 +465,18 @@ class kucoin extends kucoin$1 {
|
|
|
398
465
|
if (nonce === undefined) {
|
|
399
466
|
const cacheLength = storedOrderBook.cache.length;
|
|
400
467
|
const topic = this.safeString(message, 'topic');
|
|
401
|
-
const
|
|
468
|
+
const topicParts = topic.split(':');
|
|
469
|
+
const topicSymbol = this.safeString(topicParts, 1);
|
|
470
|
+
const topicChannel = this.safeString(topicParts, 0);
|
|
471
|
+
const subscriptions = Object.keys(client.subscriptions);
|
|
472
|
+
let subscription = undefined;
|
|
473
|
+
for (let i = 0; i < subscriptions.length; i++) {
|
|
474
|
+
const key = subscriptions[i];
|
|
475
|
+
if ((key.indexOf(topicSymbol) >= 0) && (key.indexOf(topicChannel) >= 0)) {
|
|
476
|
+
subscription = client.subscriptions[key];
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
402
480
|
const limit = this.safeInteger(subscription, 'limit');
|
|
403
481
|
const snapshotDelay = this.handleOption('watchOrderBook', 'snapshotDelay', 5);
|
|
404
482
|
if (cacheLength === snapshotDelay) {
|
|
@@ -412,6 +490,8 @@ class kucoin extends kucoin$1 {
|
|
|
412
490
|
}
|
|
413
491
|
this.handleDelta(storedOrderBook, data);
|
|
414
492
|
client.resolve(storedOrderBook, messageHash);
|
|
493
|
+
// watchMultipleOrderBook
|
|
494
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleOrderbook::', symbol, storedOrderBook);
|
|
415
495
|
}
|
|
416
496
|
getCacheIndex(orderbook, cache) {
|
|
417
497
|
const firstDelta = this.safeValue(cache, 0);
|
|
@@ -450,9 +530,18 @@ class kucoin extends kucoin$1 {
|
|
|
450
530
|
}
|
|
451
531
|
}
|
|
452
532
|
handleOrderBookSubscription(client, message, subscription) {
|
|
453
|
-
const symbol = this.safeString(subscription, 'symbol');
|
|
454
533
|
const limit = this.safeInteger(subscription, 'limit');
|
|
455
|
-
|
|
534
|
+
const symbols = this.safeValue(subscription, 'symbols');
|
|
535
|
+
if (symbols === undefined) {
|
|
536
|
+
const symbol = this.safeString(subscription, 'symbol');
|
|
537
|
+
this.orderbooks[symbol] = this.orderBook({}, limit);
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
541
|
+
const symbol = symbols[i];
|
|
542
|
+
this.orderbooks[symbol] = this.orderBook({}, limit);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
456
545
|
// moved snapshot initialization to handleOrderBook to fix
|
|
457
546
|
// https://github.com/ccxt/ccxt/issues/6820
|
|
458
547
|
// the general idea is to fetch the snapshot after the first delta
|
|
@@ -16,6 +16,8 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
16
16
|
'watchOrderBook': true,
|
|
17
17
|
'watchOrders': true,
|
|
18
18
|
'watchBalance': true,
|
|
19
|
+
'watchTradesForSymbols': true,
|
|
20
|
+
'watchOrderBookForSymbols': true,
|
|
19
21
|
},
|
|
20
22
|
'options': {
|
|
21
23
|
'accountsByType': {
|
|
@@ -199,6 +201,36 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
199
201
|
}
|
|
200
202
|
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
201
203
|
}
|
|
204
|
+
async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
|
|
205
|
+
/**
|
|
206
|
+
* @method
|
|
207
|
+
* @name kucoinfutures#watchTrades
|
|
208
|
+
* @description get the list of most recent trades for a particular symbol
|
|
209
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
210
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
211
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
212
|
+
* @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
|
|
213
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
|
|
214
|
+
*/
|
|
215
|
+
const symbolsLength = symbols.length;
|
|
216
|
+
if (symbolsLength === 0) {
|
|
217
|
+
throw new errors.ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
|
|
218
|
+
}
|
|
219
|
+
await this.loadMarkets();
|
|
220
|
+
symbols = this.marketSymbols(symbols);
|
|
221
|
+
const url = await this.negotiate(false);
|
|
222
|
+
symbols = this.marketSymbols(symbols);
|
|
223
|
+
const marketIds = this.marketIds(symbols);
|
|
224
|
+
const topic = '/contractMarket/execution:' + marketIds.join(',');
|
|
225
|
+
const messageHash = 'multipleTrades::' + symbols.join(',');
|
|
226
|
+
const trades = await this.subscribe(url, messageHash, topic, params);
|
|
227
|
+
if (this.newUpdates) {
|
|
228
|
+
const first = this.safeValue(trades, 0);
|
|
229
|
+
const tradeSymbol = this.safeString(first, 'symbol');
|
|
230
|
+
limit = trades.getLimit(tradeSymbol, limit);
|
|
231
|
+
}
|
|
232
|
+
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
233
|
+
}
|
|
202
234
|
handleTrade(client, message) {
|
|
203
235
|
//
|
|
204
236
|
// {
|
|
@@ -232,6 +264,7 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
232
264
|
trades.append(trade);
|
|
233
265
|
const messageHash = 'trades:' + symbol;
|
|
234
266
|
client.resolve(trades, messageHash);
|
|
267
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleTrades::', symbol, trades);
|
|
235
268
|
return message;
|
|
236
269
|
}
|
|
237
270
|
async watchOrderBook(symbol, limit = undefined, params = {}) {
|
|
@@ -270,6 +303,39 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
270
303
|
const orderbook = await this.subscribe(url, messageHash, topic, subscription, params);
|
|
271
304
|
return orderbook.limit();
|
|
272
305
|
}
|
|
306
|
+
async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
|
|
307
|
+
/**
|
|
308
|
+
* @method
|
|
309
|
+
* @name kucoinfutures#watchOrderBookForSymbols
|
|
310
|
+
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
311
|
+
* @param {string[]} symbols unified array of symbols
|
|
312
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
313
|
+
* @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
|
|
314
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
315
|
+
*/
|
|
316
|
+
const symbolsLength = symbols.length;
|
|
317
|
+
if (symbolsLength === 0) {
|
|
318
|
+
throw new errors.ArgumentsRequired(this.id + ' watchOrderBookForSymbols() requires a non-empty array of symbols');
|
|
319
|
+
}
|
|
320
|
+
if (limit !== undefined) {
|
|
321
|
+
if ((limit !== 20) && (limit !== 100)) {
|
|
322
|
+
throw new errors.ExchangeError(this.id + " watchOrderBook 'limit' argument must be undefined, 20 or 100");
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
await this.loadMarkets();
|
|
326
|
+
symbols = this.marketSymbols(symbols);
|
|
327
|
+
const marketIds = this.marketIds(symbols);
|
|
328
|
+
const url = await this.negotiate(false);
|
|
329
|
+
const topic = '/contractMarket/level2:' + marketIds.join(',');
|
|
330
|
+
const messageHash = 'multipleOrderbook::' + symbols.join(',');
|
|
331
|
+
const subscription = {
|
|
332
|
+
'method': this.handleOrderBookSubscription,
|
|
333
|
+
'symbols': symbols,
|
|
334
|
+
'limit': limit,
|
|
335
|
+
};
|
|
336
|
+
const orderbook = await this.subscribe(url, messageHash, topic, subscription, params);
|
|
337
|
+
return orderbook.limit();
|
|
338
|
+
}
|
|
273
339
|
handleDelta(orderbook, delta) {
|
|
274
340
|
orderbook['nonce'] = this.safeInteger(delta, 'sequence');
|
|
275
341
|
const timestamp = this.safeInteger(delta, 'timestamp');
|
|
@@ -318,13 +384,23 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
318
384
|
const marketId = this.safeString(topicParts, 1);
|
|
319
385
|
const symbol = this.safeSymbol(marketId, undefined, '-');
|
|
320
386
|
const messageHash = 'orderbook:' + symbol;
|
|
321
|
-
const storedOrderBook = this.orderbooks
|
|
387
|
+
const storedOrderBook = this.safeValue(this.orderbooks, symbol);
|
|
322
388
|
const nonce = this.safeInteger(storedOrderBook, 'nonce');
|
|
323
389
|
const deltaEnd = this.safeInteger(data, 'sequence');
|
|
324
390
|
if (nonce === undefined) {
|
|
325
391
|
const cacheLength = storedOrderBook.cache.length;
|
|
326
|
-
const
|
|
327
|
-
const
|
|
392
|
+
const topicParts = topic.split(':');
|
|
393
|
+
const topicSymbol = this.safeString(topicParts, 1);
|
|
394
|
+
const topicChannel = this.safeString(topicParts, 0);
|
|
395
|
+
const subscriptions = Object.keys(client.subscriptions);
|
|
396
|
+
let subscription = undefined;
|
|
397
|
+
for (let i = 0; i < subscriptions.length; i++) {
|
|
398
|
+
const key = subscriptions[i];
|
|
399
|
+
if ((key.indexOf(topicSymbol) >= 0) && (key.indexOf(topicChannel) >= 0)) {
|
|
400
|
+
subscription = client.subscriptions[key];
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
328
404
|
const limit = this.safeInteger(subscription, 'limit');
|
|
329
405
|
const snapshotDelay = this.handleOption('watchOrderBook', 'snapshotDelay', 5);
|
|
330
406
|
if (cacheLength === snapshotDelay) {
|
|
@@ -338,6 +414,7 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
338
414
|
}
|
|
339
415
|
this.handleDelta(storedOrderBook, data);
|
|
340
416
|
client.resolve(storedOrderBook, messageHash);
|
|
417
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleOrderbook::', symbol, storedOrderBook);
|
|
341
418
|
}
|
|
342
419
|
getCacheIndex(orderbook, cache) {
|
|
343
420
|
const firstDelta = this.safeValue(cache, 0);
|
|
@@ -356,9 +433,18 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
356
433
|
return cache.length;
|
|
357
434
|
}
|
|
358
435
|
handleOrderBookSubscription(client, message, subscription) {
|
|
359
|
-
const symbol = this.safeString(subscription, 'symbol');
|
|
360
436
|
const limit = this.safeInteger(subscription, 'limit');
|
|
361
|
-
|
|
437
|
+
const symbols = this.safeValue(subscription, 'symbols');
|
|
438
|
+
if (symbols === undefined) {
|
|
439
|
+
const symbol = this.safeString(subscription, 'symbol');
|
|
440
|
+
this.orderbooks[symbol] = this.orderBook({}, limit);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
444
|
+
const symbol = symbols[i];
|
|
445
|
+
this.orderbooks[symbol] = this.orderBook({}, limit);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
362
448
|
// moved snapshot initialization to handleOrderBook to fix
|
|
363
449
|
// https://github.com/ccxt/ccxt/issues/6820
|
|
364
450
|
// the general idea is to fetch the snapshot after the first delta
|
package/dist/cjs/src/pro/okx.js
CHANGED
|
@@ -16,6 +16,8 @@ class okx extends okx$1 {
|
|
|
16
16
|
'watchTickers': true,
|
|
17
17
|
'watchOrderBook': true,
|
|
18
18
|
'watchTrades': true,
|
|
19
|
+
'watchTradesForSymbols': true,
|
|
20
|
+
'watchOrderBookForSymbols': true,
|
|
19
21
|
'watchBalance': true,
|
|
20
22
|
'watchOHLCV': true,
|
|
21
23
|
'watchOrders': true,
|
|
@@ -169,6 +171,47 @@ class okx extends okx$1 {
|
|
|
169
171
|
}
|
|
170
172
|
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
171
173
|
}
|
|
174
|
+
async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
|
|
175
|
+
/**
|
|
176
|
+
* @method
|
|
177
|
+
* @name okx#watchTradesForSymbols
|
|
178
|
+
* @description get the list of most recent trades for a particular symbol
|
|
179
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
180
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
181
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
182
|
+
* @param {object} [params] extra parameters specific to the okx api endpoint
|
|
183
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
|
|
184
|
+
*/
|
|
185
|
+
const symbolsLength = symbols.length;
|
|
186
|
+
if (symbolsLength === 0) {
|
|
187
|
+
throw new errors.ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
|
|
188
|
+
}
|
|
189
|
+
await this.loadMarkets();
|
|
190
|
+
symbols = this.marketSymbols(symbols);
|
|
191
|
+
const channel = 'trades';
|
|
192
|
+
const topics = [];
|
|
193
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
194
|
+
const marketId = this.marketId(symbols[i]);
|
|
195
|
+
const topic = {
|
|
196
|
+
'channel': channel,
|
|
197
|
+
'instId': marketId,
|
|
198
|
+
};
|
|
199
|
+
topics.push(topic);
|
|
200
|
+
}
|
|
201
|
+
const request = {
|
|
202
|
+
'op': 'subscribe',
|
|
203
|
+
'args': topics,
|
|
204
|
+
};
|
|
205
|
+
const messageHash = 'multipleTrades::' + symbols.join(',');
|
|
206
|
+
const url = this.getUrl(channel, 'public');
|
|
207
|
+
const trades = await this.watch(url, messageHash, request, messageHash);
|
|
208
|
+
if (this.newUpdates) {
|
|
209
|
+
const first = this.safeValue(trades, 0);
|
|
210
|
+
const tradeSymbol = this.safeString(first, 'symbol');
|
|
211
|
+
limit = trades.getLimit(tradeSymbol, limit);
|
|
212
|
+
}
|
|
213
|
+
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
214
|
+
}
|
|
172
215
|
handleTrades(client, message) {
|
|
173
216
|
//
|
|
174
217
|
// {
|
|
@@ -201,6 +244,7 @@ class okx extends okx$1 {
|
|
|
201
244
|
}
|
|
202
245
|
stored.append(trade);
|
|
203
246
|
client.resolve(stored, messageHash);
|
|
247
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleTrades::', symbol, stored);
|
|
204
248
|
}
|
|
205
249
|
return message;
|
|
206
250
|
}
|
|
@@ -397,6 +441,41 @@ class okx extends okx$1 {
|
|
|
397
441
|
const orderbook = await this.subscribe('public', depth, depth, symbol, params);
|
|
398
442
|
return orderbook.limit();
|
|
399
443
|
}
|
|
444
|
+
async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
|
|
445
|
+
/**
|
|
446
|
+
* @method
|
|
447
|
+
* @name okx#watchOrderBookForSymbols
|
|
448
|
+
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
449
|
+
* @param {string[]} symbols unified array of symbols
|
|
450
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
451
|
+
* @param {object} [params] extra parameters specific to the okx api endpoint
|
|
452
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
453
|
+
*/
|
|
454
|
+
await this.loadMarkets();
|
|
455
|
+
symbols = this.marketSymbols(symbols);
|
|
456
|
+
const options = this.safeValue(this.options, 'watchOrderBook', {});
|
|
457
|
+
const depth = this.safeString(options, 'depth', 'books');
|
|
458
|
+
if ((depth === 'books-l2-tbt') || (depth === 'books50-l2-tbt')) {
|
|
459
|
+
await this.authenticate({ 'access': 'public' });
|
|
460
|
+
}
|
|
461
|
+
const topics = [];
|
|
462
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
463
|
+
const marketId = this.marketId(symbols[i]);
|
|
464
|
+
const topic = {
|
|
465
|
+
'channel': depth,
|
|
466
|
+
'instId': marketId,
|
|
467
|
+
};
|
|
468
|
+
topics.push(topic);
|
|
469
|
+
}
|
|
470
|
+
const request = {
|
|
471
|
+
'op': 'subscribe',
|
|
472
|
+
'args': topics,
|
|
473
|
+
};
|
|
474
|
+
const url = this.getUrl(depth, 'public');
|
|
475
|
+
const messageHash = 'multipleOrderbooks::' + symbols.join(',');
|
|
476
|
+
const orderbook = await this.watch(url, messageHash, request, messageHash);
|
|
477
|
+
return orderbook.limit();
|
|
478
|
+
}
|
|
400
479
|
handleDelta(bookside, delta) {
|
|
401
480
|
//
|
|
402
481
|
// [
|
|
@@ -576,6 +655,7 @@ class okx extends okx$1 {
|
|
|
576
655
|
orderbook['symbol'] = symbol;
|
|
577
656
|
this.handleOrderBookMessage(client, update, orderbook, messageHash);
|
|
578
657
|
client.resolve(orderbook, messageHash);
|
|
658
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleOrderbooks::', symbol, orderbook);
|
|
579
659
|
}
|
|
580
660
|
}
|
|
581
661
|
else if (action === 'update') {
|
|
@@ -585,6 +665,7 @@ class okx extends okx$1 {
|
|
|
585
665
|
const update = data[i];
|
|
586
666
|
this.handleOrderBookMessage(client, update, orderbook, messageHash);
|
|
587
667
|
client.resolve(orderbook, messageHash);
|
|
668
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleOrderbooks::', symbol, orderbook);
|
|
588
669
|
}
|
|
589
670
|
}
|
|
590
671
|
}
|
|
@@ -600,6 +681,7 @@ class okx extends okx$1 {
|
|
|
600
681
|
const snapshot = this.parseOrderBook(update, symbol, timestamp, 'bids', 'asks', 0, 1);
|
|
601
682
|
orderbook.reset(snapshot);
|
|
602
683
|
client.resolve(orderbook, messageHash);
|
|
684
|
+
this.resolvePromiseIfMessagehashMatches(client, 'multipleOrderbooks::', symbol, orderbook);
|
|
603
685
|
}
|
|
604
686
|
}
|
|
605
687
|
return message;
|
package/js/ccxt.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
|
|
|
4
4
|
import * as errors from './src/base/errors.js';
|
|
5
5
|
import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax } from './src/base/types.js';
|
|
6
6
|
import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending } from './src/base/errors.js';
|
|
7
|
-
declare const version = "4.0.
|
|
7
|
+
declare const version = "4.0.89";
|
|
8
8
|
import ace from './src/ace.js';
|
|
9
9
|
import alpaca from './src/alpaca.js';
|
|
10
10
|
import ascendex from './src/ascendex.js';
|
package/js/ccxt.js
CHANGED
|
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
|
|
|
38
38
|
import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending } from './src/base/errors.js';
|
|
39
39
|
//-----------------------------------------------------------------------------
|
|
40
40
|
// this is updated by vss.js when building
|
|
41
|
-
const version = '4.0.
|
|
41
|
+
const version = '4.0.90';
|
|
42
42
|
Exchange.ccxtVersion = version;
|
|
43
43
|
//-----------------------------------------------------------------------------
|
|
44
44
|
import ace from './src/ace.js';
|
|
@@ -370,6 +370,17 @@ export default class Exchange {
|
|
|
370
370
|
signIn: any;
|
|
371
371
|
transfer: any;
|
|
372
372
|
withdraw: any;
|
|
373
|
+
watchOrderBook: any;
|
|
374
|
+
watchOrders: any;
|
|
375
|
+
watchMyTrades: any;
|
|
376
|
+
watchTickers: any;
|
|
377
|
+
watchTicker: any;
|
|
378
|
+
watchTrades: any;
|
|
379
|
+
watchTradesForSymbols: any;
|
|
380
|
+
watchOrderBookForSymbols: any;
|
|
381
|
+
watchOHLCVForSymbols: any;
|
|
382
|
+
watchBalance: any;
|
|
383
|
+
watchOHLCV: any;
|
|
373
384
|
};
|
|
374
385
|
urls: {
|
|
375
386
|
logo: any;
|
|
@@ -523,6 +534,9 @@ export default class Exchange {
|
|
|
523
534
|
fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
524
535
|
fetchTradesWs(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
525
536
|
watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
537
|
+
watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
538
|
+
watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<Dictionary<Dictionary<OHLCV[]>>>;
|
|
539
|
+
watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
|
|
526
540
|
fetchDepositAddresses(codes?: string[], params?: {}): Promise<any>;
|
|
527
541
|
fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
|
|
528
542
|
fetchRestOrderBookSafe(symbol: any, limit?: any, params?: {}): Promise<OrderBook>;
|
|
@@ -786,5 +800,8 @@ export default class Exchange {
|
|
|
786
800
|
parseWsOHLCVs(ohlcvs: object[], market?: any, timeframe?: string, since?: Int, limit?: Int): any[];
|
|
787
801
|
fetchTransactions(code?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
|
|
788
802
|
filterByArrayPositions(objects: any, key: IndexType, values?: any, indexed?: boolean): Position[];
|
|
803
|
+
resolvePromiseIfMessagehashMatches(client: any, prefix: string, symbol: string, data: any): void;
|
|
804
|
+
resolveMultipleOHLCV(client: any, prefix: string, symbol: string, timeframe: string, data: any): void;
|
|
805
|
+
createOHLCVObject(symbol: string, timeframe: string, data: any): Dictionary<Dictionary<OHLCV[]>>;
|
|
789
806
|
}
|
|
790
807
|
export { Exchange, };
|
package/js/src/base/Exchange.js
CHANGED
|
@@ -419,6 +419,17 @@ export default class Exchange {
|
|
|
419
419
|
'signIn': undefined,
|
|
420
420
|
'transfer': undefined,
|
|
421
421
|
'withdraw': undefined,
|
|
422
|
+
'watchOrderBook': undefined,
|
|
423
|
+
'watchOrders': undefined,
|
|
424
|
+
'watchMyTrades': undefined,
|
|
425
|
+
'watchTickers': undefined,
|
|
426
|
+
'watchTicker': undefined,
|
|
427
|
+
'watchTrades': undefined,
|
|
428
|
+
'watchTradesForSymbols': undefined,
|
|
429
|
+
'watchOrderBookForSymbols': undefined,
|
|
430
|
+
'watchOHLCVForSymbols': undefined,
|
|
431
|
+
'watchBalance': undefined,
|
|
432
|
+
'watchOHLCV': undefined,
|
|
422
433
|
},
|
|
423
434
|
'urls': {
|
|
424
435
|
'logo': undefined,
|
|
@@ -1289,6 +1300,15 @@ export default class Exchange {
|
|
|
1289
1300
|
async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
1290
1301
|
throw new NotSupported(this.id + ' watchTrades() is not supported yet');
|
|
1291
1302
|
}
|
|
1303
|
+
async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
|
|
1304
|
+
throw new NotSupported(this.id + ' watchTradesForSymbols() is not supported yet');
|
|
1305
|
+
}
|
|
1306
|
+
async watchOHLCVForSymbols(symbolsAndTimeframes, since = undefined, limit = undefined, params = {}) {
|
|
1307
|
+
throw new NotSupported(this.id + ' watchOHLCVForSymbols() is not supported yet');
|
|
1308
|
+
}
|
|
1309
|
+
async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
|
|
1310
|
+
throw new NotSupported(this.id + ' watchOrderBookForSymbols() is not supported yet');
|
|
1311
|
+
}
|
|
1292
1312
|
async fetchDepositAddresses(codes = undefined, params = {}) {
|
|
1293
1313
|
throw new NotSupported(this.id + ' fetchDepositAddresses() is not supported yet');
|
|
1294
1314
|
}
|
|
@@ -2544,6 +2564,17 @@ export default class Exchange {
|
|
|
2544
2564
|
const percentageString = Precise.stringMul(Precise.stringDiv(unrealizedPnlString, initialMarginString, 4), '100');
|
|
2545
2565
|
position['percentage'] = this.parseNumber(percentageString);
|
|
2546
2566
|
}
|
|
2567
|
+
// if contractSize is undefined get from market
|
|
2568
|
+
let contractSize = this.safeNumber(position, 'contractSize');
|
|
2569
|
+
const symbol = this.safeString(position, 'symbol');
|
|
2570
|
+
let market = undefined;
|
|
2571
|
+
if (symbol !== undefined) {
|
|
2572
|
+
market = this.market(symbol);
|
|
2573
|
+
}
|
|
2574
|
+
if (contractSize === undefined && market !== undefined) {
|
|
2575
|
+
contractSize = this.safeNumber(market, 'contractSize');
|
|
2576
|
+
position['contractSize'] = contractSize;
|
|
2577
|
+
}
|
|
2547
2578
|
return position;
|
|
2548
2579
|
}
|
|
2549
2580
|
parsePositions(positions, symbols = undefined, params = {}) {
|
|
@@ -4007,5 +4038,36 @@ export default class Exchange {
|
|
|
4007
4038
|
*/
|
|
4008
4039
|
return this.filterByArray(objects, key, values, indexed);
|
|
4009
4040
|
}
|
|
4041
|
+
resolvePromiseIfMessagehashMatches(client, prefix, symbol, data) {
|
|
4042
|
+
const messageHashes = this.findMessageHashes(client, prefix);
|
|
4043
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
4044
|
+
const messageHash = messageHashes[i];
|
|
4045
|
+
const parts = messageHash.split('::');
|
|
4046
|
+
const symbolsString = parts[1];
|
|
4047
|
+
const symbols = symbolsString.split(',');
|
|
4048
|
+
if (this.inArray(symbol, symbols)) {
|
|
4049
|
+
client.resolve(data, messageHash);
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
resolveMultipleOHLCV(client, prefix, symbol, timeframe, data) {
|
|
4054
|
+
const messageHashes = this.findMessageHashes(client, 'multipleOHLCV::');
|
|
4055
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
4056
|
+
const messageHash = messageHashes[i];
|
|
4057
|
+
const parts = messageHash.split('::');
|
|
4058
|
+
const symbolsAndTimeframes = parts[1];
|
|
4059
|
+
const splitted = symbolsAndTimeframes.split(',');
|
|
4060
|
+
const id = symbol + '#' + timeframe;
|
|
4061
|
+
if (this.inArray(id, splitted)) {
|
|
4062
|
+
client.resolve([symbol, timeframe, data], messageHash);
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
createOHLCVObject(symbol, timeframe, data) {
|
|
4067
|
+
const res = {};
|
|
4068
|
+
res[symbol] = {};
|
|
4069
|
+
res[symbol][timeframe] = data;
|
|
4070
|
+
return res;
|
|
4071
|
+
}
|
|
4010
4072
|
}
|
|
4011
4073
|
export { Exchange, };
|
package/js/src/bitmex.js
CHANGED
|
@@ -2354,6 +2354,7 @@ export default class bitmex extends Exchange {
|
|
|
2354
2354
|
if (until !== undefined) {
|
|
2355
2355
|
request['endTime'] = this.iso8601(until);
|
|
2356
2356
|
}
|
|
2357
|
+
request['reverse'] = true;
|
|
2357
2358
|
const response = await this.publicGetFunding(this.extend(request, params));
|
|
2358
2359
|
//
|
|
2359
2360
|
// [
|
package/js/src/pro/binance.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export default class binance extends binanceRest {
|
|
|
6
6
|
requestId(url: any): any;
|
|
7
7
|
stream(type: any, subscriptionHash: any): string;
|
|
8
8
|
watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<any>;
|
|
9
|
+
watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<any>;
|
|
9
10
|
fetchOrderBookSnapshot(client: any, message: any, subscription: any): Promise<void>;
|
|
10
11
|
handleDelta(bookside: any, delta: any): void;
|
|
11
12
|
handleDeltas(bookside: any, deltas: any): void;
|
|
@@ -13,6 +14,7 @@ export default class binance extends binanceRest {
|
|
|
13
14
|
handleOrderBook(client: Client, message: any): void;
|
|
14
15
|
handleOrderBookSubscription(client: Client, message: any, subscription: any): void;
|
|
15
16
|
handleSubscriptionStatus(client: Client, message: any): any;
|
|
17
|
+
watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<any>;
|
|
16
18
|
watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
|
|
17
19
|
parseTrade(trade: any, market?: any): import("../base/types.js").Trade | {
|
|
18
20
|
id: any;
|
|
@@ -34,6 +36,7 @@ export default class binance extends binanceRest {
|
|
|
34
36
|
};
|
|
35
37
|
handleTrade(client: Client, message: any): void;
|
|
36
38
|
watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
|
|
39
|
+
watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<import("../base/types.js").Dictionary<import("../base/types.js").Dictionary<import("../base/types.js").OHLCV[]>>>;
|
|
37
40
|
handleOHLCV(client: Client, message: any): void;
|
|
38
41
|
watchTicker(symbol: string, params?: {}): Promise<any>;
|
|
39
42
|
watchTickers(symbols?: string[], params?: {}): Promise<any>;
|