ccxt 4.2.56 → 4.2.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/src/mexc.d.ts CHANGED
@@ -172,6 +172,18 @@ export default class mexc extends Exchange {
172
172
  parseTransactionFee(transaction: any, currency?: Currency): {};
173
173
  fetchDepositWithdrawFees(codes?: Strings, params?: {}): Promise<any>;
174
174
  parseDepositWithdrawFee(fee: any, currency?: Currency): any;
175
+ fetchLeverage(symbol: string, params?: {}): Promise<{
176
+ info: any;
177
+ symbol: string;
178
+ leverage: number;
179
+ marginMode: any;
180
+ }>;
181
+ parseLeverage(leverage: any, market?: Market): {
182
+ info: any;
183
+ symbol: string;
184
+ leverage: number;
185
+ marginMode: any;
186
+ };
175
187
  handleMarginModeAndParams(methodName: any, params?: {}, defaultValue?: any): any[];
176
188
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
177
189
  url: any;
package/js/src/mexc.js CHANGED
@@ -74,6 +74,8 @@ export default class mexc extends Exchange {
74
74
  'fetchL2OrderBook': true,
75
75
  'fetchLedger': undefined,
76
76
  'fetchLedgerEntry': undefined,
77
+ 'fetchLeverage': true,
78
+ 'fetchLeverages': false,
77
79
  'fetchLeverageTiers': true,
78
80
  'fetchMarginMode': false,
79
81
  'fetchMarketLeverageTiers': undefined,
@@ -5377,6 +5379,79 @@ export default class mexc extends Exchange {
5377
5379
  }
5378
5380
  return this.assignDefaultDepositWithdrawFees(result);
5379
5381
  }
5382
+ async fetchLeverage(symbol, params = {}) {
5383
+ /**
5384
+ * @method
5385
+ * @name mexc#fetchLeverage
5386
+ * @description fetch the set leverage for a market
5387
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-leverage
5388
+ * @param {string} symbol unified market symbol
5389
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5390
+ * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
5391
+ */
5392
+ await this.loadMarkets();
5393
+ const market = this.market(symbol);
5394
+ const request = {
5395
+ 'symbol': market['id'],
5396
+ };
5397
+ const response = await this.contractPrivateGetPositionLeverage(this.extend(request, params));
5398
+ //
5399
+ // {
5400
+ // "success": true,
5401
+ // "code": 0,
5402
+ // "data": [
5403
+ // {
5404
+ // "level": 1,
5405
+ // "maxVol": 463300,
5406
+ // "mmr": 0.004,
5407
+ // "imr": 0.005,
5408
+ // "positionType": 1,
5409
+ // "openType": 1,
5410
+ // "leverage": 20,
5411
+ // "limitBySys": false,
5412
+ // "currentMmr": 0.004
5413
+ // },
5414
+ // {
5415
+ // "level": 1,
5416
+ // "maxVol": 463300,
5417
+ // "mmr": 0.004,
5418
+ // "imr": 0.005,
5419
+ // "positionType": 2,
5420
+ // "openType": 1,
5421
+ // "leverage": 20,
5422
+ // "limitBySys": false,
5423
+ // "currentMmr": 0.004
5424
+ // }
5425
+ // ]
5426
+ // }
5427
+ //
5428
+ const data = this.safeList(response, 'data', []);
5429
+ const longLeverage = this.safeDict(data, 0);
5430
+ return this.parseLeverage(longLeverage, market);
5431
+ }
5432
+ parseLeverage(leverage, market = undefined) {
5433
+ //
5434
+ // {
5435
+ // "level": 1,
5436
+ // "maxVol": 463300,
5437
+ // "mmr": 0.004,
5438
+ // "imr": 0.005,
5439
+ // "positionType": 1,
5440
+ // "openType": 1,
5441
+ // "leverage": 20,
5442
+ // "limitBySys": false,
5443
+ // "currentMmr": 0.004
5444
+ // }
5445
+ //
5446
+ const marketId = this.safeString(leverage, 'symbol');
5447
+ market = this.safeMarket(marketId, market, undefined, 'contract');
5448
+ return {
5449
+ 'info': leverage,
5450
+ 'symbol': market['symbol'],
5451
+ 'leverage': this.safeInteger(leverage, 'leverage'),
5452
+ 'marginMode': undefined,
5453
+ };
5454
+ }
5380
5455
  handleMarginModeAndParams(methodName, params = {}, defaultValue = undefined) {
5381
5456
  /**
5382
5457
  * @ignore
@@ -63,17 +63,9 @@ export default class bitmex extends bitmexRest {
63
63
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
64
64
  */
65
65
  await this.loadMarkets();
66
- const market = this.market(symbol);
67
- const name = 'instrument';
68
- const messageHash = name + ':' + market['id'];
69
- const url = this.urls['api']['ws'];
70
- const request = {
71
- 'op': 'subscribe',
72
- 'args': [
73
- messageHash,
74
- ],
75
- };
76
- return await this.watch(url, messageHash, this.extend(request, params), messageHash);
66
+ symbol = this.symbol(symbol);
67
+ const tickers = await this.watchTickers([symbol], params);
68
+ return tickers[symbol];
77
69
  }
78
70
  async watchTickers(symbols = undefined, params = {}) {
79
71
  /**
@@ -89,26 +81,27 @@ export default class bitmex extends bitmexRest {
89
81
  const name = 'instrument';
90
82
  const url = this.urls['api']['ws'];
91
83
  const messageHashes = [];
84
+ const rawSubscriptions = [];
92
85
  if (symbols !== undefined) {
93
86
  for (let i = 0; i < symbols.length; i++) {
94
87
  const symbol = symbols[i];
95
88
  const market = this.market(symbol);
96
- const hash = name + ':' + market['id'];
97
- messageHashes.push(hash);
89
+ const subscription = name + ':' + market['id'];
90
+ rawSubscriptions.push(subscription);
91
+ const messageHash = 'ticker:' + symbol;
92
+ messageHashes.push(messageHash);
98
93
  }
99
94
  }
100
95
  else {
101
- messageHashes.push(name);
96
+ rawSubscriptions.push(name);
97
+ messageHashes.push('alltickers');
102
98
  }
103
99
  const request = {
104
100
  'op': 'subscribe',
105
- 'args': messageHashes,
101
+ 'args': rawSubscriptions,
106
102
  };
107
- const ticker = await this.watchMultiple(url, messageHashes, this.extend(request, params), messageHashes);
103
+ const ticker = await this.watchMultiple(url, messageHashes, this.extend(request, params), rawSubscriptions);
108
104
  if (this.newUpdates) {
109
- if (symbols === undefined) {
110
- return ticker;
111
- }
112
105
  const result = {};
113
106
  result[ticker['symbol']] = ticker;
114
107
  return result;
@@ -342,23 +335,23 @@ export default class bitmex extends bitmexRest {
342
335
  // ]
343
336
  // }
344
337
  //
345
- const table = this.safeString(message, 'table');
346
338
  const data = this.safeList(message, 'data', []);
347
339
  const tickers = {};
348
340
  for (let i = 0; i < data.length; i++) {
349
341
  const update = data[i];
350
342
  const marketId = this.safeString(update, 'symbol');
351
- const market = this.safeMarket(marketId);
352
- const symbol = market['symbol'];
353
- const messageHash = table + ':' + marketId;
354
- const ticker = this.safeDict(this.tickers, symbol, {});
355
- const info = this.safeDict(ticker, 'info', {});
356
- const parsedTicker = this.parseTicker(this.extend(info, update), market);
357
- tickers[symbol] = parsedTicker;
358
- this.tickers[symbol] = parsedTicker;
359
- client.resolve(ticker, messageHash);
343
+ const symbol = this.safeSymbol(marketId);
344
+ if (!(symbol in this.tickers)) {
345
+ this.tickers[symbol] = this.parseTicker({});
346
+ }
347
+ const updatedTicker = this.parseTicker(update);
348
+ const fullParsedTicker = this.deepExtend(this.tickers[symbol], updatedTicker);
349
+ tickers[symbol] = fullParsedTicker;
350
+ this.tickers[symbol] = fullParsedTicker;
351
+ const messageHash = 'ticker:' + symbol;
352
+ client.resolve(fullParsedTicker, messageHash);
353
+ client.resolve(fullParsedTicker, 'alltickers');
360
354
  }
361
- client.resolve(tickers, 'instrument');
362
355
  return message;
363
356
  }
364
357
  async watchBalance(params = {}) {
@@ -1338,7 +1331,7 @@ export default class bitmex extends bitmexRest {
1338
1331
  const messageHash = table + ':' + market['id'];
1339
1332
  const result = [
1340
1333
  this.parse8601(this.safeString(candle, 'timestamp')) - duration * 1000,
1341
- this.safeFloat(candle, 'open'),
1334
+ undefined,
1342
1335
  this.safeFloat(candle, 'high'),
1343
1336
  this.safeFloat(candle, 'low'),
1344
1337
  this.safeFloat(candle, 'close'),
package/js/src/pro/cex.js CHANGED
@@ -1091,7 +1091,10 @@ export default class cex extends cexRest {
1091
1091
  for (let i = 0; i < sorted.length; i++) {
1092
1092
  stored.append(this.parseOHLCV(sorted[i], market));
1093
1093
  }
1094
- this.ohlcvs[symbol] = stored;
1094
+ if (!(symbol in this.ohlcvs)) {
1095
+ this.ohlcvs[symbol] = {};
1096
+ }
1097
+ this.ohlcvs[symbol]['unknown'] = stored;
1095
1098
  client.resolve(stored, messageHash);
1096
1099
  }
1097
1100
  handleOHLCV24(client, message) {
@@ -1150,7 +1153,8 @@ export default class cex extends cexRest {
1150
1153
  const pair = this.safeString(message, 'pair');
1151
1154
  const symbol = this.pairToSymbol(pair);
1152
1155
  const messageHash = 'ohlcv:' + symbol;
1153
- const stored = this.safeValue(this.ohlcvs, symbol);
1156
+ // const stored = this.safeValue (this.ohlcvs, symbol);
1157
+ const stored = this.ohlcvs[symbol]['unknown'];
1154
1158
  for (let i = 0; i < data.length; i++) {
1155
1159
  const ohlcv = [
1156
1160
  this.safeTimestamp(data[i], 0),
@@ -390,14 +390,17 @@ export default class coinex extends coinexRest {
390
390
  const keys = Object.keys(this.ohlcvs);
391
391
  const keysLength = keys.length;
392
392
  if (keysLength === 0) {
393
+ this.ohlcvs['unknown'] = {};
393
394
  const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
394
- this.ohlcvs = new ArrayCacheByTimestamp(limit);
395
+ const stored = new ArrayCacheByTimestamp(limit);
396
+ this.ohlcvs['unknown']['unknown'] = stored;
395
397
  }
398
+ const ohlcv = this.ohlcvs['unknown']['unknown'];
396
399
  for (let i = 0; i < ohlcvs.length; i++) {
397
400
  const candle = ohlcvs[i];
398
- this.ohlcvs.append(candle);
401
+ ohlcv.append(candle);
399
402
  }
400
- client.resolve(this.ohlcvs, messageHash);
403
+ client.resolve(ohlcv, messageHash);
401
404
  }
402
405
  async watchTicker(symbol, params = {}) {
403
406
  /**
@@ -247,7 +247,7 @@ export default class mexc extends mexcRest {
247
247
  // "d": {
248
248
  // "e": "spot@public.kline.v3.api",
249
249
  // "k": {
250
- // "t": 1678642260,
250
+ // "t": 1678642261,
251
251
  // "o": 20626.94,
252
252
  // "c": 20599.69,
253
253
  // "h": 20626.94,
@@ -460,7 +460,7 @@ export default class mexc extends mexcRest {
460
460
  client.subscriptions[messageHash] = 1;
461
461
  this.orderbooks[symbol] = this.countedOrderBook({});
462
462
  }
463
- const storedOrderBook = this.safeValue(this.orderbooks, symbol);
463
+ const storedOrderBook = this.orderbooks[symbol];
464
464
  const nonce = this.safeInteger(storedOrderBook, 'nonce');
465
465
  if (nonce === undefined) {
466
466
  const cacheLength = storedOrderBook.cache.length;
@@ -117,15 +117,19 @@ export default class whitebit extends whitebitRest {
117
117
  const symbol = market['symbol'];
118
118
  const messageHash = 'candles' + ':' + symbol;
119
119
  const parsed = this.parseOHLCV(data, market);
120
- this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol);
121
- let stored = this.ohlcvs[symbol];
122
- if (stored === undefined) {
120
+ // this.ohlcvs[symbol] = this.safeValue (this.ohlcvs, symbol);
121
+ if (!(symbol in this.ohlcvs)) {
122
+ this.ohlcvs[symbol] = {};
123
+ }
124
+ // let stored = this.ohlcvs[symbol]['unknown']; // we don't know the timeframe but we need to respect the type
125
+ if (!('unknown' in this.ohlcvs[symbol])) {
123
126
  const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
124
- stored = new ArrayCacheByTimestamp(limit);
125
- this.ohlcvs[symbol] = stored;
127
+ const stored = new ArrayCacheByTimestamp(limit);
128
+ this.ohlcvs[symbol]['unknown'] = stored;
126
129
  }
127
- stored.append(parsed);
128
- client.resolve(stored, messageHash);
130
+ const ohlcv = this.ohlcvs[symbol]['unknown'];
131
+ ohlcv.append(parsed);
132
+ client.resolve(ohlcv, messageHash);
129
133
  }
130
134
  return message;
131
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.56",
3
+ "version": "4.2.57",
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",
package/skip-tests.json CHANGED
@@ -220,10 +220,18 @@
220
220
  "deposit": "not provided"
221
221
  },
222
222
  "fetchTickers": {
223
- "open": "https://app.travis-ci.com/github/ccxt/ccxt/builds/269177570#L3624"
223
+ "open": "https://app.travis-ci.com/github/ccxt/ccxt/builds/269177570#L3624",
224
+ "bid": "https://app.travis-ci.com/github/ccxt/ccxt/builds/269219719#L3210",
225
+ "ask": "same",
226
+ "bidVolume": "same",
227
+ "askVolume": "same"
224
228
  },
225
229
  "watchTickers": {
226
- "open": "same"
230
+ "open": "same",
231
+ "bid": "same",
232
+ "ask": "same",
233
+ "bidVolume": "same",
234
+ "askVolume": "same"
227
235
  },
228
236
  "fetchOrderBook": {
229
237
  "bid": "multiple bids might have same value"
@@ -333,10 +341,14 @@
333
341
  }
334
342
  },
335
343
  "bitmex": {
336
- "skipWs": "timeouts",
337
344
  "skipMethods": {
338
345
  "loadMarkets": "some market types are out of expected market-types",
339
- "fetchOHLCV": "open might be greater than high",
346
+ "fetchOHLCV": {
347
+ "1": "open value is greater than high: https://github.com/ccxt/ccxt/pull/21356#issuecomment-1969565862"
348
+ },
349
+ "watchOHLCV": {
350
+ "1": "same as above"
351
+ },
340
352
  "fetchTickers": "negative values",
341
353
  "fetchPositions": {
342
354
  "stopLossPrice": "undefined",
@@ -375,7 +387,8 @@
375
387
  "currency": "undefined",
376
388
  "currencyIdAndCode": "messes codes"
377
389
  },
378
- "fetchTransactions": "skip"
390
+ "fetchTransactions": "skip",
391
+ "watchTrades": "infrequent updates"
379
392
  }
380
393
  },
381
394
  "bitopro": {
@@ -782,7 +795,8 @@
782
795
  }
783
796
  },
784
797
  "delta": {
785
- "httpsProxy": "http://5.75.153.75:8002",
798
+ "skip": "frequent timeouts https://app.travis-ci.com/github/ccxt/ccxt/builds/269219719#L3723",
799
+ "until": "2024-03-05",
786
800
  "skipMethods": {
787
801
  "loadMarkets": "expiryDatetime must be equal to expiry in iso8601 format",
788
802
  "fetchOrderBook": "ask crossing bids test failing",
@@ -1190,7 +1204,6 @@
1190
1204
  }
1191
1205
  },
1192
1206
  "mexc": {
1193
- "skipWs": "temp",
1194
1207
  "skipMethods": {
1195
1208
  "loadMarkets":{
1196
1209
  "currencyIdAndCode": "messed"