ccxt 4.3.68 → 4.3.70

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.
Files changed (76) hide show
  1. package/README.md +6 -6
  2. package/dist/ccxt.browser.min.js +5 -5
  3. package/dist/cjs/ccxt.js +3 -1
  4. package/dist/cjs/src/ascendex.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +365 -353
  6. package/dist/cjs/src/binance.js +1 -1
  7. package/dist/cjs/src/bingx.js +134 -75
  8. package/dist/cjs/src/blofin.js +63 -6
  9. package/dist/cjs/src/btcbox.js +2 -1
  10. package/dist/cjs/src/bybit.js +1 -1
  11. package/dist/cjs/src/coinbaseinternational.js +247 -3
  12. package/dist/cjs/src/cryptocom.js +9 -1
  13. package/dist/cjs/src/hitbtc.js +1 -1
  14. package/dist/cjs/src/hyperliquid.js +0 -3
  15. package/dist/cjs/src/kucoin.js +12 -5
  16. package/dist/cjs/src/oxfun.js +2 -2
  17. package/dist/cjs/src/poloniex.js +34 -33
  18. package/dist/cjs/src/poloniexfutures.js +26 -26
  19. package/dist/cjs/src/pro/blofin.js +665 -0
  20. package/dist/cjs/src/pro/coinbaseinternational.js +154 -9
  21. package/dist/cjs/src/pro/cryptocom.js +3 -1
  22. package/dist/cjs/src/pro/hitbtc.js +26 -8
  23. package/dist/cjs/src/pro/okx.js +7 -0
  24. package/dist/cjs/src/pro/poloniex.js +50 -25
  25. package/dist/cjs/src/pro/poloniexfutures.js +5 -5
  26. package/dist/cjs/src/pro/woo.js +5 -4
  27. package/js/ccxt.d.ts +6 -3
  28. package/js/ccxt.js +3 -1
  29. package/js/src/abstract/coinbaseinternational.d.ts +1 -1
  30. package/js/src/ascendex.js +1 -1
  31. package/js/src/base/Exchange.d.ts +108 -82
  32. package/js/src/base/Exchange.js +365 -353
  33. package/js/src/base/types.d.ts +0 -2
  34. package/js/src/binance.d.ts +2 -2
  35. package/js/src/binance.js +1 -1
  36. package/js/src/bingx.d.ts +2 -2
  37. package/js/src/bingx.js +134 -75
  38. package/js/src/bitget.d.ts +2 -2
  39. package/js/src/bitmart.d.ts +2 -2
  40. package/js/src/bitrue.d.ts +2 -2
  41. package/js/src/blofin.d.ts +1 -1
  42. package/js/src/blofin.js +63 -6
  43. package/js/src/btcbox.js +2 -1
  44. package/js/src/bybit.d.ts +2 -2
  45. package/js/src/bybit.js +1 -1
  46. package/js/src/coinbaseinternational.d.ts +17 -1
  47. package/js/src/coinbaseinternational.js +247 -3
  48. package/js/src/coinex.d.ts +2 -2
  49. package/js/src/coinlist.d.ts +2 -2
  50. package/js/src/cryptocom.js +10 -2
  51. package/js/src/deribit.d.ts +2 -2
  52. package/js/src/digifinex.d.ts +2 -2
  53. package/js/src/hitbtc.js +1 -1
  54. package/js/src/hyperliquid.js +0 -3
  55. package/js/src/kucoin.js +12 -5
  56. package/js/src/latoken.d.ts +2 -2
  57. package/js/src/mexc.d.ts +2 -2
  58. package/js/src/okx.d.ts +2 -2
  59. package/js/src/oxfun.d.ts +1 -1
  60. package/js/src/oxfun.js +2 -2
  61. package/js/src/phemex.d.ts +2 -2
  62. package/js/src/poloniex.js +34 -33
  63. package/js/src/poloniexfutures.js +26 -26
  64. package/js/src/pro/blofin.d.ts +39 -0
  65. package/js/src/pro/blofin.js +668 -0
  66. package/js/src/pro/coinbaseinternational.d.ts +5 -1
  67. package/js/src/pro/coinbaseinternational.js +155 -10
  68. package/js/src/pro/cryptocom.js +4 -2
  69. package/js/src/pro/hitbtc.d.ts +1 -1
  70. package/js/src/pro/hitbtc.js +26 -8
  71. package/js/src/pro/okx.js +7 -0
  72. package/js/src/pro/poloniex.js +50 -25
  73. package/js/src/pro/poloniexfutures.js +5 -5
  74. package/js/src/pro/woo.js +5 -4
  75. package/js/src/woo.d.ts +2 -2
  76. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import coinbaseinternationalRest from '../coinbaseinternational.js';
2
- import { Ticker, Int, Trade, OrderBook, Market, Dict, Strings, FundingRate, FundingRates } from '../base/types.js';
2
+ import { Ticker, Int, Trade, OrderBook, Market, Dict, Strings, FundingRate, FundingRates, Tickers, OHLCV } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class coinbaseinternational extends coinbaseinternationalRest {
5
5
  describe(): any;
@@ -8,10 +8,14 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
8
8
  watchFundingRate(symbol: string, params?: {}): Promise<FundingRate>;
9
9
  watchFundingRates(symbols: string[], params?: {}): Promise<FundingRates>;
10
10
  watchTicker(symbol: string, params?: {}): Promise<Ticker>;
11
+ getActiveSymbols(): any[];
12
+ watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
11
13
  handleInstrument(client: Client, message: any): void;
12
14
  parseWsInstrument(ticker: Dict, market?: any): Ticker;
13
15
  handleTicker(client: Client, message: any): void;
14
16
  parseWsTicker(ticker: object, market?: Market): Ticker;
17
+ watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
18
+ handleOHLCV(client: Client, message: any): void;
15
19
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
16
20
  watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
17
21
  handleTrade(client: any, message: any): any;
@@ -8,7 +8,7 @@
8
8
  import coinbaseinternationalRest from '../coinbaseinternational.js';
9
9
  import { AuthenticationError, ExchangeError, NotSupported } from '../base/errors.js';
10
10
  import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
11
- import { ArrayCache } from '../base/ws/Cache.js';
11
+ import { ArrayCache, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
12
12
  // ---------------------------------------------------------------------------
13
13
  export default class coinbaseinternational extends coinbaseinternationalRest {
14
14
  describe() {
@@ -22,12 +22,12 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
22
22
  'watchTicker': true,
23
23
  'watchBalance': false,
24
24
  'watchMyTrades': false,
25
- 'watchOHLCV': false,
25
+ 'watchOHLCV': true,
26
26
  'watchOHLCVForSymbols': false,
27
27
  'watchOrders': false,
28
28
  'watchOrdersForSymbols': false,
29
29
  'watchPositions': false,
30
- 'watchTickers': false,
30
+ 'watchTickers': true,
31
31
  'createOrderWs': false,
32
32
  'editOrderWs': false,
33
33
  'cancelOrderWs': false,
@@ -53,6 +53,14 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
53
53
  'tradesLimit': 1000,
54
54
  'ordersLimit': 1000,
55
55
  'myTradesLimit': 1000,
56
+ 'timeframes': {
57
+ '1m': 'CANDLES_ONE_MINUTE',
58
+ '5m': 'CANDLES_FIVE_MINUTES',
59
+ '30m': 'CANDLES_THIRTY_MINUTES',
60
+ '1h': 'CANDLES_ONE_HOUR',
61
+ '2h': 'CANDLES_TWO_HOURS',
62
+ '1d': 'CANDLES_ONE_DAY',
63
+ },
56
64
  },
57
65
  'exceptions': {
58
66
  'exact': {
@@ -76,16 +84,20 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
76
84
  this.checkRequiredCredentials();
77
85
  let market = undefined;
78
86
  let messageHash = name;
79
- let productIds = [];
87
+ let productIds = undefined;
80
88
  if (symbols === undefined) {
81
- symbols = this.symbols;
89
+ symbols = this.getActiveSymbols();
82
90
  }
83
91
  const symbolsLength = symbols.length;
92
+ const messageHashes = [];
84
93
  if (symbolsLength > 1) {
85
94
  const parsedSymbols = this.marketSymbols(symbols);
86
95
  const marketIds = this.marketIds(parsedSymbols);
87
96
  productIds = marketIds;
88
- messageHash = messageHash + '::' + parsedSymbols.join(',');
97
+ for (let i = 0; i < parsedSymbols.length; i++) {
98
+ messageHashes.push(name + '::' + parsedSymbols[i]);
99
+ }
100
+ // messageHash = messageHash + '::' + parsedSymbols.join (',');
89
101
  }
90
102
  else if (symbolsLength === 1) {
91
103
  market = this.market(symbols[0]);
@@ -101,13 +113,19 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
101
113
  const signature = this.hmac(this.encode(auth), this.base64ToBinary(this.secret), sha256, 'base64');
102
114
  const subscribe = {
103
115
  'type': 'SUBSCRIBE',
104
- 'product_ids': productIds,
116
+ // 'product_ids': productIds,
105
117
  'channels': [name],
106
118
  'time': timestamp,
107
119
  'key': this.apiKey,
108
120
  'passphrase': this.password,
109
121
  'signature': signature,
110
122
  };
123
+ if (productIds !== undefined) {
124
+ subscribe['product_ids'] = productIds;
125
+ }
126
+ if (symbolsLength > 1) {
127
+ return await this.watchMultiple(url, messageHashes, this.extend(subscribe, params), messageHashes);
128
+ }
111
129
  return await this.watch(url, messageHash, this.extend(subscribe, params), messageHash);
112
130
  }
113
131
  async subscribeMultiple(name, symbols = undefined, params = {}) {
@@ -196,6 +214,7 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
196
214
  * @see https://docs.cloud.coinbase.com/intx/docs/websocket-channels#instruments-channel
197
215
  * @param {string} [symbol] unified symbol of the market to fetch the ticker for
198
216
  * @param {object} [params] extra parameters specific to the exchange API endpoint
217
+ * @param {string} [params.channel] the channel to watch, 'LEVEL1' or 'INSTRUMENTS', default is 'LEVEL1'
199
218
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
200
219
  */
201
220
  await this.loadMarkets();
@@ -203,6 +222,40 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
203
222
  [channel, params] = this.handleOptionAndParams(params, 'watchTicker', 'channel', 'LEVEL1');
204
223
  return await this.subscribe(channel, [symbol], params);
205
224
  }
225
+ getActiveSymbols() {
226
+ const symbols = this.symbols;
227
+ const output = [];
228
+ for (let i = 0; i < symbols.length; i++) {
229
+ const symbol = symbols[i];
230
+ const market = this.markets[symbol];
231
+ if (market['active']) {
232
+ output.push(symbol);
233
+ }
234
+ }
235
+ return output;
236
+ }
237
+ async watchTickers(symbols = undefined, params = {}) {
238
+ /**
239
+ * @method
240
+ * @name coinbaseinternational#watchTickers
241
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
242
+ * @see https://docs.cloud.coinbase.com/intx/docs/websocket-channels#instruments-channel
243
+ * @param {string[]} [symbols] unified symbol of the market to fetch the ticker for
244
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
245
+ * @param {string} [params.channel] the channel to watch, 'LEVEL1' or 'INSTRUMENTS', default is 'INSTLEVEL1UMENTS'
246
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
247
+ */
248
+ await this.loadMarkets();
249
+ let channel = undefined;
250
+ [channel, params] = this.handleOptionAndParams(params, 'watchTickers', 'channel', 'LEVEL1');
251
+ const ticker = await this.subscribe(channel, symbols, params);
252
+ if (this.newUpdates) {
253
+ const result = {};
254
+ result[ticker['symbol']] = ticker;
255
+ return result;
256
+ }
257
+ return this.filterByArray(this.tickers, 'symbol', symbols);
258
+ }
206
259
  handleInstrument(client, message) {
207
260
  //
208
261
  // {
@@ -260,6 +313,33 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
260
313
  // "channel":"INSTRUMENTS",
261
314
  // "type":"SNAPSHOT"
262
315
  // }
316
+ // instruments
317
+ // {
318
+ // sequence: 0,
319
+ // instrument_type: 'PERP',
320
+ // instrument_mode: 'standard',
321
+ // base_asset_name: 'BTC',
322
+ // quote_asset_name: 'USDC',
323
+ // base_increment: '0.0001',
324
+ // quote_increment: '0.1',
325
+ // avg_daily_quantity: '502.8845',
326
+ // avg_daily_volume: '3.1495242961566668E7',
327
+ // total30_day_quantity: '15086.535',
328
+ // total30_day_volume: '9.44857288847E8',
329
+ // total24_hour_quantity: '5.0',
330
+ // total24_hour_volume: '337016.5',
331
+ // base_imf: '0.1',
332
+ // min_quantity: '0.0001',
333
+ // position_size_limit: '800',
334
+ // funding_interval: '3600000000000',
335
+ // trading_state: 'trading',
336
+ // last_updated_time: '2024-07-30T15:00:00Z',
337
+ // default_initial_margin: '0.2',
338
+ // base_asset_multiplier: '1.0',
339
+ // channel: 'INSTRUMENTS',
340
+ // type: 'SNAPSHOT',
341
+ // time: '2024-07-30T15:26:56.766Z',
342
+ // }
263
343
  //
264
344
  const marketId = this.safeString(ticker, 'product_id');
265
345
  const datetime = this.safeString(ticker, 'time');
@@ -282,8 +362,8 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
282
362
  'change': undefined,
283
363
  'percentage': undefined,
284
364
  'average': undefined,
285
- 'baseVolume': this.safeString(ticker, 'total_24_hour_quantity'),
286
- 'quoteVolume': this.safeString(ticker, 'total_24_hour_volume'),
365
+ 'baseVolume': this.safeString2(ticker, 'total_24_hour_quantity', 'total24_hour_quantity'),
366
+ 'quoteVolume': this.safeString2(ticker, 'total_24_hour_volume', 'total24_hour_volume'),
287
367
  });
288
368
  }
289
369
  handleTicker(client, message) {
@@ -355,6 +435,68 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
355
435
  'previousClose': undefined,
356
436
  });
357
437
  }
438
+ async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
439
+ /**
440
+ * @method
441
+ * @name coinbaseinternational#watchOHLCV
442
+ * @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
443
+ * @see https://docs.cdp.coinbase.com/intx/docs/websocket-channels#candles-channel
444
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
445
+ * @param {string} timeframe the length of time each candle represents
446
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
447
+ * @param {int} [limit] the maximum amount of candles to fetch
448
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
449
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
450
+ */
451
+ await this.loadMarkets();
452
+ const market = this.market(symbol);
453
+ symbol = market['symbol'];
454
+ const options = this.safeDict(this.options, 'timeframes', {});
455
+ const interval = this.safeString(options, timeframe, timeframe);
456
+ const ohlcv = await this.subscribe(interval, [symbol], params);
457
+ if (this.newUpdates) {
458
+ limit = ohlcv.getLimit(symbol, limit);
459
+ }
460
+ return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
461
+ }
462
+ handleOHLCV(client, message) {
463
+ //
464
+ // {
465
+ // "sequence": 0,
466
+ // "product_id": "BTC-PERP",
467
+ // "channel": "CANDLES_ONE_MINUTE",
468
+ // "type": "SNAPSHOT",
469
+ // "candles": [
470
+ // {
471
+ // "time": "2023-05-10T14:58:47.000Z",
472
+ // "low": "28787.8",
473
+ // "high": "28788.8",
474
+ // "open": "28788.8",
475
+ // "close": "28787.8",
476
+ // "volume": "0.466"
477
+ // },
478
+ // ]
479
+ // }
480
+ //
481
+ const messageHash = this.safeString(message, 'channel');
482
+ const marketId = this.safeString(message, 'product_id');
483
+ const market = this.safeMarket(marketId);
484
+ const symbol = market['symbol'];
485
+ const timeframe = this.findTimeframe(messageHash);
486
+ this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
487
+ if (this.safeValue(this.ohlcvs[symbol], timeframe) === undefined) {
488
+ const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
489
+ this.ohlcvs[symbol][timeframe] = new ArrayCacheByTimestamp(limit);
490
+ }
491
+ const stored = this.ohlcvs[symbol][timeframe];
492
+ const data = this.safeList(message, 'candles', []);
493
+ for (let i = 0; i < data.length; i++) {
494
+ const tick = data[i];
495
+ const parsed = this.parseOHLCV(tick, market);
496
+ stored.append(parsed);
497
+ }
498
+ client.resolve(stored, messageHash + '::' + symbol);
499
+ }
358
500
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
359
501
  /**
360
502
  * @method
@@ -636,7 +778,7 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
636
778
  if (this.handleErrorMessage(client, message)) {
637
779
  return;
638
780
  }
639
- const channel = this.safeString(message, 'channel');
781
+ const channel = this.safeString(message, 'channel', '');
640
782
  const methods = {
641
783
  'SUBSCRIPTIONS': this.handleSubscriptionStatus,
642
784
  'INSTRUMENTS': this.handleInstrument,
@@ -651,6 +793,9 @@ export default class coinbaseinternational extends coinbaseinternationalRest {
651
793
  const errorMessage = this.safeString(message, 'message');
652
794
  throw new ExchangeError(errorMessage);
653
795
  }
796
+ if (channel.indexOf('CANDLES') > -1) {
797
+ this.handleOHLCV(client, message);
798
+ }
654
799
  const method = this.safeValue(methods, channel);
655
800
  if (method !== undefined) {
656
801
  method.call(this, client, message);
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import cryptocomRest from '../cryptocom.js';
9
- import { AuthenticationError, ChecksumError, NetworkError } from '../base/errors.js';
9
+ import { AuthenticationError, ChecksumError, ExchangeError, NetworkError } from '../base/errors.js';
10
10
  import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide } from '../base/ws/Cache.js';
11
11
  import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
12
12
  // ---------------------------------------------------------------------------
@@ -889,6 +889,7 @@ export default class cryptocom extends cryptocomRest {
889
889
  // "message": "invalid channel {"channels":["trade.BTCUSD-PERP"]}"
890
890
  // }
891
891
  //
892
+ const id = this.safeString(message, 'id');
892
893
  const errorCode = this.safeString(message, 'code');
893
894
  try {
894
895
  if (errorCode && errorCode !== '0') {
@@ -898,6 +899,7 @@ export default class cryptocom extends cryptocomRest {
898
899
  if (messageString !== undefined) {
899
900
  this.throwBroadlyMatchedException(this.exceptions['broad'], messageString, feedback);
900
901
  }
902
+ throw new ExchangeError(feedback);
901
903
  }
902
904
  return false;
903
905
  }
@@ -910,7 +912,7 @@ export default class cryptocom extends cryptocomRest {
910
912
  }
911
913
  }
912
914
  else {
913
- client.reject(e);
915
+ client.reject(e, id);
914
916
  }
915
917
  return true;
916
918
  }
@@ -38,5 +38,5 @@ export default class hitbtc extends hitbtcRest {
38
38
  handleOrderRequest(client: Client, message: any): any;
39
39
  handleMessage(client: Client, message: any): void;
40
40
  handleAuthenticate(client: Client, message: any): any;
41
- handleError(client: Client, message: any): any;
41
+ handleError(client: Client, message: any): boolean;
42
42
  }
@@ -1215,7 +1215,9 @@ export default class hitbtc extends hitbtcRest {
1215
1215
  return message;
1216
1216
  }
1217
1217
  handleMessage(client, message) {
1218
- this.handleError(client, message);
1218
+ if (this.handleError(client, message)) {
1219
+ return;
1220
+ }
1219
1221
  let channel = this.safeString2(message, 'ch', 'method');
1220
1222
  if (channel !== undefined) {
1221
1223
  const splitChannel = channel.split('/');
@@ -1294,13 +1296,29 @@ export default class hitbtc extends hitbtcRest {
1294
1296
  //
1295
1297
  const error = this.safeValue(message, 'error');
1296
1298
  if (error !== undefined) {
1297
- const code = this.safeValue(error, 'code');
1298
- const errorMessage = this.safeString(error, 'message');
1299
- const description = this.safeString(error, 'description');
1300
- const feedback = this.id + ' ' + description;
1301
- this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
1302
- this.throwBroadlyMatchedException(this.exceptions['broad'], errorMessage, feedback);
1303
- throw new ExchangeError(feedback); // unknown message
1299
+ try {
1300
+ const code = this.safeValue(error, 'code');
1301
+ const errorMessage = this.safeString(error, 'message');
1302
+ const description = this.safeString(error, 'description');
1303
+ const feedback = this.id + ' ' + description;
1304
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
1305
+ this.throwBroadlyMatchedException(this.exceptions['broad'], errorMessage, feedback);
1306
+ throw new ExchangeError(feedback); // unknown message
1307
+ }
1308
+ catch (e) {
1309
+ if (e instanceof AuthenticationError) {
1310
+ const messageHash = 'authenticated';
1311
+ client.reject(e, messageHash);
1312
+ if (messageHash in client.subscriptions) {
1313
+ delete client.subscriptions[messageHash];
1314
+ }
1315
+ }
1316
+ else {
1317
+ const id = this.safeString(message, 'id');
1318
+ client.reject(e, id);
1319
+ }
1320
+ return true;
1321
+ }
1304
1322
  }
1305
1323
  return undefined;
1306
1324
  }
package/js/src/pro/okx.js CHANGED
@@ -1899,6 +1899,13 @@ export default class okx extends okxRest {
1899
1899
  }
1900
1900
  }
1901
1901
  catch (e) {
1902
+ // if the message contains an id, it means it is a response to a request
1903
+ // so we only reject that promise, instead of deleting all futures, destroying the authentication future
1904
+ const id = this.safeString(message, 'id');
1905
+ if (id !== undefined) {
1906
+ client.reject(e, id);
1907
+ return false;
1908
+ }
1902
1909
  client.reject(e);
1903
1910
  return false;
1904
1911
  }
@@ -81,7 +81,7 @@ export default class poloniex extends poloniexRest {
81
81
  * @ignore
82
82
  * @method
83
83
  * @description authenticates the user to access private web socket channels
84
- * @see https://docs.poloniex.com/#authenticated-channels-market-data-authentication
84
+ * @see https://api-docs.poloniex.com/spot/websocket/authentication
85
85
  * @returns {object} response from exchange
86
86
  */
87
87
  this.checkRequiredCredentials();
@@ -187,7 +187,7 @@ export default class poloniex extends poloniexRest {
187
187
  /**
188
188
  * @method
189
189
  * @name poloniex#createOrderWs
190
- * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-create-order
190
+ * @see https://api-docs.poloniex.com/spot/websocket/trade-request#create-order
191
191
  * @description create a trade order
192
192
  * @param {string} symbol unified symbol of the market to create an order in
193
193
  * @param {string} type 'market' or 'limit'
@@ -257,7 +257,7 @@ export default class poloniex extends poloniexRest {
257
257
  /**
258
258
  * @method
259
259
  * @name poloniex#cancelOrderWs
260
- * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-multiple-orders
260
+ * @see https://api-docs.poloniex.com/spot/websocket/trade-request#cancel-multiple-orders
261
261
  * @description cancel multiple orders
262
262
  * @param {string} id order id
263
263
  * @param {string} [symbol] unified market symbol
@@ -276,7 +276,7 @@ export default class poloniex extends poloniexRest {
276
276
  /**
277
277
  * @method
278
278
  * @name poloniex#cancelOrdersWs
279
- * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-multiple-orders
279
+ * @see https://api-docs.poloniex.com/spot/websocket/trade-request#cancel-multiple-orders
280
280
  * @description cancel multiple orders
281
281
  * @param {string[]} ids order ids
282
282
  * @param {string} symbol unified market symbol, default is undefined
@@ -295,7 +295,7 @@ export default class poloniex extends poloniexRest {
295
295
  /**
296
296
  * @method
297
297
  * @name poloniex#cancelAllOrdersWs
298
- * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-all-orders
298
+ * @see https://api-docs.poloniex.com/spot/websocket/trade-request#cancel-all-orders
299
299
  * @description cancel all open orders of a type. Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.
300
300
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
301
301
  * @param {object} [params] extra parameters specific to the poloniex api endpoint
@@ -332,7 +332,7 @@ export default class poloniex extends poloniexRest {
332
332
  * @method
333
333
  * @name poloniex#watchOHLCV
334
334
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
335
- * @see https://docs.poloniex.com/#public-channels-market-data-candlesticks
335
+ * @see https://api-docs.poloniex.com/spot/websocket/market-data#candlesticks
336
336
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
337
337
  * @param {string} timeframe the length of time each candle represents
338
338
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -357,7 +357,7 @@ export default class poloniex extends poloniexRest {
357
357
  * @method
358
358
  * @name poloniex#watchTicker
359
359
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
360
- * @see https://docs.poloniex.com/#public-channels-market-data-ticker
360
+ * @see https://api-docs.poloniex.com/spot/websocket/market-data#ticker
361
361
  * @param {string} symbol unified symbol of the market to fetch the ticker for
362
362
  * @param {object} [params] extra parameters specific to the exchange API endpoint
363
363
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -372,7 +372,7 @@ export default class poloniex extends poloniexRest {
372
372
  * @method
373
373
  * @name poloniex#watchTicker
374
374
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
375
- * @see https://docs.poloniex.com/#public-channels-market-data-ticker
375
+ * @see https://api-docs.poloniex.com/spot/websocket/market-data#ticker
376
376
  * @param {string} symbol unified symbol of the market to fetch the ticker for
377
377
  * @param {object} [params] extra parameters specific to the exchange API endpoint
378
378
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -391,7 +391,7 @@ export default class poloniex extends poloniexRest {
391
391
  * @method
392
392
  * @name poloniex#watchTrades
393
393
  * @description get the list of most recent trades for a particular symbol
394
- * @see https://docs.poloniex.com/#public-channels-market-data-trades
394
+ * @see https://api-docs.poloniex.com/spot/websocket/market-data#trades
395
395
  * @param {string} symbol unified symbol of the market to fetch trades for
396
396
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
397
397
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -412,7 +412,7 @@ export default class poloniex extends poloniexRest {
412
412
  * @method
413
413
  * @name poloniex#watchOrderBook
414
414
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
415
- * @see https://docs.poloniex.com/#public-channels-market-data-book-level-2
415
+ * @see https://api-docs.poloniex.com/spot/websocket/market-data#book-level-2
416
416
  * @param {string} symbol unified symbol of the market to fetch the order book for
417
417
  * @param {int} [limit] not used by poloniex watchOrderBook
418
418
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -430,7 +430,7 @@ export default class poloniex extends poloniexRest {
430
430
  * @method
431
431
  * @name poloniex#watchOrders
432
432
  * @description watches information on multiple orders made by the user
433
- * @see https://docs.poloniex.com/#authenticated-channels-market-data-orders
433
+ * @see https://api-docs.poloniex.com/spot/websocket/order
434
434
  * @param {string} symbol unified market symbol of the market orders were made in
435
435
  * @param {int} [since] not used by poloniex watchOrders
436
436
  * @param {int} [limit] not used by poloniex watchOrders
@@ -455,7 +455,7 @@ export default class poloniex extends poloniexRest {
455
455
  * @method
456
456
  * @name poloniex#watchMyTrades
457
457
  * @description watches information on multiple trades made by the user using orders stream
458
- * @see https://docs.poloniex.com/#authenticated-channels-market-data-orders
458
+ * @see https://api-docs.poloniex.com/spot/websocket/order
459
459
  * @param {string} symbol unified market symbol of the market orders were made in
460
460
  * @param {int} [since] not used by poloniex watchMyTrades
461
461
  * @param {int} [limit] not used by poloniex watchMyTrades
@@ -481,7 +481,7 @@ export default class poloniex extends poloniexRest {
481
481
  * @method
482
482
  * @name poloniex#watchBalance
483
483
  * @description watch balance and get the amount of funds available for trading or funds locked in orders
484
- * @see https://docs.poloniex.com/#authenticated-channels-market-data-balances
484
+ * @see https://api-docs.poloniex.com/spot/websocket/balance
485
485
  * @param {object} [params] extra parameters specific to the exchange API endpoint
486
486
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
487
487
  */
@@ -1179,15 +1179,7 @@ export default class poloniex extends poloniexRest {
1179
1179
  this.handleAuthenticate(client, message);
1180
1180
  }
1181
1181
  else if (type === undefined) {
1182
- const data = this.safeValue(message, 'data');
1183
- const item = this.safeValue(data, 0);
1184
- const orderId = this.safeString(item, 'orderId');
1185
- if (orderId === '0') {
1186
- this.handleErrorMessage(client, item);
1187
- }
1188
- else {
1189
- this.handleOrderRequest(client, message);
1190
- }
1182
+ this.handleOrderRequest(client, message);
1191
1183
  }
1192
1184
  else {
1193
1185
  const data = this.safeValue(message, 'data', []);
@@ -1215,12 +1207,45 @@ export default class poloniex extends poloniexRest {
1215
1207
  // "event": "error",
1216
1208
  // "message": "Platform in maintenance mode"
1217
1209
  // }
1210
+ // {
1211
+ // "id":"1722386782048",
1212
+ // "data":[
1213
+ // {
1214
+ // "orderId":0,
1215
+ // "clientOrderId":null,
1216
+ // "message":"available insufficient",
1217
+ // "code":21721
1218
+ // }
1219
+ // ]
1220
+ // }
1218
1221
  //
1222
+ const id = this.safeString(message, 'id');
1219
1223
  const event = this.safeString(message, 'event');
1220
- const orderId = this.safeString(message, 'orderId');
1224
+ const data = this.safeList(message, 'data');
1225
+ const first = this.safeDict(data, 0);
1226
+ const orderId = this.safeString(first, 'orderId');
1221
1227
  if ((event === 'error') || (orderId === '0')) {
1222
- const error = this.safeString(message, 'message');
1223
- throw new ExchangeError(this.id + ' error: ' + this.json(error));
1228
+ try {
1229
+ const error = this.safeString(first, 'message');
1230
+ const code = this.safeString(first, 'code');
1231
+ const feedback = this.id + ' ' + this.json(message);
1232
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
1233
+ this.throwBroadlyMatchedException(this.exceptions['broad'], error, feedback);
1234
+ throw new ExchangeError(feedback);
1235
+ }
1236
+ catch (e) {
1237
+ if (e instanceof AuthenticationError) {
1238
+ const messageHash = 'authenticated';
1239
+ client.reject(e, messageHash);
1240
+ if (messageHash in client.subscriptions) {
1241
+ delete client.subscriptions[messageHash];
1242
+ }
1243
+ }
1244
+ else {
1245
+ client.reject(e, id);
1246
+ }
1247
+ return true;
1248
+ }
1224
1249
  }
1225
1250
  return false;
1226
1251
  }
@@ -242,7 +242,7 @@ export default class poloniexfutures extends poloniexfuturesRest {
242
242
  * @method
243
243
  * @name poloniexfutures#watchTicker
244
244
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
245
- * @see https://futures-docs.poloniex.com/#get-real-time-symbol-ticker
245
+ * @see https://api-docs.poloniex.com/futures/websocket/public#get-real-time-symbol-ticker
246
246
  * @param {string} symbol unified symbol of the market to fetch the ticker for
247
247
  * @param {object} [params] extra parameters specific to the exchange API endpoint
248
248
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -257,7 +257,7 @@ export default class poloniexfutures extends poloniexfuturesRest {
257
257
  * @method
258
258
  * @name poloniexfutures#watchTrades
259
259
  * @description get the list of most recent trades for a particular symbol
260
- * @see https://futures-docs.poloniex.com/#full-matching-engine-data-level-3
260
+ * @see https://api-docs.poloniex.com/futures/websocket/public#full-matching-engine-datalevel-3
261
261
  * @param {string} symbol unified symbol of the market to fetch trades for
262
262
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
263
263
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -280,7 +280,7 @@ export default class poloniexfutures extends poloniexfuturesRest {
280
280
  * @method
281
281
  * @name poloniexfutures#watchOrderBook
282
282
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
283
- * @see https://futures-docs.poloniex.com/#level-2-market-data
283
+ * @see https://api-docs.poloniex.com/futures/websocket/public#level-2-market-data
284
284
  * @param {string} symbol unified symbol of the market to fetch the order book for
285
285
  * @param {int} [limit] not used by poloniexfutures watchOrderBook
286
286
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -310,7 +310,7 @@ export default class poloniexfutures extends poloniexfuturesRest {
310
310
  * @method
311
311
  * @name poloniexfutures#watchOrders
312
312
  * @description watches information on multiple orders made by the user
313
- * @see https://futures-docs.poloniex.com/#private-messages
313
+ * @see https://api-docs.poloniex.com/futures/websocket/user-messages#private-messages
314
314
  * @param {string} symbol filter by unified market symbol of the market orders were made in
315
315
  * @param {int} [since] the earliest time in ms to fetch orders for
316
316
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -337,7 +337,7 @@ export default class poloniexfutures extends poloniexfuturesRest {
337
337
  * @method
338
338
  * @name poloniexfutures#watchBalance
339
339
  * @description watch balance and get the amount of funds available for trading or funds locked in orders
340
- * @see https://futures-docs.poloniex.com/#account-balance-events
340
+ * @see https://api-docs.poloniex.com/futures/websocket/user-messages#account-balance-events
341
341
  * @param {object} [params] extra parameters specific to the exchange API endpoint
342
342
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
343
343
  */
package/js/src/pro/woo.js CHANGED
@@ -30,7 +30,7 @@ export default class woo extends wooRest {
30
30
  'api': {
31
31
  'ws': {
32
32
  'public': 'wss://wss.woo.org/ws/stream',
33
- 'private': 'wss://wss.woo.network/v2/ws/private/stream',
33
+ 'private': 'wss://wss.woo.org/v2/ws/private/stream',
34
34
  },
35
35
  },
36
36
  'test': {
@@ -75,7 +75,8 @@ export default class woo extends wooRest {
75
75
  return newValue;
76
76
  }
77
77
  async watchPublic(messageHash, message) {
78
- const url = this.urls['api']['ws']['public'] + '/' + this.uid;
78
+ const urlUid = (this.uid) ? '/' + this.uid : '';
79
+ const url = this.urls['api']['ws']['public'] + urlUid;
79
80
  const requestId = this.requestId(url);
80
81
  const subscribe = {
81
82
  'id': requestId,
@@ -469,7 +470,7 @@ export default class woo extends wooRest {
469
470
  const marketId = this.safeString(trade, 'symbol');
470
471
  market = this.safeMarket(marketId, market);
471
472
  const symbol = market['symbol'];
472
- const price = this.safeString(trade, 'executedPrice', 'price');
473
+ const price = this.safeString2(trade, 'executedPrice', 'price');
473
474
  const amount = this.safeString2(trade, 'executedQuantity', 'size');
474
475
  const cost = Precise.stringMul(price, amount);
475
476
  const side = this.safeStringLower(trade, 'side');
@@ -507,7 +508,7 @@ export default class woo extends wooRest {
507
508
  checkRequiredUid(error = true) {
508
509
  if (!this.uid) {
509
510
  if (error) {
510
- throw new AuthenticationError(this.id + ' requires `uid` credential');
511
+ throw new AuthenticationError(this.id + ' requires `uid` credential (woox calls it `application_id`)');
511
512
  }
512
513
  else {
513
514
  return false;