ccxt 4.2.9 → 4.2.11

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 (56) hide show
  1. package/README.md +3 -3
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +322 -164
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +48 -8
  7. package/dist/cjs/src/binance.js +6 -1
  8. package/dist/cjs/src/bingx.js +0 -10
  9. package/dist/cjs/src/bitget.js +14 -5
  10. package/dist/cjs/src/bl3p.js +1 -1
  11. package/dist/cjs/src/btcalpha.js +1 -1
  12. package/dist/cjs/src/bybit.js +1 -1
  13. package/dist/cjs/src/cryptocom.js +3 -1
  14. package/dist/cjs/src/deribit.js +39 -22
  15. package/dist/cjs/src/kraken.js +1 -1
  16. package/dist/cjs/src/kucoin.js +30 -6
  17. package/dist/cjs/src/lykke.js +1 -1
  18. package/dist/cjs/src/ndax.js +1 -1
  19. package/dist/cjs/src/pro/bitmart.js +49 -27
  20. package/dist/cjs/src/pro/blockchaincom.js +2 -28
  21. package/dist/cjs/src/pro/coinbasepro.js +9 -16
  22. package/dist/cjs/src/pro/cryptocom.js +110 -28
  23. package/dist/cjs/src/pro/luno.js +5 -5
  24. package/js/ccxt.d.ts +1 -1
  25. package/js/ccxt.js +1 -1
  26. package/js/src/base/Exchange.d.ts +5 -3
  27. package/js/src/base/Exchange.js +48 -8
  28. package/js/src/binance.js +6 -1
  29. package/js/src/bingx.d.ts +0 -1
  30. package/js/src/bingx.js +0 -10
  31. package/js/src/bitget.js +14 -5
  32. package/js/src/bl3p.d.ts +2 -2
  33. package/js/src/bl3p.js +1 -1
  34. package/js/src/btcalpha.d.ts +2 -2
  35. package/js/src/btcalpha.js +1 -1
  36. package/js/src/bybit.js +1 -1
  37. package/js/src/cryptocom.js +3 -1
  38. package/js/src/deribit.js +39 -22
  39. package/js/src/kraken.d.ts +2 -2
  40. package/js/src/kraken.js +1 -1
  41. package/js/src/kucoin.js +30 -6
  42. package/js/src/lykke.d.ts +2 -2
  43. package/js/src/lykke.js +1 -1
  44. package/js/src/ndax.d.ts +2 -2
  45. package/js/src/ndax.js +1 -1
  46. package/js/src/pro/bitmart.d.ts +1 -0
  47. package/js/src/pro/bitmart.js +49 -27
  48. package/js/src/pro/blockchaincom.d.ts +1 -11
  49. package/js/src/pro/blockchaincom.js +2 -28
  50. package/js/src/pro/coinbasepro.js +9 -16
  51. package/js/src/pro/cryptocom.d.ts +3 -1
  52. package/js/src/pro/cryptocom.js +111 -29
  53. package/js/src/pro/luno.d.ts +4 -4
  54. package/js/src/pro/luno.js +5 -5
  55. package/package.json +11 -11
  56. package/tests-manager.sh +2 -2
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import cryptocomRest from '../cryptocom.js';
9
- import { AuthenticationError, NetworkError } from '../base/errors.js';
9
+ import { AuthenticationError, InvalidNonce, 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
  // ---------------------------------------------------------------------------
@@ -74,6 +74,8 @@ export default class cryptocom extends cryptocomRest {
74
74
  * @param {string} symbol unified symbol of the market to fetch the order book for
75
75
  * @param {int} [limit] the maximum amount of order book entries to return
76
76
  * @param {object} [params] extra parameters specific to the exchange API endpoint
77
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
78
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
77
79
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
78
80
  */
79
81
  return await this.watchOrderBookForSymbols([symbol], limit, params);
@@ -87,6 +89,8 @@ export default class cryptocom extends cryptocomRest {
87
89
  * @param {string[]} symbols unified array of symbols
88
90
  * @param {int} [limit] the maximum amount of order book entries to return
89
91
  * @param {object} [params] extra parameters specific to the exchange API endpoint
92
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
93
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
90
94
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
91
95
  */
92
96
  await this.loadMarkets();
@@ -94,12 +98,26 @@ export default class cryptocom extends cryptocomRest {
94
98
  const topics = [];
95
99
  const messageHashes = [];
96
100
  if (!limit) {
97
- limit = 150;
101
+ limit = 50;
102
+ }
103
+ const topicParams = this.safeValue(params, 'params');
104
+ if (topicParams === undefined) {
105
+ params['params'] = {};
106
+ }
107
+ let bookSubscriptionType = undefined;
108
+ [bookSubscriptionType, params] = this.handleOptionAndParams2(params, 'watchOrderBook', 'watchOrderBookForSymbols', 'bookSubscriptionType', 'SNAPSHOT_AND_UPDATE');
109
+ if (bookSubscriptionType !== undefined) {
110
+ params['params']['bookSubscriptionType'] = bookSubscriptionType;
111
+ }
112
+ let bookUpdateFrequency = undefined;
113
+ [bookUpdateFrequency, params] = this.handleOptionAndParams2(params, 'watchOrderBook', 'watchOrderBookForSymbols', 'bookUpdateFrequency');
114
+ if (bookUpdateFrequency !== undefined) {
115
+ params['params']['bookSubscriptionType'] = bookSubscriptionType;
98
116
  }
99
117
  for (let i = 0; i < symbols.length; i++) {
100
118
  const symbol = symbols[i];
101
119
  const market = this.market(symbol);
102
- const currentTopic = 'book' + '.' + market['id'] + '.' + limit;
120
+ const currentTopic = 'book' + '.' + market['id'] + '.' + limit.toString();
103
121
  const messageHash = 'orderbook:' + market['symbol'];
104
122
  messageHashes.push(messageHash);
105
123
  topics.push(currentTopic);
@@ -107,27 +125,72 @@ export default class cryptocom extends cryptocomRest {
107
125
  const orderbook = await this.watchPublicMultiple(messageHashes, topics, params);
108
126
  return orderbook.limit();
109
127
  }
110
- handleOrderBookSnapshot(client, message) {
111
- // full snapshot
128
+ handleDelta(bookside, delta) {
129
+ const price = this.safeFloat(delta, 0);
130
+ const amount = this.safeFloat(delta, 1);
131
+ const count = this.safeInteger(delta, 2);
132
+ bookside.store(price, amount, count);
133
+ }
134
+ handleDeltas(bookside, deltas) {
135
+ for (let i = 0; i < deltas.length; i++) {
136
+ this.handleDelta(bookside, deltas[i]);
137
+ }
138
+ }
139
+ handleOrderBook(client, message) {
112
140
  //
113
- // {
114
- // "instrument_name":"LTC_USDT",
115
- // "subscription":"book.LTC_USDT.150",
116
- // "channel":"book",
117
- // "depth":150,
118
- // "data": [
119
- // {
120
- // "bids": [
121
- // [122.21, 0.74041, 4]
122
- // ],
123
- // "asks": [
124
- // [122.29, 0.00002, 1]
125
- // ]
126
- // "t": 1648123943803,
127
- // "s":754560122
128
- // }
129
- // ]
130
- // }
141
+ // snapshot
142
+ // {
143
+ // "instrument_name":"LTC_USDT",
144
+ // "subscription":"book.LTC_USDT.150",
145
+ // "channel":"book",
146
+ // "depth":150,
147
+ // "data": [
148
+ // {
149
+ // "bids": [
150
+ // [122.21, 0.74041, 4]
151
+ // ],
152
+ // "asks": [
153
+ // [122.29, 0.00002, 1]
154
+ // ]
155
+ // "t": 1648123943803,
156
+ // "s":754560122
157
+ // }
158
+ // ]
159
+ // }
160
+ // update
161
+ // {
162
+ // "instrument_name":"BTC_USDT",
163
+ // "subscription":"book.BTC_USDT.50",
164
+ // "channel":"book.update",
165
+ // "depth":50,
166
+ // "data":[
167
+ // {
168
+ // "update":{
169
+ // "asks":[
170
+ // [
171
+ // "43755.46",
172
+ // "0.10000",
173
+ // "1"
174
+ // ],
175
+ // ...
176
+ // ],
177
+ // "bids":[
178
+ // [
179
+ // "43737.46",
180
+ // "0.14096",
181
+ // "1"
182
+ // ],
183
+ // ...
184
+ // ]
185
+ // },
186
+ // "t":1704484068898,
187
+ // "tt":1704484068892,
188
+ // "u":78795598253024,
189
+ // "pu":78795598162080,
190
+ // "cs":-781431132
191
+ // }
192
+ // ]
193
+ // }
131
194
  //
132
195
  const marketId = this.safeString(message, 'instrument_name');
133
196
  const market = this.safeMarket(marketId);
@@ -135,14 +198,32 @@ export default class cryptocom extends cryptocomRest {
135
198
  let data = this.safeValue(message, 'data');
136
199
  data = this.safeValue(data, 0);
137
200
  const timestamp = this.safeInteger(data, 't');
138
- const snapshot = this.parseOrderBook(data, symbol, timestamp);
139
- snapshot['nonce'] = this.safeInteger(data, 's');
140
201
  let orderbook = this.safeValue(this.orderbooks, symbol);
141
202
  if (orderbook === undefined) {
142
203
  const limit = this.safeInteger(message, 'depth');
143
- orderbook = this.orderBook({}, limit);
204
+ orderbook = this.countedOrderBook({}, limit);
144
205
  }
145
- orderbook.reset(snapshot);
206
+ const channel = this.safeString(message, 'channel');
207
+ const nonce = this.safeInteger2(data, 'u', 's');
208
+ let books = data;
209
+ if (channel === 'book') { // snapshot
210
+ orderbook.reset({});
211
+ orderbook['symbol'] = symbol;
212
+ orderbook['timestamp'] = timestamp;
213
+ orderbook['datetime'] = this.iso8601(timestamp);
214
+ orderbook['nonce'] = nonce;
215
+ }
216
+ else {
217
+ books = this.safeValue(data, 'update', {});
218
+ const previousNonce = this.safeInteger(data, 'pu');
219
+ const currentNonce = orderbook['nonce'];
220
+ if (currentNonce !== previousNonce) {
221
+ throw new InvalidNonce(this.id + ' watchOrderBook() ' + symbol + ' ' + previousNonce + ' != ' + nonce);
222
+ }
223
+ }
224
+ this.handleDeltas(orderbook['asks'], this.safeValue(books, 'asks', []));
225
+ this.handleDeltas(orderbook['bids'], this.safeValue(books, 'bids', []));
226
+ orderbook['nonce'] = nonce;
146
227
  this.orderbooks[symbol] = orderbook;
147
228
  const messageHash = 'orderbook:' + symbol;
148
229
  client.resolve(orderbook, messageHash);
@@ -764,7 +845,7 @@ export default class cryptocom extends cryptocomRest {
764
845
  },
765
846
  'nonce': id,
766
847
  };
767
- const message = this.extend(request, params);
848
+ const message = this.deepExtend(request, params);
768
849
  return await this.watchMultiple(url, messageHashes, message, messageHashes);
769
850
  }
770
851
  async watchPrivateRequest(nonce, params = {}) {
@@ -831,7 +912,8 @@ export default class cryptocom extends cryptocomRest {
831
912
  'candlestick': this.handleOHLCV,
832
913
  'ticker': this.handleTicker,
833
914
  'trade': this.handleTrades,
834
- 'book': this.handleOrderBookSnapshot,
915
+ 'book': this.handleOrderBook,
916
+ 'book.update': this.handleOrderBook,
835
917
  'user.order': this.handleOrders,
836
918
  'user.trade': this.handleTrades,
837
919
  'user.balance': this.handleBalance,
@@ -1,5 +1,5 @@
1
1
  import lunoRest from '../luno.js';
2
- import type { Int, Trade, OrderBook } from '../base/types.js';
2
+ import type { Int, Trade, OrderBook, IndexType } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class luno extends lunoRest {
5
5
  describe(): any;
@@ -8,7 +8,7 @@ export default class luno extends lunoRest {
8
8
  parseTrade(trade: any, market?: any): Trade;
9
9
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
10
10
  handleOrderBook(client: Client, message: any, subscription: any): void;
11
- customParseOrderBook(orderbook: any, symbol: any, timestamp?: any, bidsKey?: string, asksKey?: string, priceKey?: string, amountKey?: string, thirdKey?: any): {
11
+ customParseOrderBook(orderbook: any, symbol: any, timestamp?: any, bidsKey?: string, asksKey?: IndexType, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): {
12
12
  symbol: any;
13
13
  bids: any;
14
14
  asks: any;
@@ -16,8 +16,8 @@ export default class luno extends lunoRest {
16
16
  datetime: string;
17
17
  nonce: any;
18
18
  };
19
- parseBidsAsks(bidasks: any, priceKey?: string, amountKey?: string, thirdKey?: any): any[];
20
- customParseBidAsk(bidask: any, priceKey?: string, amountKey?: string, thirdKey?: any): number[];
19
+ parseBidsAsks(bidasks: any, priceKey?: IndexType, amountKey?: IndexType, thirdKey?: IndexType): any[];
20
+ customParseBidAsk(bidask: any, priceKey?: IndexType, amountKey?: IndexType, thirdKey?: IndexType): number[];
21
21
  handleDelta(orderbook: any, message: any): any;
22
22
  handleMessage(client: Client, message: any): any;
23
23
  }
@@ -213,9 +213,9 @@ export default class luno extends lunoRest {
213
213
  storedOrderBook['nonce'] = nonce;
214
214
  client.resolve(storedOrderBook, messageHash);
215
215
  }
216
- customParseOrderBook(orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 'price', amountKey = 'volume', thirdKey = undefined) {
217
- const bids = this.parseBidsAsks(this.safeValue(orderbook, bidsKey, []), priceKey, amountKey, thirdKey);
218
- const asks = this.parseBidsAsks(this.safeValue(orderbook, asksKey, []), priceKey, amountKey, thirdKey);
216
+ customParseOrderBook(orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 'price', amountKey = 'volume', countOrIdKey = 2) {
217
+ const bids = this.parseBidsAsks(this.safeValue(orderbook, bidsKey, []), priceKey, amountKey, countOrIdKey);
218
+ const asks = this.parseBidsAsks(this.safeValue(orderbook, asksKey, []), priceKey, amountKey, countOrIdKey);
219
219
  return {
220
220
  'symbol': symbol,
221
221
  'bids': this.sortBy(bids, 0, true),
@@ -225,7 +225,7 @@ export default class luno extends lunoRest {
225
225
  'nonce': undefined,
226
226
  };
227
227
  }
228
- parseBidsAsks(bidasks, priceKey = 'price', amountKey = 'volume', thirdKey = undefined) {
228
+ parseBidsAsks(bidasks, priceKey = 'price', amountKey = 'volume', thirdKey = 2) {
229
229
  bidasks = this.toArray(bidasks);
230
230
  const result = [];
231
231
  for (let i = 0; i < bidasks.length; i++) {
@@ -233,7 +233,7 @@ export default class luno extends lunoRest {
233
233
  }
234
234
  return result;
235
235
  }
236
- customParseBidAsk(bidask, priceKey = 'price', amountKey = 'volume', thirdKey = undefined) {
236
+ customParseBidAsk(bidask, priceKey = 'price', amountKey = 'volume', thirdKey = 2) {
237
237
  const price = this.safeNumber(bidask, priceKey);
238
238
  const amount = this.safeNumber(bidask, amountKey);
239
239
  const result = [price, amount];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.9",
3
+ "version": "4.2.11",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",
@@ -35,17 +35,17 @@
35
35
  "pre-transpile": "npm run export-exchanges && npm run vss && npm run tsBuild && npm run emitAPI && npm run validate-types && npm run tsBuildExamples && npm run copy-python-files && npm run check-js-syntax && npm run bundle",
36
36
  "pre-transpile-pr": "npm run export-exchanges && npm run tsBuild && npm run emitAPI && npm run check-js-syntax",
37
37
  "post-transpile": "npm run check-python-syntax && npm run check-php-syntax",
38
- "test-ws": "npm run build && node run-tests --ws",
39
- "test": "npm run build && npm run commonjs-test && npm run static-tests && node run-tests",
40
- "fast-test": "npm run commonjs-test && node run-tests --js",
38
+ "test-ws": "npm run build && node run-tests --ws --useProxy",
39
+ "test": "npm run build && npm run commonjs-test && npm run static-tests && node run-tests --useProxy",
40
+ "fast-test": "npm run commonjs-test && node run-tests --js --useProxy",
41
41
  "commonjs-test": "node test-commonjs.cjs",
42
- "fast-test-ws": "node run-tests --ws --js",
43
- "test-js": "npm run commonjs-test && node run-tests --js",
44
- "test-js-ws": "node run-tests --ws --js",
45
- "test-py": "node run-tests --python",
46
- "test-py-ws": "node run-tests --ws --python",
47
- "test-php": "node run-tests --php",
48
- "test-php-ws": "node run-tests --ws --php",
42
+ "fast-test-ws": "node run-tests --ws --js --useProxy",
43
+ "test-js": "npm run commonjs-test && node run-tests --js --useProxy",
44
+ "test-js-ws": "node run-tests --ws --js --useProxy",
45
+ "test-py": "node run-tests --python --useProxy",
46
+ "test-py-ws": "node run-tests --ws --python --useProxy",
47
+ "test-php": "node run-tests --php --useProxy",
48
+ "test-php-ws": "node run-tests --ws --php --useProxy",
49
49
  "test-base": "npm run test-js-base && npm run test-python-base && npm run test-php-base && npm run id-tests && npm run static-tests",
50
50
  "test-base-ws": "npm run test-js-base-ws && npm run test-python-base-ws && npm run test-php-base-ws",
51
51
  "test-js-base": "node ./js/src/test/base/test.base.js",
package/tests-manager.sh CHANGED
@@ -78,12 +78,12 @@ function run_tests {
78
78
  fi
79
79
  if [ -z "$rest_pid" ]; then
80
80
  # shellcheck disable=SC2086
81
- node test-commonjs.cjs && node run-tests --js --python-async --php-async $rest_args &
81
+ node test-commonjs.cjs && node run-tests --js --python-async --php-async --useProxy $rest_args &
82
82
  local rest_pid=$!
83
83
  fi
84
84
  if [ -z "$ws_pid" ]; then
85
85
  # shellcheck disable=SC2086
86
- node run-tests-ws --js --python-async --php-async $ws_args &
86
+ node run-tests-ws --js --python-async --php-async --useProxy $ws_args &
87
87
  local ws_pid=$!
88
88
  fi
89
89
  wait $rest_pid && wait $ws_pid && echo "$TRAVIS_BUILD_WEB_URL" > "$cached_url_file"