ccxt 4.1.1 → 4.1.3

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/js/src/okx.js CHANGED
@@ -2086,15 +2086,32 @@ export default class okx extends Exchange {
2086
2086
  defaultType = this.safeString(options, 'type', defaultType); // Candles or HistoryCandles
2087
2087
  const type = this.safeString(params, 'type', defaultType);
2088
2088
  params = this.omit(params, 'type');
2089
- let method = 'publicGetMarket' + type;
2090
2089
  const isHistoryCandles = (type === 'HistoryCandles');
2090
+ let response = undefined;
2091
2091
  if (price === 'mark') {
2092
- method = (isHistoryCandles) ? 'publicGetMarketHistoryMarkPriceCandles' : 'publicGetMarketMarkPriceCandles';
2092
+ if (isHistoryCandles) {
2093
+ response = await this.publicGetMarketHistoryMarkPriceCandles(this.extend(request, params));
2094
+ }
2095
+ else {
2096
+ response = await this.publicGetMarketMarkPriceCandles(this.extend(request, params));
2097
+ }
2093
2098
  }
2094
2099
  else if (price === 'index') {
2095
- method = (isHistoryCandles) ? 'publicGetMarketHistoryIndexCandles' : 'publicGetMarketIndexCandles';
2100
+ if (isHistoryCandles) {
2101
+ response = await this.publicGetMarketHistoryIndexCandles(this.extend(request, params));
2102
+ }
2103
+ else {
2104
+ response = await this.publicGetMarketIndexCandles(this.extend(request, params));
2105
+ }
2106
+ }
2107
+ else {
2108
+ if (isHistoryCandles) {
2109
+ response = await this.publicGetMarketHistoryCandles(this.extend(request, params));
2110
+ }
2111
+ else {
2112
+ response = await this.publicGetMarketCandles(this.extend(request, params));
2113
+ }
2096
2114
  }
2097
- const response = await this[method](this.extend(request, params));
2098
2115
  //
2099
2116
  // {
2100
2117
  // "code": "0",
@@ -2306,17 +2323,16 @@ export default class okx extends Exchange {
2306
2323
  */
2307
2324
  await this.loadMarkets();
2308
2325
  const [marketType, query] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
2309
- let method = undefined;
2326
+ const request = {
2327
+ // 'ccy': 'BTC,ETH', // comma-separated list of currency ids
2328
+ };
2329
+ let response = undefined;
2310
2330
  if (marketType === 'funding') {
2311
- method = 'privateGetAssetBalances';
2331
+ response = await this.privateGetAssetBalances(this.extend(request, query));
2312
2332
  }
2313
2333
  else {
2314
- method = 'privateGetAccountBalance';
2334
+ response = await this.privateGetAccountBalance(this.extend(request, query));
2315
2335
  }
2316
- const request = {
2317
- // 'ccy': 'BTC,ETH', // comma-separated list of currency ids
2318
- };
2319
- const response = await this[method](this.extend(request, query));
2320
2336
  //
2321
2337
  // {
2322
2338
  // "code": "0",
@@ -143,14 +143,20 @@ export default class binance extends binanceRest {
143
143
  // valid <levels> are 5, 10, or 20
144
144
  //
145
145
  // default 100, max 1000, valid limits 5, 10, 20, 50, 100, 500, 1000
146
+ await this.loadMarkets();
147
+ const market = this.market(symbol);
146
148
  if (limit !== undefined) {
147
- if ((limit !== 5) && (limit !== 10) && (limit !== 20) && (limit !== 50) && (limit !== 100) && (limit !== 500) && (limit !== 1000)) {
148
- throw new ExchangeError(this.id + ' watchOrderBook limit argument must be undefined, 5, 10, 20, 50, 100, 500 or 1000');
149
+ if (market['contract']) {
150
+ if ((limit !== 5) && (limit !== 10) && (limit !== 20) && (limit !== 50) && (limit !== 100) && (limit !== 500) && (limit !== 1000)) {
151
+ throw new ExchangeError(this.id + ' watchOrderBook limit argument must be undefined, 5, 10, 20, 50, 100, 500 or 1000');
152
+ }
153
+ }
154
+ else {
155
+ if (limit > 5000) {
156
+ throw new ExchangeError(this.id + ' watchOrderBook limit argument must be less than or equal to 5000');
157
+ }
149
158
  }
150
159
  }
151
- //
152
- await this.loadMarkets();
153
- const market = this.market(symbol);
154
160
  let type = market['type'];
155
161
  if (market['contract']) {
156
162
  type = market['linear'] ? 'future' : 'delivery';
@@ -16,6 +16,8 @@ export default class coinbasepro extends coinbaseproRest {
16
16
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
17
17
  watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<any>;
18
18
  watchMyTrades(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
19
+ watchMyTradesForSymbols(symbols?: string[], since?: Int, limit?: Int, params?: {}): Promise<any>;
20
+ watchOrdersForSymbols(symbols?: string[], since?: Int, limit?: Int, params?: {}): Promise<any>;
19
21
  watchOrders(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
20
22
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<any>;
21
23
  watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<any>;
@@ -24,30 +26,7 @@ export default class coinbasepro extends coinbaseproRest {
24
26
  parseWsTrade(trade: any, market?: any): import("../base/types.js").Trade;
25
27
  parseWsOrderStatus(status: any): string;
26
28
  handleOrder(client: Client, message: any): void;
27
- parseWsOrder(order: any, market?: any): {
28
- info: any;
29
- symbol: any;
30
- id: string;
31
- clientOrderId: string;
32
- timestamp: number;
33
- datetime: string;
34
- lastTradeTimestamp: any;
35
- type: string;
36
- timeInForce: any;
37
- postOnly: any;
38
- side: string;
39
- price: number;
40
- stopPrice: any;
41
- triggerPrice: any;
42
- amount: number;
43
- cost: any;
44
- average: any;
45
- filled: any;
46
- remaining: number;
47
- status: string;
48
- fee: any;
49
- trades: any;
50
- };
29
+ parseWsOrder(order: any, market?: any): import("../base/types.js").Order;
51
30
  handleTicker(client: Client, message: any): any;
52
31
  parseTicker(ticker: any, market?: any): import("../base/types.js").Ticker;
53
32
  handleDelta(bookside: any, delta: any): void;
@@ -22,9 +22,11 @@ export default class coinbasepro extends coinbaseproRest {
22
22
  'watchTickers': true,
23
23
  'watchTrades': true,
24
24
  'watchTradesForSymbols': true,
25
+ 'watchMyTradesForSymbols': true,
25
26
  'watchBalance': false,
26
27
  'watchStatus': false,
27
28
  'watchOrders': true,
29
+ 'watchOrdersForSymbols': true,
28
30
  'watchMyTrades': true,
29
31
  },
30
32
  'urls': {
@@ -212,6 +214,54 @@ export default class coinbasepro extends coinbaseproRest {
212
214
  }
213
215
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
214
216
  }
217
+ async watchMyTradesForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
218
+ /**
219
+ * @method
220
+ * @name coinbasepro#watchMyTradesForSymbols
221
+ * @description watches information on multiple trades made by the user
222
+ * @param {string[]} symbols unified symbol of the market to fetch trades for
223
+ * @param {int} [since] the earliest time in ms to fetch trades for
224
+ * @param {int} [limit] the maximum number of trade structures to retrieve
225
+ * @param {object} [params] extra parameters specific to the coinbasepro api endpoint
226
+ * @returns {object[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure
227
+ */
228
+ symbols = this.marketSymbols(symbols, undefined, false);
229
+ await this.loadMarkets();
230
+ const name = 'user';
231
+ const messageHash = 'multipleMyTrades::';
232
+ const authentication = this.authenticate();
233
+ const trades = await this.subscribeMultiple(name, symbols, messageHash, this.extend(params, authentication));
234
+ if (this.newUpdates) {
235
+ const first = this.safeValue(trades, 0);
236
+ const tradeSymbol = this.safeString(first, 'symbol');
237
+ limit = trades.getLimit(tradeSymbol, limit);
238
+ }
239
+ return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
240
+ }
241
+ async watchOrdersForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
242
+ /**
243
+ * @method
244
+ * @name coinbasepro#watchOrdersForSymbols
245
+ * @description watches information on multiple orders made by the user
246
+ * @param {string[]} symbols unified symbol of the market to fetch orders for
247
+ * @param {int} [since] the earliest time in ms to fetch orders for
248
+ * @param {int} [limit] the maximum number of trade structures to retrieve
249
+ * @param {object} [params] extra parameters specific to the coinbasepro api endpoint
250
+ * @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
251
+ */
252
+ symbols = this.marketSymbols(symbols, undefined, false);
253
+ await this.loadMarkets();
254
+ const name = 'user';
255
+ const messageHash = 'multipleOrders::';
256
+ const authentication = this.authenticate();
257
+ const orders = await this.subscribeMultiple(name, symbols, messageHash, this.extend(params, authentication));
258
+ if (this.newUpdates) {
259
+ const first = this.safeValue(orders, 0);
260
+ const tradeSymbol = this.safeString(first, 'symbol');
261
+ limit = orders.getLimit(tradeSymbol, limit);
262
+ }
263
+ return this.filterBySinceLimit(orders, since, limit, 'timestamp', true);
264
+ }
215
265
  async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
216
266
  /**
217
267
  * @method
@@ -351,6 +401,7 @@ export default class coinbasepro extends coinbaseproRest {
351
401
  const marketId = this.safeString(message, 'product_id');
352
402
  if (marketId !== undefined) {
353
403
  const trade = this.parseWsTrade(message);
404
+ const symbol = trade['symbol'];
354
405
  const type = 'myTrades';
355
406
  const messageHash = type + ':' + marketId;
356
407
  let tradesArray = this.myTrades;
@@ -361,6 +412,7 @@ export default class coinbasepro extends coinbaseproRest {
361
412
  }
362
413
  tradesArray.append(trade);
363
414
  client.resolve(tradesArray, messageHash);
415
+ this.resolvePromiseIfMessagehashMatches(client, 'multipleMyTrades::', symbol, tradesArray);
364
416
  }
365
417
  return message;
366
418
  }
@@ -417,14 +469,25 @@ export default class coinbasepro extends coinbaseproRest {
417
469
  // }
418
470
  const parsed = super.parseTrade(trade);
419
471
  let feeRate = undefined;
472
+ let isMaker = false;
420
473
  if ('maker_fee_rate' in trade) {
474
+ isMaker = true;
421
475
  parsed['takerOrMaker'] = 'maker';
422
476
  feeRate = this.safeNumber(trade, 'maker_fee_rate');
423
477
  }
424
478
  else {
425
479
  parsed['takerOrMaker'] = 'taker';
426
480
  feeRate = this.safeNumber(trade, 'taker_fee_rate');
427
- }
481
+ // side always represents the maker side of the trade
482
+ // so if we're taker, we invert it
483
+ const currentSide = parsed['side'];
484
+ parsed['side'] = this.safeString({
485
+ 'buy': 'sell',
486
+ 'sell': 'buy',
487
+ }, currentSide, currentSide);
488
+ }
489
+ const idKey = isMaker ? 'maker_order_id' : 'taker_order_id';
490
+ parsed['order'] = this.safeString(trade, idKey);
428
491
  market = this.market(parsed['symbol']);
429
492
  const feeCurrency = market['quote'];
430
493
  let feeCost = undefined;
@@ -550,6 +613,7 @@ export default class coinbasepro extends coinbaseproRest {
550
613
  const parsed = this.parseWsOrder(message);
551
614
  orders.append(parsed);
552
615
  client.resolve(orders, messageHash);
616
+ this.resolvePromiseIfMessagehashMatches(client, 'multipleOrders::', symbol, orders);
553
617
  }
554
618
  else {
555
619
  const sequence = this.safeInteger(message, 'sequence');
@@ -593,6 +657,7 @@ export default class coinbasepro extends coinbaseproRest {
593
657
  // update the newUpdates count
594
658
  orders.append(previousOrder);
595
659
  client.resolve(orders, messageHash);
660
+ this.resolvePromiseIfMessagehashMatches(client, 'multipleOrders::', symbol, orders);
596
661
  }
597
662
  else if ((type === 'received') || (type === 'done')) {
598
663
  const info = this.extend(previousOrder['info'], message);
@@ -608,6 +673,7 @@ export default class coinbasepro extends coinbaseproRest {
608
673
  // update the newUpdates count
609
674
  orders.append(previousOrder);
610
675
  client.resolve(orders, messageHash);
676
+ this.resolvePromiseIfMessagehashMatches(client, 'multipleOrders::', symbol, orders);
611
677
  }
612
678
  }
613
679
  }
@@ -638,11 +704,7 @@ export default class coinbasepro extends coinbaseproRest {
638
704
  remaining = amount - filled;
639
705
  }
640
706
  }
641
- let cost = undefined;
642
- if ((price !== undefined) && (amount !== undefined)) {
643
- cost = price * amount;
644
- }
645
- return {
707
+ return this.safeOrder({
646
708
  'info': order,
647
709
  'symbol': symbol,
648
710
  'id': id,
@@ -658,14 +720,14 @@ export default class coinbasepro extends coinbaseproRest {
658
720
  'stopPrice': undefined,
659
721
  'triggerPrice': undefined,
660
722
  'amount': amount,
661
- 'cost': cost,
723
+ 'cost': undefined,
662
724
  'average': undefined,
663
725
  'filled': filled,
664
726
  'remaining': remaining,
665
727
  'status': status,
666
728
  'fee': undefined,
667
729
  'trades': undefined,
668
- };
730
+ });
669
731
  }
670
732
  handleTicker(client, message) {
671
733
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 130+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",
package/skip-tests.json CHANGED
@@ -48,6 +48,7 @@
48
48
  },
49
49
  "binance": {
50
50
  "httpsProxy": "http://51.83.140.52:11230",
51
+ "skipPhpAsync": true,
51
52
  "skipWs": true,
52
53
  "skipMethods": {
53
54
  "loadMarkets": {
@@ -79,6 +80,7 @@
79
80
  },
80
81
  "binancecoinm": {
81
82
  "httpsProxy": "http://51.83.140.52:11230",
83
+ "skipPhpAsync": true,
82
84
  "skipWs": true,
83
85
  "skipMethods": {
84
86
  "loadMarkets": {
@@ -97,6 +99,7 @@
97
99
  },
98
100
  "binanceusdm": {
99
101
  "httpsProxy": "http://51.83.140.52:11230",
102
+ "skipPhpAsync": true,
100
103
  "skipWs": true,
101
104
  "skipMethods": {
102
105
  "fetchTickers": {
@@ -120,6 +123,7 @@
120
123
  },
121
124
  "tokocrypto": {
122
125
  "httpsProxy": "http://51.83.140.52:11230",
126
+ "skipPhpAsync": true,
123
127
  "skipWs": true
124
128
  },
125
129
  "bitbank": {
@@ -912,7 +916,8 @@
912
916
  }
913
917
  },
914
918
  "kuna": {
915
- "httpsProxy": "http://51.83.140.52:11230"
919
+ "httpsProxy": "http://51.83.140.52:11230",
920
+ "skipPhpAsync": true
916
921
  },
917
922
  "kucoin": {
918
923
  "skipWs": true,