ccxt 4.3.19 → 4.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/ccxt.js +1 -1
  3. package/dist/cjs/src/base/Exchange.js +3 -0
  4. package/dist/cjs/src/base/functions/platform.js +3 -1
  5. package/dist/cjs/src/base/functions.js +1 -0
  6. package/dist/cjs/src/binance.js +10 -1
  7. package/dist/cjs/src/bitget.js +3 -0
  8. package/dist/cjs/src/bitmex.js +1 -0
  9. package/dist/cjs/src/bybit.js +38 -9
  10. package/dist/cjs/src/coinex.js +180 -201
  11. package/dist/cjs/src/hyperliquid.js +24 -2
  12. package/dist/cjs/src/okx.js +3 -0
  13. package/dist/cjs/src/phemex.js +17 -6
  14. package/dist/cjs/src/pro/htx.js +12 -7
  15. package/dist/cjs/src/pro/kucoinfutures.js +92 -0
  16. package/dist/cjs/src/pro/woo.js +52 -24
  17. package/js/ccxt.d.ts +1 -1
  18. package/js/ccxt.js +1 -1
  19. package/js/src/abstract/binance.d.ts +1 -0
  20. package/js/src/abstract/binancecoinm.d.ts +1 -0
  21. package/js/src/abstract/binanceus.d.ts +1 -0
  22. package/js/src/abstract/binanceusdm.d.ts +1 -0
  23. package/js/src/abstract/bitget.d.ts +3 -0
  24. package/js/src/abstract/okx.d.ts +3 -0
  25. package/js/src/ascendex.d.ts +1 -1
  26. package/js/src/base/Exchange.d.ts +1 -1
  27. package/js/src/base/Exchange.js +3 -0
  28. package/js/src/base/functions/platform.d.ts +2 -1
  29. package/js/src/base/functions/platform.js +3 -2
  30. package/js/src/binance.d.ts +1 -1
  31. package/js/src/binance.js +10 -1
  32. package/js/src/bingx.d.ts +1 -1
  33. package/js/src/bitget.d.ts +1 -1
  34. package/js/src/bitget.js +3 -0
  35. package/js/src/bitmex.js +1 -0
  36. package/js/src/bybit.d.ts +1 -0
  37. package/js/src/bybit.js +38 -9
  38. package/js/src/coinex.d.ts +2 -2
  39. package/js/src/coinex.js +180 -201
  40. package/js/src/delta.d.ts +1 -1
  41. package/js/src/digifinex.d.ts +1 -1
  42. package/js/src/exmo.d.ts +1 -1
  43. package/js/src/gate.d.ts +1 -1
  44. package/js/src/hitbtc.d.ts +1 -1
  45. package/js/src/hyperliquid.d.ts +1 -1
  46. package/js/src/hyperliquid.js +24 -2
  47. package/js/src/okx.d.ts +1 -1
  48. package/js/src/okx.js +3 -0
  49. package/js/src/phemex.d.ts +1 -1
  50. package/js/src/phemex.js +17 -6
  51. package/js/src/pro/htx.js +12 -7
  52. package/js/src/pro/kucoinfutures.d.ts +3 -1
  53. package/js/src/pro/kucoinfutures.js +93 -1
  54. package/js/src/pro/woo.d.ts +2 -1
  55. package/js/src/pro/woo.js +52 -24
  56. package/package.json +1 -1
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,9 +71,9 @@ 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
- parseMarginModification(data: any, market?: Market): MarginModification;
76
+ parseMarginModification(data: Dict, market?: Market): MarginModification;
77
77
  addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
78
78
  reduceMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
79
79
  fetchFundingHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
package/js/src/coinex.js CHANGED
@@ -298,7 +298,7 @@ export default class coinex extends Exchange {
298
298
  'v2': {
299
299
  'public': {
300
300
  'get': {
301
- 'maintain-info': 1,
301
+ 'maintain/info': 1,
302
302
  'ping': 1,
303
303
  'time': 1,
304
304
  'spot/market': 1,
@@ -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
  }
@@ -4223,72 +4239,60 @@ export default class coinex extends Exchange {
4223
4239
  async modifyMarginHelper(symbol, amount, addOrReduce, params = {}) {
4224
4240
  await this.loadMarkets();
4225
4241
  const market = this.market(symbol);
4242
+ const rawAmount = this.amountToPrecision(symbol, amount);
4243
+ let requestAmount = rawAmount;
4244
+ if (addOrReduce === 'reduce') {
4245
+ requestAmount = Precise.stringNeg(rawAmount);
4246
+ }
4226
4247
  const request = {
4227
4248
  'market': market['id'],
4228
- 'amount': this.amountToPrecision(symbol, amount),
4229
- 'type': addOrReduce,
4249
+ 'market_type': 'FUTURES',
4250
+ 'amount': requestAmount,
4230
4251
  };
4231
- const response = await this.v1PerpetualPrivatePostPositionAdjustMargin(this.extend(request, params));
4252
+ const response = await this.v2PrivatePostFuturesAdjustPositionMargin(this.extend(request, params));
4232
4253
  //
4233
4254
  // {
4234
4255
  // "code": 0,
4235
4256
  // "data": {
4236
- // "adl_sort": 1,
4237
- // "adl_sort_val": "0.00004320",
4238
- // "amount": "0.0005",
4239
- // "amount_max": "0.0005",
4240
- // "amount_max_margin": "6.57352000000000000000",
4241
- // "bkr_price": "16294.08000000000000011090",
4242
- // "bkr_price_imply": "0.00000000000000000000",
4243
- // "close_left": "0.0005",
4244
- // "create_time": 1651202571.320778,
4245
- // "deal_all": "19.72000000000000000000",
4246
- // "deal_asset_fee": "0.00000000000000000000",
4247
- // "fee_asset": "",
4248
- // "finish_type": 1,
4249
- // "first_price": "39441.12",
4250
- // "insurance": "0.00000000000000000000",
4251
- // "latest_price": "39441.12",
4257
+ // "adl_level": 1,
4258
+ // "ath_margin_size": "2.034928",
4259
+ // "ath_position_amount": "0.0001",
4260
+ // "avg_entry_price": "61047.84",
4261
+ // "bkr_price": "30698.5600000000000004142",
4262
+ // "close_avbl": "0.0001",
4263
+ // "cml_position_value": "6.104784",
4264
+ // "created_at": 1715488472908,
4252
4265
  // "leverage": "3",
4253
- // "liq_amount": "0.00000000000000000000",
4254
- // "liq_order_price": "0",
4255
- // "liq_order_time": 0,
4256
- // "liq_price": "16491.28560000000000011090",
4257
- // "liq_price_imply": "0.00000000000000000000",
4258
- // "liq_profit": "0.00000000000000000000",
4259
- // "liq_time": 0,
4260
- // "mainten_margin": "0.005",
4261
- // "mainten_margin_amount": "0.09860280000000000000",
4262
- // "maker_fee": "0.00000000000000000000",
4263
- // "margin_amount": "11.57352000000000000000",
4266
+ // "liq_price": "30852.82412060301507579316",
4267
+ // "maintenance_margin_rate": "0.005",
4268
+ // "maintenance_margin_value": "0.03051465",
4269
+ // "margin_avbl": "3.034928",
4270
+ // "margin_mode": "isolated",
4264
4271
  // "market": "BTCUSDT",
4265
- // "open_margin": "0.58687582908396110455",
4266
- // "open_margin_imply": "0.00000000000000000000",
4267
- // "open_price": "39441.12000000000000000000",
4268
- // "open_val": "19.72056000000000000000",
4269
- // "open_val_max": "19.72056000000000000000",
4270
- // "position_id": 65171206,
4271
- // "profit_clearing": "-0.00986028000000000000",
4272
- // "profit_real": "-0.00986028000000000000",
4273
- // "profit_unreal": "0.00",
4274
- // "side": 2,
4275
- // "stop_loss_price": "0.00000000000000000000",
4276
- // "stop_loss_type": 0,
4277
- // "s ys": 0,
4278
- // "take_profit_price": "0.00000000000000000000",
4279
- // "take_profit_type": 0,
4280
- // "taker_fee": "0.00000000000000000000",
4281
- // "total": 3464,
4282
- // "type": 1,
4283
- // "update_time": 1651202638.911212,
4284
- // "user_id": 3620173
4272
+ // "market_type": "FUTURES",
4273
+ // "max_position_value": "6.104784",
4274
+ // "open_interest": "0.0001",
4275
+ // "position_id": 306458800,
4276
+ // "position_margin_rate": "0.49713929272518077625",
4277
+ // "realized_pnl": "-0.003052392",
4278
+ // "settle_price": "61047.84",
4279
+ // "settle_value": "6.104784",
4280
+ // "side": "long",
4281
+ // "stop_loss_price": "0",
4282
+ // "stop_loss_type": "",
4283
+ // "take_profit_price": "0",
4284
+ // "take_profit_type": "",
4285
+ // "unrealized_pnl": "0",
4286
+ // "updated_at": 1715488805563
4285
4287
  // },
4286
- // "message":"OK"
4288
+ // "message": "OK"
4287
4289
  // }
4288
4290
  //
4289
4291
  const data = this.safeDict(response, 'data');
4290
- const status = this.safeString(response, 'message');
4292
+ const status = this.safeStringLower(response, 'message');
4293
+ const type = (addOrReduce === 'reduce') ? 'reduce' : 'add';
4291
4294
  return this.extend(this.parseMarginModification(data, market), {
4295
+ 'type': type,
4292
4296
  'amount': this.parseNumber(amount),
4293
4297
  'status': status,
4294
4298
  });
@@ -4297,86 +4301,66 @@ export default class coinex extends Exchange {
4297
4301
  //
4298
4302
  // addMargin/reduceMargin
4299
4303
  //
4300
- // {
4301
- // "adl_sort": 1,
4302
- // "adl_sort_val": "0.00004320",
4303
- // "amount": "0.0005",
4304
- // "amount_max": "0.0005",
4305
- // "amount_max_margin": "6.57352000000000000000",
4306
- // "bkr_price": "16294.08000000000000011090",
4307
- // "bkr_price_imply": "0.00000000000000000000",
4308
- // "close_left": "0.0005",
4309
- // "create_time": 1651202571.320778,
4310
- // "deal_all": "19.72000000000000000000",
4311
- // "deal_asset_fee": "0.00000000000000000000",
4312
- // "fee_asset": "",
4313
- // "finish_type": 1,
4314
- // "first_price": "39441.12",
4315
- // "insurance": "0.00000000000000000000",
4316
- // "latest_price": "39441.12",
4317
- // "leverage": "3",
4318
- // "liq_amount": "0.00000000000000000000",
4319
- // "liq_order_price": "0",
4320
- // "liq_order_time": 0,
4321
- // "liq_price": "16491.28560000000000011090",
4322
- // "liq_price_imply": "0.00000000000000000000",
4323
- // "liq_profit": "0.00000000000000000000",
4324
- // "liq_time": 0,
4325
- // "mainten_margin": "0.005",
4326
- // "mainten_margin_amount": "0.09860280000000000000",
4327
- // "maker_fee": "0.00000000000000000000",
4328
- // "margin_amount": "11.57352000000000000000",
4329
- // "market": "BTCUSDT",
4330
- // "open_margin": "0.58687582908396110455",
4331
- // "open_margin_imply": "0.00000000000000000000",
4332
- // "open_price": "39441.12000000000000000000",
4333
- // "open_val": "19.72056000000000000000",
4334
- // "open_val_max": "19.72056000000000000000",
4335
- // "position_id": 65171206,
4336
- // "profit_clearing": "-0.00986028000000000000",
4337
- // "profit_real": "-0.00986028000000000000",
4338
- // "profit_unreal": "0.00",
4339
- // "side": 2,
4340
- // "stop_loss_price": "0.00000000000000000000",
4341
- // "stop_loss_type": 0,
4342
- // "sy s": 0,
4343
- // "take_profit_price": "0.00000000000000000000",
4344
- // "take_profit_type": 0,
4345
- // "taker_fee": "0.00000000000000000000",
4346
- // "total": 3464,
4347
- // "type": 1,
4348
- // "update_time": 1651202638.911212,
4349
- // "user_id": 3620173
4350
- // }
4304
+ // {
4305
+ // "adl_level": 1,
4306
+ // "ath_margin_size": "2.034928",
4307
+ // "ath_position_amount": "0.0001",
4308
+ // "avg_entry_price": "61047.84",
4309
+ // "bkr_price": "30698.5600000000000004142",
4310
+ // "close_avbl": "0.0001",
4311
+ // "cml_position_value": "6.104784",
4312
+ // "created_at": 1715488472908,
4313
+ // "leverage": "3",
4314
+ // "liq_price": "30852.82412060301507579316",
4315
+ // "maintenance_margin_rate": "0.005",
4316
+ // "maintenance_margin_value": "0.03051465",
4317
+ // "margin_avbl": "3.034928",
4318
+ // "margin_mode": "isolated",
4319
+ // "market": "BTCUSDT",
4320
+ // "market_type": "FUTURES",
4321
+ // "max_position_value": "6.104784",
4322
+ // "open_interest": "0.0001",
4323
+ // "position_id": 306458800,
4324
+ // "position_margin_rate": "0.49713929272518077625",
4325
+ // "realized_pnl": "-0.003052392",
4326
+ // "settle_price": "61047.84",
4327
+ // "settle_value": "6.104784",
4328
+ // "side": "long",
4329
+ // "stop_loss_price": "0",
4330
+ // "stop_loss_type": "",
4331
+ // "take_profit_price": "0",
4332
+ // "take_profit_type": "",
4333
+ // "unrealized_pnl": "0",
4334
+ // "updated_at": 1715488805563
4335
+ // }
4351
4336
  //
4352
4337
  // fetchMarginAdjustmentHistory
4353
4338
  //
4354
- // {
4355
- // bkr_price: '0',
4356
- // leverage: '3',
4357
- // liq_price: '0',
4358
- // margin_amount: '5.33236666666666666666',
4359
- // margin_change: '3',
4360
- // market: 'XRPUSDT',
4361
- // position_amount: '11',
4362
- // position_id: '297155652',
4363
- // position_type: '2',
4364
- // settle_price: '0.6361',
4365
- // time: '1711050906.382891',
4366
- // type: '1',
4367
- // user_id: '3685860'
4368
- // }
4339
+ // {
4340
+ // "bkr_pirce": "24698.56000000000000005224",
4341
+ // "created_at": 1715489978697,
4342
+ // "leverage": "3",
4343
+ // "liq_price": "24822.67336683417085432386",
4344
+ // "margin_avbl": "3.634928",
4345
+ // "margin_change": "-1.5",
4346
+ // "margin_mode": "isolated",
4347
+ // "market": "BTCUSDT",
4348
+ // "market_type": "FUTURES",
4349
+ // "open_interest": "0.0001",
4350
+ // "position_id": 306458800,
4351
+ // "settle_price": "61047.84"
4352
+ // }
4369
4353
  //
4370
4354
  const marketId = this.safeString(data, 'market');
4371
- const type = this.safeString(data, 'type');
4372
- const timestamp = this.safeIntegerProduct2(data, 'time', 'update_time', 1000);
4355
+ const timestamp = this.safeInteger2(data, 'updated_at', 'created_at');
4356
+ const change = this.safeString(data, 'margin_change');
4373
4357
  return {
4374
4358
  'info': data,
4375
4359
  'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
4376
- 'type': (type === '1') ? 'add' : 'reduce',
4360
+ 'type': undefined,
4377
4361
  'marginMode': 'isolated',
4378
- 'amount': this.safeNumber(data, 'margin_change'),
4379
- 'total': this.safeNumber(data, 'position_amount'),
4362
+ 'amount': this.parseNumber(Precise.stringAbs(change)),
4363
+ 'total': this.safeNumber(data, 'margin_avbl'),
4380
4364
  'code': market['quote'],
4381
4365
  'status': undefined,
4382
4366
  'timestamp': timestamp,
@@ -4388,26 +4372,26 @@ export default class coinex extends Exchange {
4388
4372
  * @method
4389
4373
  * @name coinex#addMargin
4390
4374
  * @description add margin
4391
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http032_adjust_position_margin
4375
+ * @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin
4392
4376
  * @param {string} symbol unified market symbol
4393
4377
  * @param {float} amount amount of margin to add
4394
4378
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4395
4379
  * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=add-margin-structure}
4396
4380
  */
4397
- return await this.modifyMarginHelper(symbol, amount, 1, params);
4381
+ return await this.modifyMarginHelper(symbol, amount, 'add', params);
4398
4382
  }
4399
4383
  async reduceMargin(symbol, amount, params = {}) {
4400
4384
  /**
4401
4385
  * @method
4402
4386
  * @name coinex#reduceMargin
4403
4387
  * @description remove margin from a position
4404
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http032_adjust_position_margin
4388
+ * @see https://docs.coinex.com/api/v2/futures/position/http/adjust-position-margin
4405
4389
  * @param {string} symbol unified market symbol
4406
4390
  * @param {float} amount the amount of margin to remove
4407
4391
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4408
4392
  * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=reduce-margin-structure}
4409
4393
  */
4410
- return await this.modifyMarginHelper(symbol, amount, 2, params);
4394
+ return await this.modifyMarginHelper(symbol, amount, 'reduce', params);
4411
4395
  }
4412
4396
  async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
4413
4397
  /**
@@ -5944,71 +5928,66 @@ export default class coinex extends Exchange {
5944
5928
  * @method
5945
5929
  * @name coinex#fetchMarginAdjustmentHistory
5946
5930
  * @description fetches the history of margin added or reduced from contract isolated positions
5947
- * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http046_position_margin_history
5948
- * @param {string} [symbol] unified market symbol
5931
+ * @see https://docs.coinex.com/api/v2/futures/position/http/list-position-margin-history
5932
+ * @param {string} symbol unified market symbol
5949
5933
  * @param {string} [type] not used by coinex fetchMarginAdjustmentHistory
5950
5934
  * @param {int} [since] timestamp in ms of the earliest change to fetch
5951
- * @param {int} [limit] the maximum amount of changes to fetch, default=100, max=100
5935
+ * @param {int} [limit] the maximum amount of changes to fetch, default is 10
5952
5936
  * @param {object} params extra parameters specific to the exchange api endpoint
5953
5937
  * @param {int} [params.until] timestamp in ms of the latest change to fetch
5954
- *
5955
- * EXCHANGE SPECIFIC PARAMETERS
5956
- * @param {int} [params.offset] offset
5938
+ * @param {int} [params.positionId] the id of the position that you want to retrieve margin adjustment history for
5957
5939
  * @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5958
5940
  */
5959
5941
  await this.loadMarkets();
5960
- const until = this.safeInteger(params, 'until');
5961
- params = this.omit(params, 'until');
5962
- if (limit === undefined) {
5963
- limit = 100;
5942
+ if (symbol === undefined) {
5943
+ throw new ArgumentsRequired(this.id + ' fetchMarginAdjustmentHistory() requires a symbol argument');
5964
5944
  }
5965
- const request = {
5966
- 'market': '',
5967
- 'position_id': 0,
5968
- 'offset': 0,
5969
- 'limit': limit,
5970
- };
5971
- if (symbol !== undefined) {
5972
- const market = this.market(symbol);
5973
- request['market'] = market['id'];
5945
+ const positionId = this.safeInteger2(params, 'positionId', 'position_id');
5946
+ params = this.omit(params, 'positionId');
5947
+ if (positionId === undefined) {
5948
+ throw new ArgumentsRequired(this.id + ' fetchMarginAdjustmentHistory() requires a positionId parameter');
5974
5949
  }
5950
+ const market = this.market(symbol);
5951
+ let request = {
5952
+ 'market': market['id'],
5953
+ 'market_type': 'FUTURES',
5954
+ 'position_id': positionId,
5955
+ };
5956
+ [request, params] = this.handleUntilOption('end_time', request, params);
5975
5957
  if (since !== undefined) {
5976
5958
  request['start_time'] = since;
5977
5959
  }
5978
- if (until !== undefined) {
5979
- request['end_time'] = until;
5960
+ if (limit !== undefined) {
5961
+ request['limit'] = limit;
5980
5962
  }
5981
- const response = await this.v1PerpetualPrivateGetPositionMarginHistory(this.extend(request, params));
5963
+ const response = await this.v2PrivateGetFuturesPositionMarginHistory(this.extend(request, params));
5982
5964
  //
5983
- // {
5984
- // code: '0',
5985
- // data: {
5986
- // limit: '100',
5987
- // offset: '0',
5988
- // records: [
5989
- // {
5990
- // bkr_price: '0',
5991
- // leverage: '3',
5992
- // liq_price: '0',
5993
- // margin_amount: '5.33236666666666666666',
5994
- // margin_change: '3',
5995
- // market: 'XRPUSDT',
5996
- // position_amount: '11',
5997
- // position_id: '297155652',
5998
- // position_type: '2',
5999
- // settle_price: '0.6361',
6000
- // time: '1711050906.382891',
6001
- // type: '1',
6002
- // user_id: '3685860'
6003
- // }
6004
- // ]
6005
- // },
6006
- // message: 'OK'
6007
- // }
5965
+ // {
5966
+ // "code": 0,
5967
+ // "data": [
5968
+ // {
5969
+ // "bkr_pirce": "24698.56000000000000005224",
5970
+ // "created_at": 1715489978697,
5971
+ // "leverage": "3",
5972
+ // "liq_price": "24822.67336683417085432386",
5973
+ // "margin_avbl": "3.634928",
5974
+ // "margin_change": "-1.5",
5975
+ // "margin_mode": "isolated",
5976
+ // "market": "BTCUSDT",
5977
+ // "market_type": "FUTURES",
5978
+ // "open_interest": "0.0001",
5979
+ // "position_id": 306458800,
5980
+ // "settle_price": "61047.84"
5981
+ // },
5982
+ // ],
5983
+ // "message": "OK",
5984
+ // "pagination": {
5985
+ // "has_next": true
5986
+ // }
5987
+ // }
6008
5988
  //
6009
- const data = this.safeDict(response, 'data', {});
6010
- const records = this.safeList(data, 'records', []);
6011
- const modifications = this.parseMarginModifications(records, undefined, 'market', 'swap');
5989
+ const data = this.safeList(response, 'data', []);
5990
+ const modifications = this.parseMarginModifications(data, undefined, 'market', 'swap');
6012
5991
  return this.filterBySymbolSinceLimit(modifications, symbol, since, limit);
6013
5992
  }
6014
5993
  }
package/js/src/delta.d.ts CHANGED
@@ -118,7 +118,7 @@ export default class delta extends Exchange {
118
118
  addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
119
119
  reduceMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
120
120
  modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<MarginModification>;
121
- parseMarginModification(data: any, market?: Market): MarginModification;
121
+ parseMarginModification(data: Dict, market?: Market): MarginModification;
122
122
  fetchOpenInterest(symbol: string, params?: {}): Promise<import("./base/types.js").OpenInterest>;
123
123
  parseOpenInterest(interest: any, market?: Market): import("./base/types.js").OpenInterest;
124
124
  fetchLeverage(symbol: string, params?: {}): Promise<Leverage>;
@@ -136,7 +136,7 @@ export default class digifinex extends Exchange {
136
136
  addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
137
137
  reduceMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
138
138
  modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<MarginModification>;
139
- parseMarginModification(data: any, market?: Market): MarginModification;
139
+ parseMarginModification(data: Dict, market?: Market): MarginModification;
140
140
  fetchFundingHistory(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").FundingHistory[]>;
141
141
  parseIncome(income: any, market?: Market): {
142
142
  info: any;
package/js/src/exmo.d.ts CHANGED
@@ -7,7 +7,7 @@ import type { Dict, Int, Order, OrderSide, OrderType, Trade, OrderBook, OHLCV, B
7
7
  export default class exmo extends Exchange {
8
8
  describe(): any;
9
9
  modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<MarginModification>;
10
- parseMarginModification(data: any, market?: Market): MarginModification;
10
+ parseMarginModification(data: Dict, market?: Market): MarginModification;
11
11
  reduceMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
12
12
  addMargin(symbol: string, amount: number, params?: {}): Promise<MarginModification>;
13
13
  fetchTradingFees(params?: {}): Promise<TradingFees>;