ccxt 4.2.9 → 4.2.10

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 (47) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +267 -143
  3. package/dist/ccxt.browser.min.js +7 -7
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +37 -8
  6. package/dist/cjs/src/binance.js +6 -1
  7. package/dist/cjs/src/bl3p.js +1 -1
  8. package/dist/cjs/src/btcalpha.js +1 -1
  9. package/dist/cjs/src/cryptocom.js +3 -1
  10. package/dist/cjs/src/deribit.js +39 -22
  11. package/dist/cjs/src/kraken.js +1 -1
  12. package/dist/cjs/src/kucoin.js +1 -1
  13. package/dist/cjs/src/lykke.js +1 -1
  14. package/dist/cjs/src/ndax.js +1 -1
  15. package/dist/cjs/src/pro/bitmart.js +49 -27
  16. package/dist/cjs/src/pro/blockchaincom.js +2 -28
  17. package/dist/cjs/src/pro/coinbasepro.js +9 -16
  18. package/dist/cjs/src/pro/cryptocom.js +110 -28
  19. package/dist/cjs/src/pro/luno.js +5 -5
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/base/Exchange.d.ts +4 -3
  23. package/js/src/base/Exchange.js +37 -8
  24. package/js/src/binance.js +6 -1
  25. package/js/src/bl3p.d.ts +2 -2
  26. package/js/src/bl3p.js +1 -1
  27. package/js/src/btcalpha.d.ts +2 -2
  28. package/js/src/btcalpha.js +1 -1
  29. package/js/src/cryptocom.js +3 -1
  30. package/js/src/deribit.js +39 -22
  31. package/js/src/kraken.d.ts +2 -2
  32. package/js/src/kraken.js +1 -1
  33. package/js/src/kucoin.js +1 -1
  34. package/js/src/lykke.d.ts +2 -2
  35. package/js/src/lykke.js +1 -1
  36. package/js/src/ndax.d.ts +2 -2
  37. package/js/src/ndax.js +1 -1
  38. package/js/src/pro/bitmart.d.ts +1 -0
  39. package/js/src/pro/bitmart.js +49 -27
  40. package/js/src/pro/blockchaincom.d.ts +1 -11
  41. package/js/src/pro/blockchaincom.js +2 -28
  42. package/js/src/pro/coinbasepro.js +9 -16
  43. package/js/src/pro/cryptocom.d.ts +3 -1
  44. package/js/src/pro/cryptocom.js +111 -29
  45. package/js/src/pro/luno.d.ts +4 -4
  46. package/js/src/pro/luno.js +5 -5
  47. package/package.json +1 -1
@@ -71,6 +71,8 @@ class cryptocom extends cryptocom$1 {
71
71
  * @param {string} symbol unified symbol of the market to fetch the order book for
72
72
  * @param {int} [limit] the maximum amount of order book entries to return
73
73
  * @param {object} [params] extra parameters specific to the exchange API endpoint
74
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
75
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
74
76
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
75
77
  */
76
78
  return await this.watchOrderBookForSymbols([symbol], limit, params);
@@ -84,6 +86,8 @@ class cryptocom extends cryptocom$1 {
84
86
  * @param {string[]} symbols unified array of symbols
85
87
  * @param {int} [limit] the maximum amount of order book entries to return
86
88
  * @param {object} [params] extra parameters specific to the exchange API endpoint
89
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
90
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
87
91
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
88
92
  */
89
93
  await this.loadMarkets();
@@ -91,12 +95,26 @@ class cryptocom extends cryptocom$1 {
91
95
  const topics = [];
92
96
  const messageHashes = [];
93
97
  if (!limit) {
94
- limit = 150;
98
+ limit = 50;
99
+ }
100
+ const topicParams = this.safeValue(params, 'params');
101
+ if (topicParams === undefined) {
102
+ params['params'] = {};
103
+ }
104
+ let bookSubscriptionType = undefined;
105
+ [bookSubscriptionType, params] = this.handleOptionAndParams2(params, 'watchOrderBook', 'watchOrderBookForSymbols', 'bookSubscriptionType', 'SNAPSHOT_AND_UPDATE');
106
+ if (bookSubscriptionType !== undefined) {
107
+ params['params']['bookSubscriptionType'] = bookSubscriptionType;
108
+ }
109
+ let bookUpdateFrequency = undefined;
110
+ [bookUpdateFrequency, params] = this.handleOptionAndParams2(params, 'watchOrderBook', 'watchOrderBookForSymbols', 'bookUpdateFrequency');
111
+ if (bookUpdateFrequency !== undefined) {
112
+ params['params']['bookSubscriptionType'] = bookSubscriptionType;
95
113
  }
96
114
  for (let i = 0; i < symbols.length; i++) {
97
115
  const symbol = symbols[i];
98
116
  const market = this.market(symbol);
99
- const currentTopic = 'book' + '.' + market['id'] + '.' + limit;
117
+ const currentTopic = 'book' + '.' + market['id'] + '.' + limit.toString();
100
118
  const messageHash = 'orderbook:' + market['symbol'];
101
119
  messageHashes.push(messageHash);
102
120
  topics.push(currentTopic);
@@ -104,27 +122,72 @@ class cryptocom extends cryptocom$1 {
104
122
  const orderbook = await this.watchPublicMultiple(messageHashes, topics, params);
105
123
  return orderbook.limit();
106
124
  }
107
- handleOrderBookSnapshot(client, message) {
108
- // full snapshot
125
+ handleDelta(bookside, delta) {
126
+ const price = this.safeFloat(delta, 0);
127
+ const amount = this.safeFloat(delta, 1);
128
+ const count = this.safeInteger(delta, 2);
129
+ bookside.store(price, amount, count);
130
+ }
131
+ handleDeltas(bookside, deltas) {
132
+ for (let i = 0; i < deltas.length; i++) {
133
+ this.handleDelta(bookside, deltas[i]);
134
+ }
135
+ }
136
+ handleOrderBook(client, message) {
109
137
  //
110
- // {
111
- // "instrument_name":"LTC_USDT",
112
- // "subscription":"book.LTC_USDT.150",
113
- // "channel":"book",
114
- // "depth":150,
115
- // "data": [
116
- // {
117
- // "bids": [
118
- // [122.21, 0.74041, 4]
119
- // ],
120
- // "asks": [
121
- // [122.29, 0.00002, 1]
122
- // ]
123
- // "t": 1648123943803,
124
- // "s":754560122
125
- // }
126
- // ]
127
- // }
138
+ // snapshot
139
+ // {
140
+ // "instrument_name":"LTC_USDT",
141
+ // "subscription":"book.LTC_USDT.150",
142
+ // "channel":"book",
143
+ // "depth":150,
144
+ // "data": [
145
+ // {
146
+ // "bids": [
147
+ // [122.21, 0.74041, 4]
148
+ // ],
149
+ // "asks": [
150
+ // [122.29, 0.00002, 1]
151
+ // ]
152
+ // "t": 1648123943803,
153
+ // "s":754560122
154
+ // }
155
+ // ]
156
+ // }
157
+ // update
158
+ // {
159
+ // "instrument_name":"BTC_USDT",
160
+ // "subscription":"book.BTC_USDT.50",
161
+ // "channel":"book.update",
162
+ // "depth":50,
163
+ // "data":[
164
+ // {
165
+ // "update":{
166
+ // "asks":[
167
+ // [
168
+ // "43755.46",
169
+ // "0.10000",
170
+ // "1"
171
+ // ],
172
+ // ...
173
+ // ],
174
+ // "bids":[
175
+ // [
176
+ // "43737.46",
177
+ // "0.14096",
178
+ // "1"
179
+ // ],
180
+ // ...
181
+ // ]
182
+ // },
183
+ // "t":1704484068898,
184
+ // "tt":1704484068892,
185
+ // "u":78795598253024,
186
+ // "pu":78795598162080,
187
+ // "cs":-781431132
188
+ // }
189
+ // ]
190
+ // }
128
191
  //
129
192
  const marketId = this.safeString(message, 'instrument_name');
130
193
  const market = this.safeMarket(marketId);
@@ -132,14 +195,32 @@ class cryptocom extends cryptocom$1 {
132
195
  let data = this.safeValue(message, 'data');
133
196
  data = this.safeValue(data, 0);
134
197
  const timestamp = this.safeInteger(data, 't');
135
- const snapshot = this.parseOrderBook(data, symbol, timestamp);
136
- snapshot['nonce'] = this.safeInteger(data, 's');
137
198
  let orderbook = this.safeValue(this.orderbooks, symbol);
138
199
  if (orderbook === undefined) {
139
200
  const limit = this.safeInteger(message, 'depth');
140
- orderbook = this.orderBook({}, limit);
201
+ orderbook = this.countedOrderBook({}, limit);
141
202
  }
142
- orderbook.reset(snapshot);
203
+ const channel = this.safeString(message, 'channel');
204
+ const nonce = this.safeInteger2(data, 'u', 's');
205
+ let books = data;
206
+ if (channel === 'book') { // snapshot
207
+ orderbook.reset({});
208
+ orderbook['symbol'] = symbol;
209
+ orderbook['timestamp'] = timestamp;
210
+ orderbook['datetime'] = this.iso8601(timestamp);
211
+ orderbook['nonce'] = nonce;
212
+ }
213
+ else {
214
+ books = this.safeValue(data, 'update', {});
215
+ const previousNonce = this.safeInteger(data, 'pu');
216
+ const currentNonce = orderbook['nonce'];
217
+ if (currentNonce !== previousNonce) {
218
+ throw new errors.InvalidNonce(this.id + ' watchOrderBook() ' + symbol + ' ' + previousNonce + ' != ' + nonce);
219
+ }
220
+ }
221
+ this.handleDeltas(orderbook['asks'], this.safeValue(books, 'asks', []));
222
+ this.handleDeltas(orderbook['bids'], this.safeValue(books, 'bids', []));
223
+ orderbook['nonce'] = nonce;
143
224
  this.orderbooks[symbol] = orderbook;
144
225
  const messageHash = 'orderbook:' + symbol;
145
226
  client.resolve(orderbook, messageHash);
@@ -761,7 +842,7 @@ class cryptocom extends cryptocom$1 {
761
842
  },
762
843
  'nonce': id,
763
844
  };
764
- const message = this.extend(request, params);
845
+ const message = this.deepExtend(request, params);
765
846
  return await this.watchMultiple(url, messageHashes, message, messageHashes);
766
847
  }
767
848
  async watchPrivateRequest(nonce, params = {}) {
@@ -828,7 +909,8 @@ class cryptocom extends cryptocom$1 {
828
909
  'candlestick': this.handleOHLCV,
829
910
  'ticker': this.handleTicker,
830
911
  'trade': this.handleTrades,
831
- 'book': this.handleOrderBookSnapshot,
912
+ 'book': this.handleOrderBook,
913
+ 'book.update': this.handleOrderBook,
832
914
  'user.order': this.handleOrders,
833
915
  'user.trade': this.handleTrades,
834
916
  'user.balance': this.handleBalance,
@@ -210,9 +210,9 @@ class luno extends luno$1 {
210
210
  storedOrderBook['nonce'] = nonce;
211
211
  client.resolve(storedOrderBook, messageHash);
212
212
  }
213
- customParseOrderBook(orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 'price', amountKey = 'volume', thirdKey = undefined) {
214
- const bids = this.parseBidsAsks(this.safeValue(orderbook, bidsKey, []), priceKey, amountKey, thirdKey);
215
- const asks = this.parseBidsAsks(this.safeValue(orderbook, asksKey, []), priceKey, amountKey, thirdKey);
213
+ customParseOrderBook(orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 'price', amountKey = 'volume', countOrIdKey = 2) {
214
+ const bids = this.parseBidsAsks(this.safeValue(orderbook, bidsKey, []), priceKey, amountKey, countOrIdKey);
215
+ const asks = this.parseBidsAsks(this.safeValue(orderbook, asksKey, []), priceKey, amountKey, countOrIdKey);
216
216
  return {
217
217
  'symbol': symbol,
218
218
  'bids': this.sortBy(bids, 0, true),
@@ -222,7 +222,7 @@ class luno extends luno$1 {
222
222
  'nonce': undefined,
223
223
  };
224
224
  }
225
- parseBidsAsks(bidasks, priceKey = 'price', amountKey = 'volume', thirdKey = undefined) {
225
+ parseBidsAsks(bidasks, priceKey = 'price', amountKey = 'volume', thirdKey = 2) {
226
226
  bidasks = this.toArray(bidasks);
227
227
  const result = [];
228
228
  for (let i = 0; i < bidasks.length; i++) {
@@ -230,7 +230,7 @@ class luno extends luno$1 {
230
230
  }
231
231
  return result;
232
232
  }
233
- customParseBidAsk(bidask, priceKey = 'price', amountKey = 'volume', thirdKey = undefined) {
233
+ customParseBidAsk(bidask, priceKey = 'price', amountKey = 'volume', thirdKey = 2) {
234
234
  const price = this.safeNumber(bidask, priceKey);
235
235
  const amount = this.safeNumber(bidask, amountKey);
236
236
  const result = [price, amount];
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 type { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks } 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, NoChange } from './src/base/errors.js';
7
- declare const version = "4.2.8";
7
+ declare const version = "4.2.9";
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, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.2.9';
41
+ const version = '4.2.10';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -678,7 +678,7 @@ export default class Exchange {
678
678
  marketIds(symbols: any): any;
679
679
  marketSymbols(symbols: any, type?: string, allowEmpty?: boolean, sameTypeOnly?: boolean, sameSubTypeOnly?: boolean): any;
680
680
  marketCodes(codes: any): any;
681
- parseBidsAsks(bidasks: any, priceKey?: IndexType, amountKey?: IndexType): any[];
681
+ parseBidsAsks(bidasks: any, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): any[];
682
682
  fetchL2OrderBook(symbol: string, limit?: Int, params?: {}): Promise<any>;
683
683
  filterBySymbol(objects: any, symbol?: string): any;
684
684
  parseOHLCV(ohlcv: any, market?: Market): OHLCV;
@@ -690,7 +690,7 @@ export default class Exchange {
690
690
  selectNetworkIdFromRawNetworks(currencyCode: any, networkCode: any, indexedNetworkEntries: any): any;
691
691
  selectNetworkKeyFromNetworks(currencyCode: any, networkCode: any, indexedNetworkEntries: any, isIndexedByUnifiedNetworkCode?: boolean): any;
692
692
  safeNumber2(dictionary: any, key1: any, key2: any, d?: any): number;
693
- parseOrderBook(orderbook: object, symbol: string, timestamp?: Int, bidsKey?: string, asksKey?: string, priceKey?: IndexType, amountKey?: IndexType): OrderBook;
693
+ parseOrderBook(orderbook: object, symbol: string, timestamp?: Int, bidsKey?: string, asksKey?: string, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): OrderBook;
694
694
  parseOHLCVs(ohlcvs: object[], market?: any, timeframe?: string, since?: Int, limit?: Int): OHLCV[];
695
695
  parseLeverageTiers(response: any, symbols?: string[], marketIdKey?: any): {};
696
696
  loadTradingLimits(symbols?: string[], reload?: boolean, params?: {}): Promise<Dictionary<any>>;
@@ -726,7 +726,7 @@ export default class Exchange {
726
726
  fetchPositions(symbols?: string[], params?: {}): Promise<Position[]>;
727
727
  fetchPositionsRisk(symbols?: string[], params?: {}): Promise<Position[]>;
728
728
  fetchBidsAsks(symbols?: string[], params?: {}): Promise<Dictionary<Ticker>>;
729
- parseBidAsk(bidask: any, priceKey?: IndexType, amountKey?: IndexType): number[];
729
+ parseBidAsk(bidask: any, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): number[];
730
730
  safeCurrency(currencyId: Str, currency?: Currency): CurrencyInterface;
731
731
  safeMarket(marketId: Str, market?: Market, delimiter?: Str, marketType?: Str): MarketInterface;
732
732
  checkRequiredCredentials(error?: boolean): boolean;
@@ -750,6 +750,7 @@ export default class Exchange {
750
750
  fetchCrossBorrowRate(code: string, params?: {}): Promise<any>;
751
751
  fetchIsolatedBorrowRate(symbol: string, params?: {}): Promise<any>;
752
752
  handleOptionAndParams(params: any, methodName: any, optionName: any, defaultValue?: any): any[];
753
+ handleOptionAndParams2(params: any, methodName: any, methodName2: any, optionName: any, defaultValue?: any): any[];
753
754
  handleOption(methodName: any, optionName: any, defaultValue?: any): any;
754
755
  handleMarketTypeAndParams(methodName: string, market?: Market, params?: {}): any;
755
756
  handleSubTypeAndParams(methodName: any, market?: any, params?: {}, defaultValue?: any): any[];
@@ -2858,11 +2858,11 @@ export default class Exchange {
2858
2858
  }
2859
2859
  return result;
2860
2860
  }
2861
- parseBidsAsks(bidasks, priceKey = 0, amountKey = 1) {
2861
+ parseBidsAsks(bidasks, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
2862
2862
  bidasks = this.toArray(bidasks);
2863
2863
  const result = [];
2864
2864
  for (let i = 0; i < bidasks.length; i++) {
2865
- result.push(this.parseBidAsk(bidasks[i], priceKey, amountKey));
2865
+ result.push(this.parseBidAsk(bidasks[i], priceKey, amountKey, countOrIdKey));
2866
2866
  }
2867
2867
  return result;
2868
2868
  }
@@ -3031,9 +3031,9 @@ export default class Exchange {
3031
3031
  const value = this.safeString2(dictionary, key1, key2);
3032
3032
  return this.parseNumber(value, d);
3033
3033
  }
3034
- parseOrderBook(orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 0, amountKey = 1) {
3035
- const bids = this.parseBidsAsks(this.safeValue(orderbook, bidsKey, []), priceKey, amountKey);
3036
- const asks = this.parseBidsAsks(this.safeValue(orderbook, asksKey, []), priceKey, amountKey);
3034
+ parseOrderBook(orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 0, amountKey = 1, countOrIdKey = 2) {
3035
+ const bids = this.parseBidsAsks(this.safeValue(orderbook, bidsKey, []), priceKey, amountKey, countOrIdKey);
3036
+ const asks = this.parseBidsAsks(this.safeValue(orderbook, asksKey, []), priceKey, amountKey, countOrIdKey);
3037
3037
  return {
3038
3038
  'symbol': symbol,
3039
3039
  'bids': this.sortBy(bids, 0, true),
@@ -3348,10 +3348,15 @@ export default class Exchange {
3348
3348
  async fetchBidsAsks(symbols = undefined, params = {}) {
3349
3349
  throw new NotSupported(this.id + ' fetchBidsAsks() is not supported yet');
3350
3350
  }
3351
- parseBidAsk(bidask, priceKey = 0, amountKey = 1) {
3351
+ parseBidAsk(bidask, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
3352
3352
  const price = this.safeNumber(bidask, priceKey);
3353
3353
  const amount = this.safeNumber(bidask, amountKey);
3354
- return [price, amount];
3354
+ const countOrId = this.safeInteger(bidask, countOrIdKey);
3355
+ const bidAsk = [price, amount];
3356
+ if (countOrId !== undefined) {
3357
+ bidAsk.push(countOrId);
3358
+ }
3359
+ return bidAsk;
3355
3360
  }
3356
3361
  safeCurrency(currencyId, currency = undefined) {
3357
3362
  if ((currencyId === undefined) && (currency !== undefined)) {
@@ -3399,7 +3404,7 @@ export default class Exchange {
3399
3404
  }
3400
3405
  }
3401
3406
  }
3402
- else if (delimiter !== undefined) {
3407
+ else if (delimiter !== undefined && delimiter !== '') {
3403
3408
  const parts = marketId.split(delimiter);
3404
3409
  const partsLength = parts.length;
3405
3410
  if (partsLength === 2) {
@@ -3560,6 +3565,30 @@ export default class Exchange {
3560
3565
  }
3561
3566
  return [value, params];
3562
3567
  }
3568
+ handleOptionAndParams2(params, methodName, methodName2, optionName, defaultValue = undefined) {
3569
+ // This method can be used to obtain method specific properties, i.e: this.handleOptionAndParams (params, 'fetchPosition', 'marginMode', 'isolated')
3570
+ const defaultOptionName = 'default' + this.capitalize(optionName); // we also need to check the 'defaultXyzWhatever'
3571
+ // check if params contain the key
3572
+ let value = this.safeValue2(params, optionName, defaultOptionName);
3573
+ if (value !== undefined) {
3574
+ params = this.omit(params, [optionName, defaultOptionName]);
3575
+ }
3576
+ else {
3577
+ // check if exchange has properties for this method
3578
+ const exchangeWideMethodOptions = this.safeValue2(this.options, methodName, methodName2);
3579
+ if (exchangeWideMethodOptions !== undefined) {
3580
+ // check if the option is defined inside this method's props
3581
+ value = this.safeValue2(exchangeWideMethodOptions, optionName, defaultOptionName);
3582
+ }
3583
+ if (value === undefined) {
3584
+ // if it's still undefined, check if global exchange-wide option exists
3585
+ value = this.safeValue2(this.options, optionName, defaultOptionName);
3586
+ }
3587
+ // if it's still undefined, use the default value
3588
+ value = (value !== undefined) ? value : defaultValue;
3589
+ }
3590
+ return [value, params];
3591
+ }
3563
3592
  handleOption(methodName, optionName, defaultValue = undefined) {
3564
3593
  // eslint-disable-next-line no-unused-vars
3565
3594
  const [result, empty] = this.handleOptionAndParams({}, methodName, optionName, defaultValue);
package/js/src/binance.js CHANGED
@@ -3148,7 +3148,12 @@ export default class binance extends Exchange {
3148
3148
  response = await this.dapiPublicGetTickerBookTicker(params);
3149
3149
  }
3150
3150
  else {
3151
- response = await this.publicGetTickerBookTicker(params);
3151
+ const request = {};
3152
+ if (symbols !== undefined) {
3153
+ const marketIds = this.marketIds(symbols);
3154
+ request['symbols'] = this.json(marketIds);
3155
+ }
3156
+ response = await this.publicGetTickerBookTicker(this.extend(request, params));
3152
3157
  }
3153
3158
  return this.parseTickers(response, symbols);
3154
3159
  }
package/js/src/bl3p.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bl3p.js';
2
- import type { Balances, Int, Market, OrderBook, OrderSide, OrderType, Str, Ticker, Trade } from './base/types.js';
2
+ import type { Balances, Int, Market, OrderBook, OrderSide, OrderType, Str, Ticker, Trade, IndexType } from './base/types.js';
3
3
  /**
4
4
  * @class bl3p
5
5
  * @augments Exchange
@@ -8,7 +8,7 @@ export default class bl3p extends Exchange {
8
8
  describe(): any;
9
9
  parseBalance(response: any): Balances;
10
10
  fetchBalance(params?: {}): Promise<Balances>;
11
- parseBidAsk(bidask: any, priceKey?: number, amountKey?: number): number[];
11
+ parseBidAsk(bidask: any, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): number[];
12
12
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
13
13
  parseTicker(ticker: any, market?: Market): Ticker;
14
14
  fetchTicker(symbol: string, params?: {}): Promise<Ticker>;
package/js/src/bl3p.js CHANGED
@@ -149,7 +149,7 @@ export default class bl3p extends Exchange {
149
149
  const response = await this.privatePostGENMKTMoneyInfo(params);
150
150
  return this.parseBalance(response);
151
151
  }
152
- parseBidAsk(bidask, priceKey = 0, amountKey = 1) {
152
+ parseBidAsk(bidask, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
153
153
  const price = this.safeString(bidask, priceKey);
154
154
  const size = this.safeString(bidask, amountKey);
155
155
  return [
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/btcalpha.js';
2
- import type { Balances, Currency, Int, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
2
+ import type { IndexType, Balances, Currency, Int, Market, OHLCV, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
3
3
  /**
4
4
  * @class btcalpha
5
5
  * @augments Exchange
@@ -12,7 +12,7 @@ export default class btcalpha extends Exchange {
12
12
  fetchTicker(symbol: string, params?: {}): Promise<Ticker>;
13
13
  parseTicker(ticker: any, market?: Market): Ticker;
14
14
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
15
- parseBidsAsks(bidasks: any, priceKey?: number, amountKey?: number): any[];
15
+ parseBidsAsks(bidasks: any, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): any[];
16
16
  parseTrade(trade: any, market?: Market): Trade;
17
17
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
18
18
  fetchDeposits(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Transaction[]>;
@@ -362,7 +362,7 @@ export default class btcalpha extends Exchange {
362
362
  const response = await this.publicGetOrderbookPairName(this.extend(request, params));
363
363
  return this.parseOrderBook(response, market['symbol'], undefined, 'buy', 'sell', 'price', 'amount');
364
364
  }
365
- parseBidsAsks(bidasks, priceKey = 0, amountKey = 1) {
365
+ parseBidsAsks(bidasks, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
366
366
  const result = [];
367
367
  for (let i = 0; i < bidasks.length; i++) {
368
368
  const bidask = bidasks[i];
@@ -773,6 +773,7 @@ export default class cryptocom extends Exchange {
773
773
  // "p": "26386.00",
774
774
  // "q": "0.00453",
775
775
  // "t": 1686944282062,
776
+ // "tn" : 1704476468851524373,
776
777
  // "d": "4611686018455979970",
777
778
  // "i": "BTC_USD"
778
779
  // },
@@ -1943,7 +1944,8 @@ export default class cryptocom extends Exchange {
1943
1944
  // "s": "sell",
1944
1945
  // "p": "26386.00",
1945
1946
  // "q": "0.00453",
1946
- // "t": 1686944282062,
1947
+ // "tn": 1686944282062,
1948
+ // "tn": 1704476468851524373,
1947
1949
  // "d": "4611686018455979970",
1948
1950
  // "i": "BTC_USD"
1949
1951
  // }
package/js/src/deribit.js CHANGED
@@ -1726,27 +1726,18 @@ export default class deribit extends Exchange {
1726
1726
  * @param {string} symbol unified symbol of the market to create an order in
1727
1727
  * @param {string} type 'market' or 'limit'
1728
1728
  * @param {string} side 'buy' or 'sell'
1729
- * @param {float} amount how much of currency you want to trade. For perpetual and futures the amount is in USD. For options it is in corresponding cryptocurrency contracts currency.
1729
+ * @param {float} amount how much you want to trade in units of the base currency. For inverse perpetual and futures the amount is in the quote currency USD. For options it is in the underlying assets base currency.
1730
1730
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1731
1731
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1732
+ * @param {string} [params.trigger] the trigger type 'index_price', 'mark_price', or 'last_price', default is 'last_price'
1733
+ * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
1732
1734
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1733
1735
  */
1734
1736
  await this.loadMarkets();
1735
1737
  const market = this.market(symbol);
1736
- if (market['inverse']) {
1737
- amount = this.amountToPrecision(symbol, amount);
1738
- }
1739
- else if (market['settle'] === 'USDC') {
1740
- amount = this.amountToPrecision(symbol, amount);
1741
- }
1742
- else {
1743
- amount = this.currencyToPrecision(symbol, amount);
1744
- }
1745
1738
  const request = {
1746
1739
  'instrument_name': market['id'],
1747
- // for perpetual and futures the amount is in USD
1748
- // for options it is in corresponding cryptocurrency contracts, e.g., BTC or ETH
1749
- 'amount': amount,
1740
+ 'amount': this.amountToPrecision(symbol, amount),
1750
1741
  'type': type, // limit, stop_limit, market, stop_market, default is limit
1751
1742
  // 'label': 'string', // user-defined label for the order (maximum 64 characters)
1752
1743
  // 'price': this.priceToPrecision (symbol, 123.45), // only for limit and stop_limit orders
@@ -1759,12 +1750,15 @@ export default class deribit extends Exchange {
1759
1750
  // 'trigger': 'index_price', // mark_price, last_price, required for stop_limit orders
1760
1751
  // 'advanced': 'usd', // 'implv', advanced option order type, options only
1761
1752
  };
1753
+ const trigger = this.safeString(params, 'trigger', 'last_price');
1762
1754
  const timeInForce = this.safeStringUpper(params, 'timeInForce');
1763
1755
  const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
1764
1756
  // only stop loss sell orders are allowed when price crossed from above
1765
1757
  const stopLossPrice = this.safeValue(params, 'stopLossPrice');
1766
1758
  // only take profit buy orders are allowed when price crossed from below
1767
1759
  const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
1760
+ const trailingAmount = this.safeString2(params, 'trailingAmount', 'trigger_offset');
1761
+ const isTrailingAmountOrder = trailingAmount !== undefined;
1768
1762
  const isStopLimit = type === 'stop_limit';
1769
1763
  const isStopMarket = type === 'stop_market';
1770
1764
  const isTakeLimit = type === 'take_limit';
@@ -1786,10 +1780,15 @@ export default class deribit extends Exchange {
1786
1780
  else {
1787
1781
  request['type'] = 'market';
1788
1782
  }
1789
- if (isStopOrder) {
1783
+ if (isTrailingAmountOrder) {
1784
+ request['trigger'] = trigger;
1785
+ request['type'] = 'trailing_stop';
1786
+ request['trigger_offset'] = this.parseToNumeric(trailingAmount);
1787
+ }
1788
+ else if (isStopOrder) {
1790
1789
  const triggerPrice = (stopLossPrice !== undefined) ? stopLossPrice : takeProfitPrice;
1791
1790
  request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
1792
- request['trigger'] = 'last_price'; // required
1791
+ request['trigger'] = trigger;
1793
1792
  if (isStopLossOrder) {
1794
1793
  if (isMarketOrder) {
1795
1794
  // stop_market (sell only)
@@ -1829,7 +1828,7 @@ export default class deribit extends Exchange {
1829
1828
  request['time_in_force'] = 'fill_or_kill';
1830
1829
  }
1831
1830
  }
1832
- params = this.omit(params, ['timeInForce', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'reduceOnly']);
1831
+ params = this.omit(params, ['timeInForce', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'reduceOnly', 'trailingAmount']);
1833
1832
  let response = undefined;
1834
1833
  if (this.capitalize(side) === 'Buy') {
1835
1834
  response = await this.privateGetBuy(this.extend(request, params));
@@ -1896,25 +1895,43 @@ export default class deribit extends Exchange {
1896
1895
  return this.parseOrder(order, market);
1897
1896
  }
1898
1897
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1898
+ /**
1899
+ * @method
1900
+ * @name deribit#editOrder
1901
+ * @description edit a trade order
1902
+ * @see https://docs.deribit.com/#private-edit
1903
+ * @param {string} id edit order id
1904
+ * @param {string} [symbol] unified symbol of the market to edit an order in
1905
+ * @param {string} [type] 'market' or 'limit'
1906
+ * @param {string} [side] 'buy' or 'sell'
1907
+ * @param {float} amount how much you want to trade in units of the base currency, inverse swap and future use the quote currency
1908
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
1909
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1910
+ * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
1911
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1912
+ */
1899
1913
  if (amount === undefined) {
1900
1914
  throw new ArgumentsRequired(this.id + ' editOrder() requires an amount argument');
1901
1915
  }
1902
- if (price === undefined) {
1903
- throw new ArgumentsRequired(this.id + ' editOrder() requires a price argument');
1904
- }
1905
1916
  await this.loadMarkets();
1906
1917
  const request = {
1907
1918
  'order_id': id,
1908
- // for perpetual and futures the amount is in USD
1909
- // for options it is in corresponding cryptocurrency contracts, e.g., BTC or ETH
1910
1919
  'amount': this.amountToPrecision(symbol, amount),
1911
- 'price': this.priceToPrecision(symbol, price), // required
1912
1920
  // 'post_only': false, // if the new price would cause the order to be filled immediately (as taker), the price will be changed to be just below the spread.
1913
1921
  // 'reject_post_only': false, // if true the order is put to order book unmodified or request is rejected
1914
1922
  // 'reduce_only': false, // if true, the order is intended to only reduce a current position
1915
1923
  // 'stop_price': false, // stop price, required for stop_limit orders
1916
1924
  // 'advanced': 'usd', // 'implv', advanced option order type, options only
1917
1925
  };
1926
+ if (price !== undefined) {
1927
+ request['price'] = this.priceToPrecision(symbol, price);
1928
+ }
1929
+ const trailingAmount = this.safeString2(params, 'trailingAmount', 'trigger_offset');
1930
+ const isTrailingAmountOrder = trailingAmount !== undefined;
1931
+ if (isTrailingAmountOrder) {
1932
+ request['trigger_offset'] = this.parseToNumeric(trailingAmount);
1933
+ params = this.omit(params, 'trigger_offset');
1934
+ }
1918
1935
  const response = await this.privateGetEdit(this.extend(request, params));
1919
1936
  const result = this.safeValue(response, 'result', {});
1920
1937
  const order = this.safeValue(result, 'order');
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/kraken.js';
2
- import type { Int, OrderSide, OrderType, OHLCV, Trade, Order, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Strings, Currency, Market } from './base/types.js';
2
+ import type { IndexType, Int, OrderSide, OrderType, OHLCV, Trade, Order, Balances, Str, Transaction, Ticker, OrderBook, Tickers, Strings, Currency, Market } from './base/types.js';
3
3
  /**
4
4
  * @class kraken
5
5
  * @augments Exchange
@@ -27,7 +27,7 @@ export default class kraken extends Exchange {
27
27
  percentage: boolean;
28
28
  tierBased: boolean;
29
29
  };
30
- parseBidAsk(bidask: any, priceKey?: number, amountKey?: number): number[];
30
+ parseBidAsk(bidask: any, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): number[];
31
31
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
32
32
  parseTicker(ticker: any, market?: Market): Ticker;
33
33
  fetchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
package/js/src/kraken.js CHANGED
@@ -754,7 +754,7 @@ export default class kraken extends Exchange {
754
754
  'tierBased': true,
755
755
  };
756
756
  }
757
- parseBidAsk(bidask, priceKey = 0, amountKey = 1) {
757
+ parseBidAsk(bidask, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
758
758
  const price = this.safeNumber(bidask, priceKey);
759
759
  const amount = this.safeNumber(bidask, amountKey);
760
760
  const timestamp = this.safeInteger(bidask, 2);
package/js/src/kucoin.js CHANGED
@@ -2422,7 +2422,7 @@ export default class kucoin extends Exchange {
2422
2422
  // }
2423
2423
  // }
2424
2424
  const responseData = this.safeValue(response, 'data', {});
2425
- const orders = this.safeValue(responseData, 'items', []);
2425
+ const orders = this.safeValue(responseData, 'items', responseData);
2426
2426
  return this.parseOrders(orders, market, since, limit);
2427
2427
  }
2428
2428
  async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
package/js/src/lykke.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/lykke.js';
2
- import type { Balances, Currency, Int, Market, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
2
+ import type { IndexType, Balances, Currency, Int, Market, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction } from './base/types.js';
3
3
  /**
4
4
  * @class lykke
5
5
  * @augments Exchange
@@ -25,7 +25,7 @@ export default class lykke extends Exchange {
25
25
  fetchOpenOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
26
26
  fetchClosedOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
27
27
  fetchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
28
- parseBidAsk(bidask: any, priceKey?: number, amountKey?: number): number[];
28
+ parseBidAsk(bidask: any, priceKey?: IndexType, amountKey?: IndexType, countOrIdKey?: IndexType): number[];
29
29
  fetchDepositAddress(code: string, params?: {}): Promise<{
30
30
  currency: string;
31
31
  address: string;