ccxt 4.3.19 → 4.3.20

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/README.md CHANGED
@@ -215,13 +215,13 @@ console.log(version, Object.keys(exchanges));
215
215
 
216
216
  All-in-one browser bundle (dependencies included), served from a CDN of your choice:
217
217
 
218
- * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.3.19/dist/ccxt.browser.js
219
- * unpkg: https://unpkg.com/ccxt@4.3.19/dist/ccxt.browser.js
218
+ * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.3.20/dist/ccxt.browser.js
219
+ * unpkg: https://unpkg.com/ccxt@4.3.20/dist/ccxt.browser.js
220
220
 
221
221
  CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.
222
222
 
223
223
  ```HTML
224
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.3.19/dist/ccxt.browser.js"></script>
224
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.3.20/dist/ccxt.browser.js"></script>
225
225
  ```
226
226
 
227
227
  Creates a global `ccxt` object:
package/dist/cjs/ccxt.js CHANGED
@@ -184,7 +184,7 @@ var woofipro$1 = require('./src/pro/woofipro.js');
184
184
 
185
185
  //-----------------------------------------------------------------------------
186
186
  // this is updated by vss.js when building
187
- const version = '4.3.19';
187
+ const version = '4.3.20';
188
188
  Exchange["default"].ccxtVersion = version;
189
189
  const exchanges = {
190
190
  'ace': ace,
@@ -5948,6 +5948,9 @@ class Exchange {
5948
5948
  if (method === 'fetchAccounts') {
5949
5949
  response = await this[method](params);
5950
5950
  }
5951
+ else if (method === 'getLeverageTiersPaginated') {
5952
+ response = await this[method](symbol, params);
5953
+ }
5951
5954
  else {
5952
5955
  response = await this[method](symbol, since, maxEntriesPerRequest, params);
5953
5956
  }
@@ -310,6 +310,9 @@ class bitget extends bitget$1 {
310
310
  'v2/spot/account/subaccount-assets': 2,
311
311
  'v2/spot/account/bills': 2,
312
312
  'v2/spot/account/transferRecords': 1,
313
+ 'v2/account/funding-assets': 2,
314
+ 'v2/account/bot-assets': 2,
315
+ 'v2/account/all-account-balance': 20,
313
316
  'v2/spot/wallet/deposit-address': 2,
314
317
  'v2/spot/wallet/deposit-records': 2,
315
318
  'v2/spot/wallet/withdrawal-records': 2,
@@ -8148,6 +8148,35 @@ class bybit extends bybit$1 {
8148
8148
  'datetime': this.iso8601(timestamp),
8149
8149
  });
8150
8150
  }
8151
+ async getLeverageTiersPaginated(symbol = undefined, params = {}) {
8152
+ await this.loadMarkets();
8153
+ let market = undefined;
8154
+ if (symbol !== undefined) {
8155
+ market = this.market(symbol);
8156
+ }
8157
+ let paginate = false;
8158
+ [paginate, params] = this.handleOptionAndParams(params, 'getLeverageTiersPaginated', 'paginate');
8159
+ if (paginate) {
8160
+ return await this.fetchPaginatedCallCursor('getLeverageTiersPaginated', symbol, undefined, undefined, params, 'nextPageCursor', 'cursor', undefined, 100);
8161
+ }
8162
+ let subType = undefined;
8163
+ [subType, params] = this.handleSubTypeAndParams('getLeverageTiersPaginated', market, params, 'linear');
8164
+ const request = {
8165
+ 'category': subType,
8166
+ };
8167
+ const response = await this.publicGetV5MarketRiskLimit(this.extend(request, params));
8168
+ const result = this.addPaginationCursorToResult(response);
8169
+ const first = this.safeDict(result, 0);
8170
+ const total = result.length;
8171
+ const lastIndex = total - 1;
8172
+ const last = this.safeDict(result, lastIndex);
8173
+ const cursorValue = this.safeString(first, 'nextPageCursor');
8174
+ last['info'] = {
8175
+ 'nextPageCursor': cursorValue,
8176
+ };
8177
+ result[lastIndex] = last;
8178
+ return result;
8179
+ }
8151
8180
  async fetchLeverageTiers(symbols = undefined, params = {}) {
8152
8181
  /**
8153
8182
  * @method
@@ -8157,24 +8186,20 @@ class bybit extends bybit$1 {
8157
8186
  * @param {string[]} [symbols] a list of unified market symbols
8158
8187
  * @param {object} [params] extra parameters specific to the exchange API endpoint
8159
8188
  * @param {string} [params.subType] market subType, ['linear', 'inverse'], default is 'linear'
8189
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
8160
8190
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
8161
8191
  */
8162
8192
  await this.loadMarkets();
8163
8193
  let market = undefined;
8194
+ let symbol = undefined;
8164
8195
  if (symbols !== undefined) {
8165
8196
  market = this.market(symbols[0]);
8166
8197
  if (market['spot']) {
8167
8198
  throw new errors.NotSupported(this.id + ' fetchLeverageTiers() is not supported for spot market');
8168
8199
  }
8200
+ symbol = market['symbol'];
8169
8201
  }
8170
- let subType = undefined;
8171
- [subType, params] = this.handleSubTypeAndParams('fetchTickers', market, params, 'linear');
8172
- const request = {
8173
- 'category': subType,
8174
- };
8175
- const response = await this.publicGetV5MarketRiskLimit(this.extend(request, params));
8176
- const result = this.safeDict(response, 'result', {});
8177
- const data = this.safeList(result, 'list', []);
8202
+ const data = await this.getLeverageTiersPaginated(symbol, this.extend({ 'paginate': true, 'paginationCalls': 20 }, params));
8178
8203
  symbols = this.marketSymbols(symbols);
8179
8204
  return this.parseLeverageTiers(data, symbols, 'symbol');
8180
8205
  }
@@ -8200,9 +8225,13 @@ class bybit extends bybit$1 {
8200
8225
  for (let i = 0; i < keys.length; i++) {
8201
8226
  const marketId = keys[i];
8202
8227
  const entry = grouped[marketId];
8228
+ for (let j = 0; j < entry.length; j++) {
8229
+ const id = this.safeInteger(entry[j], 'id');
8230
+ entry[j]['id'] = id;
8231
+ }
8203
8232
  const market = this.safeMarket(marketId, undefined, undefined, 'contract');
8204
8233
  const symbol = market['symbol'];
8205
- tiers[symbol] = this.parseMarketLeverageTiers(entry, market);
8234
+ tiers[symbol] = this.parseMarketLeverageTiers(this.sortBy(entry, 'id'), market);
8206
8235
  }
8207
8236
  return tiers;
8208
8237
  }
@@ -4171,47 +4171,63 @@ class coinex extends coinex$1 {
4171
4171
  * @method
4172
4172
  * @name coinex#fetchLeverageTiers
4173
4173
  * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
4174
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http007_market_limit
4174
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-position-level
4175
4175
  * @param {string[]|undefined} symbols list of unified market symbols
4176
4176
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4177
4177
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
4178
4178
  */
4179
4179
  await this.loadMarkets();
4180
- const response = await this.v1PerpetualPublicGetMarketLimitConfig(params);
4180
+ const request = {};
4181
+ if (symbols !== undefined) {
4182
+ const marketIds = this.marketIds(symbols);
4183
+ request['market'] = marketIds.join(',');
4184
+ }
4185
+ const response = await this.v2PublicGetFuturesPositionLevel(this.extend(request, params));
4181
4186
  //
4182
4187
  // {
4183
4188
  // "code": 0,
4184
- // "data": {
4185
- // "BTCUSD": [
4186
- // ["500001", "100", "0.005"],
4187
- // ["1000001", "50", "0.01"],
4188
- // ["2000001", "30", "0.015"],
4189
- // ["5000001", "20", "0.02"],
4190
- // ["10000001", "15", "0.025"],
4191
- // ["20000001", "10", "0.03"]
4192
- // ],
4193
- // ...
4194
- // },
4189
+ // "data": [
4190
+ // {
4191
+ // "level": [
4192
+ // {
4193
+ // "amount": "20001",
4194
+ // "leverage": "20",
4195
+ // "maintenance_margin_rate": "0.02",
4196
+ // "min_initial_margin_rate": "0.05"
4197
+ // },
4198
+ // {
4199
+ // "amount": "50001",
4200
+ // "leverage": "10",
4201
+ // "maintenance_margin_rate": "0.04",
4202
+ // "min_initial_margin_rate": "0.1"
4203
+ // },
4204
+ // ],
4205
+ // "market": "MINAUSDT"
4206
+ // },
4207
+ // ],
4195
4208
  // "message": "OK"
4196
4209
  // }
4197
4210
  //
4198
- const data = this.safeValue(response, 'data', {});
4199
- return this.parseLeverageTiers(data, symbols, undefined);
4211
+ const data = this.safeList(response, 'data', []);
4212
+ return this.parseLeverageTiers(data, symbols, 'market');
4200
4213
  }
4201
- parseMarketLeverageTiers(item, market = undefined) {
4214
+ parseMarketLeverageTiers(info, market = undefined) {
4202
4215
  const tiers = [];
4216
+ const brackets = this.safeList(info, 'level', []);
4203
4217
  let minNotional = 0;
4204
- for (let j = 0; j < item.length; j++) {
4205
- const bracket = item[j];
4206
- const maxNotional = this.safeNumber(bracket, 0);
4218
+ for (let i = 0; i < brackets.length; i++) {
4219
+ const tier = brackets[i];
4220
+ const marketId = this.safeString(info, 'market');
4221
+ market = this.safeMarket(marketId, market, undefined, 'swap');
4222
+ const maxNotional = this.safeNumber(tier, 'amount');
4207
4223
  tiers.push({
4208
- 'tier': j + 1,
4224
+ 'tier': this.sum(i, 1),
4209
4225
  'currency': market['linear'] ? market['base'] : market['quote'],
4210
4226
  'minNotional': minNotional,
4211
4227
  'maxNotional': maxNotional,
4212
- 'maintenanceMarginRate': this.safeNumber(bracket, 2),
4213
- 'maxLeverage': this.safeInteger(bracket, 1),
4214
- 'info': bracket,
4228
+ 'maintenanceMarginRate': this.safeNumber(tier, 'maintenance_margin_rate'),
4229
+ 'maxLeverage': this.safeInteger(tier, 'leverage'),
4230
+ 'info': tier,
4215
4231
  });
4216
4232
  minNotional = maxNotional;
4217
4233
  }
@@ -2432,12 +2432,14 @@ class phemex extends phemex$1 {
2432
2432
  * @name phemex#createOrder
2433
2433
  * @description create a trade order
2434
2434
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#place-order
2435
+ * @see https://phemex-docs.github.io/#place-order-http-put-prefered-3
2435
2436
  * @param {string} symbol unified symbol of the market to create an order in
2436
2437
  * @param {string} type 'market' or 'limit'
2437
2438
  * @param {string} side 'buy' or 'sell'
2438
2439
  * @param {float} amount how much of currency you want to trade in units of base currency
2439
2440
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2440
2441
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2442
+ * @param {float} [params.trigger] trigger price for conditional orders
2441
2443
  * @param {object} [params.takeProfit] *swap only* *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered (perpetual swap markets only)
2442
2444
  * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
2443
2445
  * @param {object} [params.stopLoss] *swap only* *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered (perpetual swap markets only)
@@ -2448,7 +2450,7 @@ class phemex extends phemex$1 {
2448
2450
  const market = this.market(symbol);
2449
2451
  const requestSide = this.capitalize(side);
2450
2452
  type = this.capitalize(type);
2451
- const reduceOnly = this.safeValue(params, 'reduceOnly');
2453
+ const reduceOnly = this.safeBool(params, 'reduceOnly');
2452
2454
  const request = {
2453
2455
  // common
2454
2456
  'symbol': market['id'],
@@ -2492,13 +2494,13 @@ class phemex extends phemex$1 {
2492
2494
  request['clOrdID'] = clientOrderId;
2493
2495
  params = this.omit(params, ['clOrdID', 'clientOrderId']);
2494
2496
  }
2495
- const stopPrice = this.safeStringN(params, ['stopPx', 'stopPrice', 'triggerPrice']);
2496
- if (stopPrice !== undefined) {
2497
+ const triggerPrice = this.safeStringN(params, ['stopPx', 'stopPrice', 'triggerPrice']);
2498
+ if (triggerPrice !== undefined) {
2497
2499
  if (market['settle'] === 'USDT') {
2498
- request['stopPxRp'] = this.priceToPrecision(symbol, stopPrice);
2500
+ request['stopPxRp'] = this.priceToPrecision(symbol, triggerPrice);
2499
2501
  }
2500
2502
  else {
2501
- request['stopPxEp'] = this.toEp(stopPrice, market);
2503
+ request['stopPxEp'] = this.toEp(triggerPrice, market);
2502
2504
  }
2503
2505
  }
2504
2506
  params = this.omit(params, ['stopPx', 'stopPrice', 'stopLoss', 'takeProfit', 'triggerPrice']);
@@ -2509,6 +2511,15 @@ class phemex extends phemex$1 {
2509
2511
  qtyType = 'ByQuote';
2510
2512
  }
2511
2513
  }
2514
+ if (triggerPrice !== undefined) {
2515
+ if (type === 'Limit') {
2516
+ request['ordType'] = 'StopLimit';
2517
+ }
2518
+ else if (type === 'Market') {
2519
+ request['ordType'] = 'Stop';
2520
+ }
2521
+ request['trigger'] = 'ByLastPrice';
2522
+ }
2512
2523
  request['qtyType'] = qtyType;
2513
2524
  if (qtyType === 'ByQuote') {
2514
2525
  let cost = this.safeNumber(params, 'cost');
@@ -2549,7 +2560,7 @@ class phemex extends phemex$1 {
2549
2560
  else {
2550
2561
  request['orderQty'] = this.parseToInt(amount);
2551
2562
  }
2552
- if (stopPrice !== undefined) {
2563
+ if (triggerPrice !== undefined) {
2553
2564
  const triggerType = this.safeString(params, 'triggerType', 'ByMarkPrice');
2554
2565
  request['triggerType'] = triggerType;
2555
2566
  }
@@ -1897,7 +1897,7 @@ class htx extends htx$1 {
1897
1897
  // "data": { "user-id": "35930539" }
1898
1898
  // }
1899
1899
  //
1900
- const promise = client.futures['authenticated'];
1900
+ const promise = client.futures['auth'];
1901
1901
  promise.resolve(message);
1902
1902
  }
1903
1903
  handleErrorMessage(client, message) {
@@ -1925,6 +1925,12 @@ class htx extends htx$1 {
1925
1925
  // 'err-msg': "Non - single account user is not available, please check through the cross and isolated account asset interface",
1926
1926
  // "ts": 1698419490189
1927
1927
  // }
1928
+ // {
1929
+ // "action":"req",
1930
+ // "code":2002,
1931
+ // "ch":"auth",
1932
+ // "message":"auth.fail"
1933
+ // }
1928
1934
  //
1929
1935
  const status = this.safeString(message, 'status');
1930
1936
  if (status === 'error') {
@@ -1935,6 +1941,7 @@ class htx extends htx$1 {
1935
1941
  const errorCode = this.safeString(message, 'err-code');
1936
1942
  try {
1937
1943
  this.throwExactlyMatchedException(this.exceptions['ws']['exact'], errorCode, this.json(message));
1944
+ throw new errors.ExchangeError(this.json(message));
1938
1945
  }
1939
1946
  catch (e) {
1940
1947
  const messageHash = this.safeString(subscription, 'messageHash');
@@ -1947,11 +1954,12 @@ class htx extends htx$1 {
1947
1954
  }
1948
1955
  return false;
1949
1956
  }
1950
- const code = this.safeInteger2(message, 'code', 'err-code');
1951
- if (code !== undefined && ((code !== 200) && (code !== 0))) {
1957
+ const code = this.safeString2(message, 'code', 'err-code');
1958
+ if (code !== undefined && ((code !== '200') && (code !== '0'))) {
1952
1959
  const feedback = this.id + ' ' + this.json(message);
1953
1960
  try {
1954
1961
  this.throwExactlyMatchedException(this.exceptions['ws']['exact'], code, feedback);
1962
+ throw new errors.ExchangeError(feedback);
1955
1963
  }
1956
1964
  catch (e) {
1957
1965
  if (e instanceof errors.AuthenticationError) {
@@ -2305,9 +2313,6 @@ class htx extends htx$1 {
2305
2313
  'url': url,
2306
2314
  'hostname': hostname,
2307
2315
  };
2308
- if (type === 'spot') {
2309
- this.options['ws']['gunzip'] = false;
2310
- }
2311
2316
  await this.authenticate(authParams);
2312
2317
  return await this.watch(url, messageHash, this.extend(request, params), channel, extendedSubsription);
2313
2318
  }
@@ -2319,7 +2324,7 @@ class htx extends htx$1 {
2319
2324
  throw new errors.ArgumentsRequired(this.id + ' authenticate requires a url, hostname and type argument');
2320
2325
  }
2321
2326
  this.checkRequiredCredentials();
2322
- const messageHash = 'authenticated';
2327
+ const messageHash = 'auth';
2323
2328
  const relativePath = url.replace('wss://' + hostname, '');
2324
2329
  const client = this.client(url);
2325
2330
  const future = client.future(messageHash);
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, Leverage, Leverages, Option, OptionChain, Conversion } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
7
- declare const version = "4.3.18";
7
+ declare const version = "4.3.19";
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, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.3.19';
41
+ const version = '4.3.20';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -100,6 +100,9 @@ interface Exchange {
100
100
  privateSpotGetV2SpotAccountSubaccountAssets(params?: {}): Promise<implicitReturnType>;
101
101
  privateSpotGetV2SpotAccountBills(params?: {}): Promise<implicitReturnType>;
102
102
  privateSpotGetV2SpotAccountTransferRecords(params?: {}): Promise<implicitReturnType>;
103
+ privateSpotGetV2AccountFundingAssets(params?: {}): Promise<implicitReturnType>;
104
+ privateSpotGetV2AccountBotAssets(params?: {}): Promise<implicitReturnType>;
105
+ privateSpotGetV2AccountAllAccountBalance(params?: {}): Promise<implicitReturnType>;
103
106
  privateSpotGetV2SpotWalletDepositAddress(params?: {}): Promise<implicitReturnType>;
104
107
  privateSpotGetV2SpotWalletDepositRecords(params?: {}): Promise<implicitReturnType>;
105
108
  privateSpotGetV2SpotWalletWithdrawalRecords(params?: {}): Promise<implicitReturnType>;
@@ -5935,6 +5935,9 @@ export default class Exchange {
5935
5935
  if (method === 'fetchAccounts') {
5936
5936
  response = await this[method](params);
5937
5937
  }
5938
+ else if (method === 'getLeverageTiersPaginated') {
5939
+ response = await this[method](symbol, params);
5940
+ }
5938
5941
  else {
5939
5942
  response = await this[method](symbol, since, maxEntriesPerRequest, params);
5940
5943
  }
package/js/src/bitget.js CHANGED
@@ -313,6 +313,9 @@ export default class bitget extends Exchange {
313
313
  'v2/spot/account/subaccount-assets': 2,
314
314
  'v2/spot/account/bills': 2,
315
315
  'v2/spot/account/transferRecords': 1,
316
+ 'v2/account/funding-assets': 2,
317
+ 'v2/account/bot-assets': 2,
318
+ 'v2/account/all-account-balance': 20,
316
319
  'v2/spot/wallet/deposit-address': 2,
317
320
  'v2/spot/wallet/deposit-records': 2,
318
321
  'v2/spot/wallet/withdrawal-records': 2,
package/js/src/bybit.d.ts CHANGED
@@ -211,6 +211,7 @@ export default class bybit extends Exchange {
211
211
  parseGreeks(greeks: Dict, market?: Market): Greeks;
212
212
  fetchMyLiquidations(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
213
213
  parseLiquidation(liquidation: any, market?: Market): Liquidation;
214
+ getLeverageTiersPaginated(symbol?: Str, params?: {}): Promise<any>;
214
215
  fetchLeverageTiers(symbols?: Strings, params?: {}): Promise<{}>;
215
216
  parseLeverageTiers(response: any, symbols?: Strings, marketIdKey?: any): {};
216
217
  parseMarketLeverageTiers(info: any, market?: Market): any[];
package/js/src/bybit.js CHANGED
@@ -8155,6 +8155,35 @@ export default class bybit extends Exchange {
8155
8155
  'datetime': this.iso8601(timestamp),
8156
8156
  });
8157
8157
  }
8158
+ async getLeverageTiersPaginated(symbol = undefined, params = {}) {
8159
+ await this.loadMarkets();
8160
+ let market = undefined;
8161
+ if (symbol !== undefined) {
8162
+ market = this.market(symbol);
8163
+ }
8164
+ let paginate = false;
8165
+ [paginate, params] = this.handleOptionAndParams(params, 'getLeverageTiersPaginated', 'paginate');
8166
+ if (paginate) {
8167
+ return await this.fetchPaginatedCallCursor('getLeverageTiersPaginated', symbol, undefined, undefined, params, 'nextPageCursor', 'cursor', undefined, 100);
8168
+ }
8169
+ let subType = undefined;
8170
+ [subType, params] = this.handleSubTypeAndParams('getLeverageTiersPaginated', market, params, 'linear');
8171
+ const request = {
8172
+ 'category': subType,
8173
+ };
8174
+ const response = await this.publicGetV5MarketRiskLimit(this.extend(request, params));
8175
+ const result = this.addPaginationCursorToResult(response);
8176
+ const first = this.safeDict(result, 0);
8177
+ const total = result.length;
8178
+ const lastIndex = total - 1;
8179
+ const last = this.safeDict(result, lastIndex);
8180
+ const cursorValue = this.safeString(first, 'nextPageCursor');
8181
+ last['info'] = {
8182
+ 'nextPageCursor': cursorValue,
8183
+ };
8184
+ result[lastIndex] = last;
8185
+ return result;
8186
+ }
8158
8187
  async fetchLeverageTiers(symbols = undefined, params = {}) {
8159
8188
  /**
8160
8189
  * @method
@@ -8164,24 +8193,20 @@ export default class bybit extends Exchange {
8164
8193
  * @param {string[]} [symbols] a list of unified market symbols
8165
8194
  * @param {object} [params] extra parameters specific to the exchange API endpoint
8166
8195
  * @param {string} [params.subType] market subType, ['linear', 'inverse'], default is 'linear'
8196
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
8167
8197
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
8168
8198
  */
8169
8199
  await this.loadMarkets();
8170
8200
  let market = undefined;
8201
+ let symbol = undefined;
8171
8202
  if (symbols !== undefined) {
8172
8203
  market = this.market(symbols[0]);
8173
8204
  if (market['spot']) {
8174
8205
  throw new NotSupported(this.id + ' fetchLeverageTiers() is not supported for spot market');
8175
8206
  }
8207
+ symbol = market['symbol'];
8176
8208
  }
8177
- let subType = undefined;
8178
- [subType, params] = this.handleSubTypeAndParams('fetchTickers', market, params, 'linear');
8179
- const request = {
8180
- 'category': subType,
8181
- };
8182
- const response = await this.publicGetV5MarketRiskLimit(this.extend(request, params));
8183
- const result = this.safeDict(response, 'result', {});
8184
- const data = this.safeList(result, 'list', []);
8209
+ const data = await this.getLeverageTiersPaginated(symbol, this.extend({ 'paginate': true, 'paginationCalls': 20 }, params));
8185
8210
  symbols = this.marketSymbols(symbols);
8186
8211
  return this.parseLeverageTiers(data, symbols, 'symbol');
8187
8212
  }
@@ -8207,9 +8232,13 @@ export default class bybit extends Exchange {
8207
8232
  for (let i = 0; i < keys.length; i++) {
8208
8233
  const marketId = keys[i];
8209
8234
  const entry = grouped[marketId];
8235
+ for (let j = 0; j < entry.length; j++) {
8236
+ const id = this.safeInteger(entry[j], 'id');
8237
+ entry[j]['id'] = id;
8238
+ }
8210
8239
  const market = this.safeMarket(marketId, undefined, undefined, 'contract');
8211
8240
  const symbol = market['symbol'];
8212
- tiers[symbol] = this.parseMarketLeverageTiers(entry, market);
8241
+ tiers[symbol] = this.parseMarketLeverageTiers(this.sortBy(entry, 'id'), market);
8213
8242
  }
8214
8243
  return tiers;
8215
8244
  }
@@ -71,7 +71,7 @@ export default class coinex extends Exchange {
71
71
  setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<any>;
72
72
  setLeverage(leverage: Int, symbol?: Str, params?: {}): Promise<any>;
73
73
  fetchLeverageTiers(symbols?: Strings, params?: {}): Promise<{}>;
74
- parseMarketLeverageTiers(item: any, market?: Market): any[];
74
+ parseMarketLeverageTiers(info: any, market?: Market): any[];
75
75
  modifyMarginHelper(symbol: string, amount: any, addOrReduce: any, params?: {}): Promise<any>;
76
76
  parseMarginModification(data: any, market?: Market): MarginModification;
77
77
  addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
package/js/src/coinex.js CHANGED
@@ -4174,47 +4174,63 @@ export default class coinex extends Exchange {
4174
4174
  * @method
4175
4175
  * @name coinex#fetchLeverageTiers
4176
4176
  * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
4177
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http007_market_limit
4177
+ * @see https://docs.coinex.com/api/v2/futures/market/http/list-market-position-level
4178
4178
  * @param {string[]|undefined} symbols list of unified market symbols
4179
4179
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4180
4180
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
4181
4181
  */
4182
4182
  await this.loadMarkets();
4183
- const response = await this.v1PerpetualPublicGetMarketLimitConfig(params);
4183
+ const request = {};
4184
+ if (symbols !== undefined) {
4185
+ const marketIds = this.marketIds(symbols);
4186
+ request['market'] = marketIds.join(',');
4187
+ }
4188
+ const response = await this.v2PublicGetFuturesPositionLevel(this.extend(request, params));
4184
4189
  //
4185
4190
  // {
4186
4191
  // "code": 0,
4187
- // "data": {
4188
- // "BTCUSD": [
4189
- // ["500001", "100", "0.005"],
4190
- // ["1000001", "50", "0.01"],
4191
- // ["2000001", "30", "0.015"],
4192
- // ["5000001", "20", "0.02"],
4193
- // ["10000001", "15", "0.025"],
4194
- // ["20000001", "10", "0.03"]
4195
- // ],
4196
- // ...
4197
- // },
4192
+ // "data": [
4193
+ // {
4194
+ // "level": [
4195
+ // {
4196
+ // "amount": "20001",
4197
+ // "leverage": "20",
4198
+ // "maintenance_margin_rate": "0.02",
4199
+ // "min_initial_margin_rate": "0.05"
4200
+ // },
4201
+ // {
4202
+ // "amount": "50001",
4203
+ // "leverage": "10",
4204
+ // "maintenance_margin_rate": "0.04",
4205
+ // "min_initial_margin_rate": "0.1"
4206
+ // },
4207
+ // ],
4208
+ // "market": "MINAUSDT"
4209
+ // },
4210
+ // ],
4198
4211
  // "message": "OK"
4199
4212
  // }
4200
4213
  //
4201
- const data = this.safeValue(response, 'data', {});
4202
- return this.parseLeverageTiers(data, symbols, undefined);
4214
+ const data = this.safeList(response, 'data', []);
4215
+ return this.parseLeverageTiers(data, symbols, 'market');
4203
4216
  }
4204
- parseMarketLeverageTiers(item, market = undefined) {
4217
+ parseMarketLeverageTiers(info, market = undefined) {
4205
4218
  const tiers = [];
4219
+ const brackets = this.safeList(info, 'level', []);
4206
4220
  let minNotional = 0;
4207
- for (let j = 0; j < item.length; j++) {
4208
- const bracket = item[j];
4209
- const maxNotional = this.safeNumber(bracket, 0);
4221
+ for (let i = 0; i < brackets.length; i++) {
4222
+ const tier = brackets[i];
4223
+ const marketId = this.safeString(info, 'market');
4224
+ market = this.safeMarket(marketId, market, undefined, 'swap');
4225
+ const maxNotional = this.safeNumber(tier, 'amount');
4210
4226
  tiers.push({
4211
- 'tier': j + 1,
4227
+ 'tier': this.sum(i, 1),
4212
4228
  'currency': market['linear'] ? market['base'] : market['quote'],
4213
4229
  'minNotional': minNotional,
4214
4230
  'maxNotional': maxNotional,
4215
- 'maintenanceMarginRate': this.safeNumber(bracket, 2),
4216
- 'maxLeverage': this.safeInteger(bracket, 1),
4217
- 'info': bracket,
4231
+ 'maintenanceMarginRate': this.safeNumber(tier, 'maintenance_margin_rate'),
4232
+ 'maxLeverage': this.safeInteger(tier, 'leverage'),
4233
+ 'info': tier,
4218
4234
  });
4219
4235
  minNotional = maxNotional;
4220
4236
  }
package/js/src/phemex.js CHANGED
@@ -2435,12 +2435,14 @@ export default class phemex extends Exchange {
2435
2435
  * @name phemex#createOrder
2436
2436
  * @description create a trade order
2437
2437
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#place-order
2438
+ * @see https://phemex-docs.github.io/#place-order-http-put-prefered-3
2438
2439
  * @param {string} symbol unified symbol of the market to create an order in
2439
2440
  * @param {string} type 'market' or 'limit'
2440
2441
  * @param {string} side 'buy' or 'sell'
2441
2442
  * @param {float} amount how much of currency you want to trade in units of base currency
2442
2443
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2443
2444
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2445
+ * @param {float} [params.trigger] trigger price for conditional orders
2444
2446
  * @param {object} [params.takeProfit] *swap only* *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered (perpetual swap markets only)
2445
2447
  * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
2446
2448
  * @param {object} [params.stopLoss] *swap only* *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered (perpetual swap markets only)
@@ -2451,7 +2453,7 @@ export default class phemex extends Exchange {
2451
2453
  const market = this.market(symbol);
2452
2454
  const requestSide = this.capitalize(side);
2453
2455
  type = this.capitalize(type);
2454
- const reduceOnly = this.safeValue(params, 'reduceOnly');
2456
+ const reduceOnly = this.safeBool(params, 'reduceOnly');
2455
2457
  const request = {
2456
2458
  // common
2457
2459
  'symbol': market['id'],
@@ -2495,13 +2497,13 @@ export default class phemex extends Exchange {
2495
2497
  request['clOrdID'] = clientOrderId;
2496
2498
  params = this.omit(params, ['clOrdID', 'clientOrderId']);
2497
2499
  }
2498
- const stopPrice = this.safeStringN(params, ['stopPx', 'stopPrice', 'triggerPrice']);
2499
- if (stopPrice !== undefined) {
2500
+ const triggerPrice = this.safeStringN(params, ['stopPx', 'stopPrice', 'triggerPrice']);
2501
+ if (triggerPrice !== undefined) {
2500
2502
  if (market['settle'] === 'USDT') {
2501
- request['stopPxRp'] = this.priceToPrecision(symbol, stopPrice);
2503
+ request['stopPxRp'] = this.priceToPrecision(symbol, triggerPrice);
2502
2504
  }
2503
2505
  else {
2504
- request['stopPxEp'] = this.toEp(stopPrice, market);
2506
+ request['stopPxEp'] = this.toEp(triggerPrice, market);
2505
2507
  }
2506
2508
  }
2507
2509
  params = this.omit(params, ['stopPx', 'stopPrice', 'stopLoss', 'takeProfit', 'triggerPrice']);
@@ -2512,6 +2514,15 @@ export default class phemex extends Exchange {
2512
2514
  qtyType = 'ByQuote';
2513
2515
  }
2514
2516
  }
2517
+ if (triggerPrice !== undefined) {
2518
+ if (type === 'Limit') {
2519
+ request['ordType'] = 'StopLimit';
2520
+ }
2521
+ else if (type === 'Market') {
2522
+ request['ordType'] = 'Stop';
2523
+ }
2524
+ request['trigger'] = 'ByLastPrice';
2525
+ }
2515
2526
  request['qtyType'] = qtyType;
2516
2527
  if (qtyType === 'ByQuote') {
2517
2528
  let cost = this.safeNumber(params, 'cost');
@@ -2552,7 +2563,7 @@ export default class phemex extends Exchange {
2552
2563
  else {
2553
2564
  request['orderQty'] = this.parseToInt(amount);
2554
2565
  }
2555
- if (stopPrice !== undefined) {
2566
+ if (triggerPrice !== undefined) {
2556
2567
  const triggerType = this.safeString(params, 'triggerType', 'ByMarkPrice');
2557
2568
  request['triggerType'] = triggerType;
2558
2569
  }
package/js/src/pro/htx.js CHANGED
@@ -1900,7 +1900,7 @@ export default class htx extends htxRest {
1900
1900
  // "data": { "user-id": "35930539" }
1901
1901
  // }
1902
1902
  //
1903
- const promise = client.futures['authenticated'];
1903
+ const promise = client.futures['auth'];
1904
1904
  promise.resolve(message);
1905
1905
  }
1906
1906
  handleErrorMessage(client, message) {
@@ -1928,6 +1928,12 @@ export default class htx extends htxRest {
1928
1928
  // 'err-msg': "Non - single account user is not available, please check through the cross and isolated account asset interface",
1929
1929
  // "ts": 1698419490189
1930
1930
  // }
1931
+ // {
1932
+ // "action":"req",
1933
+ // "code":2002,
1934
+ // "ch":"auth",
1935
+ // "message":"auth.fail"
1936
+ // }
1931
1937
  //
1932
1938
  const status = this.safeString(message, 'status');
1933
1939
  if (status === 'error') {
@@ -1938,6 +1944,7 @@ export default class htx extends htxRest {
1938
1944
  const errorCode = this.safeString(message, 'err-code');
1939
1945
  try {
1940
1946
  this.throwExactlyMatchedException(this.exceptions['ws']['exact'], errorCode, this.json(message));
1947
+ throw new ExchangeError(this.json(message));
1941
1948
  }
1942
1949
  catch (e) {
1943
1950
  const messageHash = this.safeString(subscription, 'messageHash');
@@ -1950,11 +1957,12 @@ export default class htx extends htxRest {
1950
1957
  }
1951
1958
  return false;
1952
1959
  }
1953
- const code = this.safeInteger2(message, 'code', 'err-code');
1954
- if (code !== undefined && ((code !== 200) && (code !== 0))) {
1960
+ const code = this.safeString2(message, 'code', 'err-code');
1961
+ if (code !== undefined && ((code !== '200') && (code !== '0'))) {
1955
1962
  const feedback = this.id + ' ' + this.json(message);
1956
1963
  try {
1957
1964
  this.throwExactlyMatchedException(this.exceptions['ws']['exact'], code, feedback);
1965
+ throw new ExchangeError(feedback);
1958
1966
  }
1959
1967
  catch (e) {
1960
1968
  if (e instanceof AuthenticationError) {
@@ -2308,9 +2316,6 @@ export default class htx extends htxRest {
2308
2316
  'url': url,
2309
2317
  'hostname': hostname,
2310
2318
  };
2311
- if (type === 'spot') {
2312
- this.options['ws']['gunzip'] = false;
2313
- }
2314
2319
  await this.authenticate(authParams);
2315
2320
  return await this.watch(url, messageHash, this.extend(request, params), channel, extendedSubsription);
2316
2321
  }
@@ -2322,7 +2327,7 @@ export default class htx extends htxRest {
2322
2327
  throw new ArgumentsRequired(this.id + ' authenticate requires a url, hostname and type argument');
2323
2328
  }
2324
2329
  this.checkRequiredCredentials();
2325
- const messageHash = 'authenticated';
2330
+ const messageHash = 'auth';
2326
2331
  const relativePath = url.replace('wss://' + hostname, '');
2327
2332
  const client = this.client(url);
2328
2333
  const future = client.future(messageHash);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.3.19",
3
+ "version": "4.3.20",
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",