ccxt 4.2.27 → 4.2.29

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 (42) hide show
  1. package/CONTRIBUTING.md +4 -1
  2. package/README.md +5 -5
  3. package/dist/ccxt.browser.js +247 -27
  4. package/dist/ccxt.browser.min.js +2 -2
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +93 -0
  7. package/dist/cjs/src/bingx.js +4 -0
  8. package/dist/cjs/src/bit2c.js +1 -0
  9. package/dist/cjs/src/bitbank.js +1 -0
  10. package/dist/cjs/src/bitbns.js +1 -0
  11. package/dist/cjs/src/bitfinex2.js +49 -1
  12. package/dist/cjs/src/bitflyer.js +1 -0
  13. package/dist/cjs/src/bitforex.js +29 -0
  14. package/dist/cjs/src/bitmex.js +5 -2
  15. package/dist/cjs/src/bybit.js +25 -9
  16. package/dist/cjs/src/coinmetro.js +10 -4
  17. package/dist/cjs/src/kucoinfutures.js +4 -0
  18. package/dist/cjs/src/okx.js +17 -4
  19. package/dist/cjs/src/pro/coinbase.js +1 -1
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/okx.d.ts +1 -0
  23. package/js/src/base/Exchange.d.ts +9 -0
  24. package/js/src/base/Exchange.js +93 -0
  25. package/js/src/bingx.d.ts +4 -0
  26. package/js/src/bingx.js +4 -0
  27. package/js/src/bit2c.js +1 -0
  28. package/js/src/bitbank.js +1 -0
  29. package/js/src/bitbns.js +1 -0
  30. package/js/src/bitfinex2.d.ts +16 -0
  31. package/js/src/bitfinex2.js +49 -1
  32. package/js/src/bitflyer.js +1 -0
  33. package/js/src/bitforex.d.ts +1 -0
  34. package/js/src/bitforex.js +29 -0
  35. package/js/src/bitmex.js +5 -2
  36. package/js/src/bybit.js +25 -9
  37. package/js/src/coinmetro.js +10 -4
  38. package/js/src/kucoinfutures.d.ts +4 -0
  39. package/js/src/kucoinfutures.js +4 -0
  40. package/js/src/okx.js +17 -4
  41. package/js/src/pro/coinbase.js +2 -2
  42. package/package.json +1 -1
package/js/src/bit2c.js CHANGED
@@ -31,6 +31,7 @@ export default class bit2c extends Exchange {
31
31
  'future': false,
32
32
  'option': false,
33
33
  'addMargin': false,
34
+ 'cancelAllOrders': false,
34
35
  'cancelOrder': true,
35
36
  'closeAllPositions': false,
36
37
  'closePosition': false,
package/js/src/bitbank.js CHANGED
@@ -29,6 +29,7 @@ export default class bitbank extends Exchange {
29
29
  'future': false,
30
30
  'option': false,
31
31
  'addMargin': false,
32
+ 'cancelAllOrders': false,
32
33
  'cancelOrder': true,
33
34
  'closeAllPositions': false,
34
35
  'closePosition': false,
package/js/src/bitbns.js CHANGED
@@ -32,6 +32,7 @@ export default class bitbns extends Exchange {
32
32
  'swap': false,
33
33
  'future': false,
34
34
  'option': undefined,
35
+ 'cancelAllOrders': false,
35
36
  'cancelOrder': true,
36
37
  'createOrder': true,
37
38
  'fetchBalance': true,
@@ -161,4 +161,20 @@ export default class bitfinex2 extends Exchange {
161
161
  parseOpenInterest(interest: any, market?: Market): OpenInterest;
162
162
  fetchLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
163
163
  parseLiquidation(liquidation: any, market?: Market): Liquidation;
164
+ setMargin(symbol: string, amount: any, params?: {}): Promise<{
165
+ info: any;
166
+ type: any;
167
+ amount: any;
168
+ code: any;
169
+ symbol: any;
170
+ status: string;
171
+ }>;
172
+ parseMarginModification(data: any, market?: any): {
173
+ info: any;
174
+ type: any;
175
+ amount: any;
176
+ code: any;
177
+ symbol: any;
178
+ status: string;
179
+ };
164
180
  }
@@ -72,6 +72,7 @@ export default class bitfinex2 extends Exchange {
72
72
  'fetchTradingFees': true,
73
73
  'fetchTransactionFees': undefined,
74
74
  'fetchTransactions': 'emulated',
75
+ 'setMargin': true,
75
76
  'withdraw': true,
76
77
  },
77
78
  'timeframes': {
@@ -822,6 +823,11 @@ export default class bitfinex2 extends Exchange {
822
823
  const result = { 'info': response };
823
824
  for (let i = 0; i < response.length; i++) {
824
825
  const balance = response[i];
826
+ const account = this.account();
827
+ const interest = this.safeString(balance, 3);
828
+ if (interest !== '0') {
829
+ account['debt'] = interest;
830
+ }
825
831
  const type = this.safeString(balance, 0);
826
832
  const currencyId = this.safeStringLower(balance, 1, '');
827
833
  const start = currencyId.length - 2;
@@ -830,7 +836,6 @@ export default class bitfinex2 extends Exchange {
830
836
  const derivativeCondition = (!isDerivative || isDerivativeCode);
831
837
  if ((accountType === type) && derivativeCondition) {
832
838
  const code = this.safeCurrencyCode(currencyId);
833
- const account = this.account();
834
839
  account['total'] = this.safeString(balance, 2);
835
840
  account['free'] = this.safeString(balance, 4);
836
841
  result[code] = account;
@@ -3265,4 +3270,47 @@ export default class bitfinex2 extends Exchange {
3265
3270
  'datetime': this.iso8601(timestamp),
3266
3271
  });
3267
3272
  }
3273
+ async setMargin(symbol, amount, params = {}) {
3274
+ /**
3275
+ * @method
3276
+ * @name bitfinex2#setMargin
3277
+ * @description either adds or reduces margin in a swap position in order to set the margin to a specific value
3278
+ * @see https://docs.bitfinex.com/reference/rest-auth-deriv-pos-collateral-set
3279
+ * @param {string} symbol unified market symbol of the market to set margin in
3280
+ * @param {float} amount the amount to set the margin to
3281
+ * @param {object} [params] parameters specific to the exchange API endpoint
3282
+ * @returns {object} A [margin structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#add-margin-structure}
3283
+ */
3284
+ await this.loadMarkets();
3285
+ const market = this.market(symbol);
3286
+ if (!market['swap']) {
3287
+ throw new NotSupported(this.id + ' setMargin() only support swap markets');
3288
+ }
3289
+ const request = {
3290
+ 'symbol': market['id'],
3291
+ 'collateral': this.parseToNumeric(amount),
3292
+ };
3293
+ const response = await this.privatePostAuthWDerivCollateralSet(this.extend(request, params));
3294
+ //
3295
+ // [
3296
+ // [
3297
+ // 1
3298
+ // ]
3299
+ // ]
3300
+ //
3301
+ const data = this.safeValue(response, 0);
3302
+ return this.parseMarginModification(data, market);
3303
+ }
3304
+ parseMarginModification(data, market = undefined) {
3305
+ const marginStatusRaw = data[0];
3306
+ const marginStatus = (marginStatusRaw === 1) ? 'ok' : 'failed';
3307
+ return {
3308
+ 'info': data,
3309
+ 'type': undefined,
3310
+ 'amount': undefined,
3311
+ 'code': undefined,
3312
+ 'symbol': market['symbol'],
3313
+ 'status': marginStatus,
3314
+ };
3315
+ }
3268
3316
  }
@@ -31,6 +31,7 @@ export default class bitflyer extends Exchange {
31
31
  'swap': undefined,
32
32
  'future': undefined,
33
33
  'option': false,
34
+ 'cancelAllOrders': undefined,
34
35
  'cancelOrder': true,
35
36
  'createOrder': true,
36
37
  'fetchBalance': true,
@@ -20,6 +20,7 @@ export default class bitforex extends Exchange {
20
20
  parseOrderStatus(status: any): any;
21
21
  parseSide(sideId: any): "buy" | "sell";
22
22
  parseOrder(order: any, market?: Market): Order;
23
+ cancelAllOrders(symbol?: Str, params?: {}): Promise<any>;
23
24
  fetchOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;
24
25
  fetchOpenOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
25
26
  fetchClosedOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
@@ -30,6 +30,7 @@ export default class bitforex extends Exchange {
30
30
  'future': false,
31
31
  'option': false,
32
32
  'addMargin': false,
33
+ 'cancelAllOrders': true,
33
34
  'cancelOrder': true,
34
35
  'createOrder': true,
35
36
  'createReduceOnlyOrder': false,
@@ -683,6 +684,34 @@ export default class bitforex extends Exchange {
683
684
  'trades': undefined,
684
685
  }, market);
685
686
  }
687
+ async cancelAllOrders(symbol = undefined, params = {}) {
688
+ /**
689
+ * @method
690
+ * @name bitforex#cancelAllOrders
691
+ * @see https://github.com/githubdev2020/API_Doc_en/wiki/Cancle-all-orders
692
+ * @description cancel all open orders in a market
693
+ * @param {string} symbol unified market symbol of the market to cancel orders in
694
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
695
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
696
+ */
697
+ if (symbol === undefined) {
698
+ throw new ArgumentsRequired(this.id + ' cancelAllOrders () requires a symbol argument');
699
+ }
700
+ await this.loadMarkets();
701
+ const market = this.market(symbol);
702
+ const request = {
703
+ 'symbol': market['id'],
704
+ };
705
+ const response = await this.privatePostApiV1TradeCancelAllOrder(this.extend(request, params));
706
+ //
707
+ // {
708
+ // 'data': True,
709
+ // 'success': True,
710
+ // 'time': '1706542995252'
711
+ // }
712
+ //
713
+ return response;
714
+ }
686
715
  async fetchOrder(id, symbol = undefined, params = {}) {
687
716
  /**
688
717
  * @method
package/js/src/bitmex.js CHANGED
@@ -104,7 +104,7 @@ export default class bitmex extends Exchange {
104
104
  'public': 'https://testnet.bitmex.com',
105
105
  'private': 'https://testnet.bitmex.com',
106
106
  },
107
- 'logo': 'https://user-images.githubusercontent.com/1294454/27766319-f653c6e6-5ed4-11e7-933d-f0bc3699ae8f.jpg',
107
+ 'logo': 'https://github.com/ccxt/ccxt/assets/43336371/cea9cfe5-c57e-4b84-b2ac-77b960b04445',
108
108
  'api': {
109
109
  'public': 'https://www.bitmex.com',
110
110
  'private': 'https://www.bitmex.com',
@@ -115,7 +115,10 @@ export default class bitmex extends Exchange {
115
115
  'https://github.com/BitMEX/api-connectors/tree/master/official-http',
116
116
  ],
117
117
  'fees': 'https://www.bitmex.com/app/fees',
118
- 'referral': 'https://www.bitmex.com/register/upZpOX',
118
+ 'referral': {
119
+ 'url': 'https://www.bitmex.com/app/register/NZTR1q',
120
+ 'discount': 0.1,
121
+ },
119
122
  },
120
123
  'api': {
121
124
  'public': {
package/js/src/bybit.js CHANGED
@@ -857,6 +857,7 @@ export default class bybit extends Exchange {
857
857
  '181003': InvalidOrder,
858
858
  '181004': InvalidOrder,
859
859
  '182000': InvalidOrder,
860
+ '181017': BadRequest,
860
861
  '20001': OrderNotFound,
861
862
  '20003': InvalidOrder,
862
863
  '20004': InvalidOrder,
@@ -3349,16 +3350,31 @@ export default class bybit extends Exchange {
3349
3350
  let fee = undefined;
3350
3351
  const feeCostString = this.safeString(order, 'cumExecFee');
3351
3352
  if (feeCostString !== undefined) {
3352
- let feeCurrency = undefined;
3353
+ let feeCurrencyCode = undefined;
3353
3354
  if (market['spot']) {
3354
- feeCurrency = (side === 'buy') ? market['quote'] : market['base'];
3355
+ if (Precise.stringGt(feeCostString, '0')) {
3356
+ if (side === 'buy') {
3357
+ feeCurrencyCode = market['base'];
3358
+ }
3359
+ else {
3360
+ feeCurrencyCode = market['quote'];
3361
+ }
3362
+ }
3363
+ else {
3364
+ if (side === 'buy') {
3365
+ feeCurrencyCode = market['quote'];
3366
+ }
3367
+ else {
3368
+ feeCurrencyCode = market['base'];
3369
+ }
3370
+ }
3355
3371
  }
3356
3372
  else {
3357
- feeCurrency = market['settle'];
3373
+ feeCurrencyCode = market['inverse'] ? market['base'] : market['settle'];
3358
3374
  }
3359
3375
  fee = {
3360
3376
  'cost': feeCostString,
3361
- 'currency': feeCurrency,
3377
+ 'currency': feeCurrencyCode,
3362
3378
  };
3363
3379
  }
3364
3380
  let clientOrderId = this.safeString(order, 'orderLinkId');
@@ -4518,7 +4534,7 @@ export default class bybit extends Exchange {
4518
4534
  return await this.fetchUsdcOrders(symbol, since, limit, params);
4519
4535
  }
4520
4536
  request['category'] = type;
4521
- const isStop = this.safeValueN(params, ['trigger', 'stop'], false);
4537
+ const isStop = this.safeBoolN(params, ['trigger', 'stop'], false);
4522
4538
  params = this.omit(params, ['trigger', 'stop']);
4523
4539
  if (isStop) {
4524
4540
  request['orderFilter'] = 'StopOrder';
@@ -5676,10 +5692,10 @@ export default class bybit extends Exchange {
5676
5692
  // "time": 1672280219169
5677
5693
  // }
5678
5694
  //
5679
- const result = this.safeValue(response, 'result', {});
5680
- const positions = this.safeValue2(result, 'list', 'dataList', []);
5695
+ const result = this.safeDict(response, 'result', {});
5696
+ const positions = this.safeList2(result, 'list', 'dataList', []);
5681
5697
  const timestamp = this.safeInteger(response, 'time');
5682
- const first = this.safeValue(positions, 0, {});
5698
+ const first = this.safeDict(positions, 0, {});
5683
5699
  const position = this.parsePosition(first, market);
5684
5700
  position['timestamp'] = timestamp;
5685
5701
  position['datetime'] = this.iso8601(timestamp);
@@ -6425,7 +6441,7 @@ export default class bybit extends Exchange {
6425
6441
  throw new BadRequest(this.id + 'fetchOpenInterestHistory cannot use the 1m timeframe');
6426
6442
  }
6427
6443
  await this.loadMarkets();
6428
- const paginate = this.safeValue(params, 'paginate');
6444
+ const paginate = this.safeBool(params, 'paginate');
6429
6445
  if (paginate) {
6430
6446
  params = this.omit(params, 'paginate');
6431
6447
  return await this.fetchPaginatedCallDeterministic('fetchOpenInterestHistory', symbol, since, limit, timeframe, params, 500);
@@ -138,7 +138,7 @@ export default class coinmetro extends Exchange {
138
138
  'private': 'https://api.coinmetro.com',
139
139
  },
140
140
  'test': {
141
- 'public': 'https://api.coinmetro.com',
141
+ 'public': 'https://api.coinmetro.com/open',
142
142
  'private': 'https://api.coinmetro.com/open',
143
143
  },
144
144
  'www': 'https://coinmetro.com/',
@@ -1857,11 +1857,17 @@ export default class coinmetro extends Exchange {
1857
1857
  const endpoint = '/' + this.implodeParams(path, params);
1858
1858
  let url = this.urls['api'][api] + endpoint;
1859
1859
  const query = this.urlencode(request);
1860
+ if (headers === undefined) {
1861
+ headers = {};
1862
+ }
1863
+ headers['CCXT'] = 'true';
1860
1864
  if (api === 'private') {
1861
- if (headers === undefined) {
1862
- headers = {};
1865
+ if ((this.uid === undefined) && (this.apiKey !== undefined)) {
1866
+ this.uid = this.apiKey;
1867
+ }
1868
+ if ((this.token === undefined) && (this.secret !== undefined)) {
1869
+ this.token = this.secret;
1863
1870
  }
1864
- headers['CCXT'] = true;
1865
1871
  if (url === 'https://api.coinmetro.com/jwt') { // handle with headers for login endpoint
1866
1872
  headers['X-Device-Id'] = 'bypass';
1867
1873
  if (this.twofa !== undefined) {
@@ -1,5 +1,9 @@
1
1
  import kucoin from './abstract/kucoinfutures.js';
2
2
  import type { Int, OrderSide, OrderType, OHLCV, Order, Trade, FundingHistory, Balances, Str, Ticker, OrderBook, Transaction, Strings, Market, Currency, OrderRequest } from './base/types.js';
3
+ /**
4
+ * @class kucoinfutures
5
+ * @augments Exchange
6
+ */
3
7
  export default class kucoinfutures extends kucoin {
4
8
  describe(): any;
5
9
  fetchStatus(params?: {}): Promise<{
@@ -10,6 +10,10 @@ import { Precise } from './base/Precise.js';
10
10
  import { TICK_SIZE } from './base/functions/number.js';
11
11
  import kucoin from './abstract/kucoinfutures.js';
12
12
  // ---------------------------------------------------------------------------
13
+ /**
14
+ * @class kucoinfutures
15
+ * @augments Exchange
16
+ */
13
17
  export default class kucoinfutures extends kucoin {
14
18
  describe() {
15
19
  return this.deepExtend(super.describe(), {
package/js/src/okx.js CHANGED
@@ -175,6 +175,7 @@ export default class okx extends Exchange {
175
175
  'api': {
176
176
  'public': {
177
177
  'get': {
178
+ 'market/books-full': 2,
178
179
  'market/tickers': 1,
179
180
  'market/ticker': 1,
180
181
  'market/index-tickers': 1,
@@ -1673,6 +1674,7 @@ export default class okx extends Exchange {
1673
1674
  * @param {string} symbol unified symbol of the market to fetch the order book for
1674
1675
  * @param {int} [limit] the maximum amount of order book entries to return
1675
1676
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1677
+ * @param {string} [params.method] 'publicGetMarketBooksFull' or 'publicGetMarketBooks' default is 'publicGetMarketBooks'
1676
1678
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1677
1679
  */
1678
1680
  await this.loadMarkets();
@@ -1680,11 +1682,22 @@ export default class okx extends Exchange {
1680
1682
  const request = {
1681
1683
  'instId': market['id'],
1682
1684
  };
1683
- limit = (limit === undefined) ? 20 : limit;
1685
+ let method = undefined;
1686
+ [method, params] = this.handleOptionAndParams(params, 'fetchOrderBook', 'method', 'publicGetMarketBooks');
1687
+ if (method === 'publicGetMarketBooksFull' && limit === undefined) {
1688
+ limit = 5000;
1689
+ }
1690
+ limit = (limit === undefined) ? 100 : limit;
1684
1691
  if (limit !== undefined) {
1685
1692
  request['sz'] = limit; // max 400
1686
1693
  }
1687
- const response = await this.publicGetMarketBooks(this.extend(request, params));
1694
+ let response = undefined;
1695
+ if ((method === 'publicGetMarketBooksFull') || (limit > 400)) {
1696
+ response = await this.publicGetMarketBooksFull(this.extend(request, params));
1697
+ }
1698
+ else {
1699
+ response = await this.publicGetMarketBooks(this.extend(request, params));
1700
+ }
1688
1701
  //
1689
1702
  // {
1690
1703
  // "code": "0",
@@ -1738,7 +1751,7 @@ export default class okx extends Exchange {
1738
1751
  const symbol = market['symbol'];
1739
1752
  const last = this.safeString(ticker, 'last');
1740
1753
  const open = this.safeString(ticker, 'open24h');
1741
- const spot = this.safeValue(market, 'spot', false);
1754
+ const spot = this.safeBool(market, 'spot', false);
1742
1755
  const quoteVolume = spot ? this.safeString(ticker, 'volCcy24h') : undefined;
1743
1756
  const baseVolume = this.safeString(ticker, 'vol24h');
1744
1757
  const high = this.safeString(ticker, 'high24h');
@@ -2594,7 +2607,7 @@ export default class okx extends Exchange {
2594
2607
  }
2595
2608
  else {
2596
2609
  marginMode = defaultMarginMode;
2597
- margin = this.safeValue(params, 'margin', false);
2610
+ margin = this.safeBool(params, 'margin', false);
2598
2611
  }
2599
2612
  if (spot) {
2600
2613
  if (margin) {
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import coinbaseRest from '../coinbase.js';
9
- import { ArgumentsRequired, ExchangeError } from '../base/errors.js';
9
+ import { ExchangeError } from '../base/errors.js';
10
10
  import { ArrayCacheBySymbolById } from '../base/ws/Cache.js';
11
11
  import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
12
12
  // ---------------------------------------------------------------------------
@@ -113,7 +113,7 @@ export default class coinbase extends coinbaseRest {
113
113
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
114
114
  */
115
115
  if (symbols === undefined) {
116
- throw new ArgumentsRequired(this.id + ' watchTickers requires a symbols argument');
116
+ symbols = this.symbols;
117
117
  }
118
118
  const name = 'ticker_batch';
119
119
  const tickers = await this.subscribe(name, symbols, params);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.27",
3
+ "version": "4.2.29",
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",