ccxt 4.1.58 → 4.1.59

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 (64) hide show
  1. package/README.md +5 -5
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +757 -818
  4. package/dist/ccxt.browser.min.js +2 -2
  5. package/dist/cjs/ccxt.js +1 -19
  6. package/dist/cjs/src/base/Exchange.js +38 -17
  7. package/dist/cjs/src/binance.js +70 -22
  8. package/dist/cjs/src/bitget.js +74 -52
  9. package/dist/cjs/src/bitmart.js +10 -18
  10. package/dist/cjs/src/bitrue.js +1 -1
  11. package/dist/cjs/src/bybit.js +36 -33
  12. package/dist/cjs/src/coinex.js +25 -30
  13. package/dist/cjs/src/htx.js +82 -39
  14. package/dist/cjs/src/kucoin.js +83 -35
  15. package/dist/cjs/src/mexc.js +3 -105
  16. package/dist/cjs/src/okx.js +8 -16
  17. package/dist/cjs/src/pro/bitget.js +7 -0
  18. package/dist/cjs/src/pro/bitmart.js +7 -0
  19. package/dist/cjs/src/pro/bitvavo.js +9 -0
  20. package/dist/cjs/src/pro/bybit.js +9 -0
  21. package/dist/cjs/src/pro/htx.js +16 -5
  22. package/dist/cjs/src/pro/kucoin.js +7 -0
  23. package/dist/cjs/src/pro/mexc.js +9 -0
  24. package/js/ccxt.d.ts +2 -23
  25. package/js/ccxt.js +2 -16
  26. package/js/src/abstract/mexc.d.ts +0 -4
  27. package/js/src/base/Exchange.d.ts +7 -0
  28. package/js/src/base/Exchange.js +38 -17
  29. package/js/src/binance.d.ts +20 -2
  30. package/js/src/binance.js +70 -22
  31. package/js/src/bitget.d.ts +20 -2
  32. package/js/src/bitget.js +74 -52
  33. package/js/src/bitmart.d.ts +2 -2
  34. package/js/src/bitmart.js +10 -18
  35. package/js/src/bitrue.js +1 -1
  36. package/js/src/bybit.d.ts +2 -2
  37. package/js/src/bybit.js +36 -33
  38. package/js/src/coinex.d.ts +2 -2
  39. package/js/src/coinex.js +25 -30
  40. package/js/src/htx.d.ts +5 -3
  41. package/js/src/htx.js +82 -39
  42. package/js/src/kucoin.d.ts +20 -2
  43. package/js/src/kucoin.js +83 -35
  44. package/js/src/mexc.d.ts +0 -11
  45. package/js/src/mexc.js +3 -105
  46. package/js/src/okx.d.ts +18 -2
  47. package/js/src/okx.js +8 -16
  48. package/js/src/pro/bitget.js +7 -0
  49. package/js/src/pro/bitmart.js +7 -0
  50. package/js/src/pro/bitvavo.js +9 -0
  51. package/js/src/pro/bybit.js +9 -0
  52. package/js/src/pro/htx.js +16 -5
  53. package/js/src/pro/kucoin.js +7 -0
  54. package/js/src/pro/mexc.js +9 -0
  55. package/package.json +1 -1
  56. package/skip-tests.json +5 -0
  57. package/js/src/abstract/huobipro.d.ts +0 -547
  58. package/js/src/abstract/huobipro.js +0 -11
  59. package/js/src/abstract/mexc3.d.ts +0 -180
  60. package/js/src/abstract/mexc3.js +0 -11
  61. package/js/src/abstract/okex.d.ts +0 -280
  62. package/js/src/abstract/okex.js +0 -11
  63. package/js/src/abstract/okex5.d.ts +0 -280
  64. package/js/src/abstract/okex5.js +0 -11
package/js/src/bitget.js CHANGED
@@ -33,7 +33,8 @@ export default class bitget extends Exchange {
33
33
  'future': true,
34
34
  'option': false,
35
35
  'addMargin': true,
36
- 'borrowMargin': true,
36
+ 'borrowCrossMargin': true,
37
+ 'borrowIsolatedMargin': true,
37
38
  'cancelAllOrders': true,
38
39
  'cancelOrder': true,
39
40
  'cancelOrders': true,
@@ -97,7 +98,8 @@ export default class bitget extends Exchange {
97
98
  'fetchWithdrawal': false,
98
99
  'fetchWithdrawals': true,
99
100
  'reduceMargin': true,
100
- 'repayMargin': true,
101
+ 'repayCrossMargin': true,
102
+ 'repayIsolatedMargin': true,
101
103
  'setLeverage': true,
102
104
  'setMarginMode': true,
103
105
  'setPositionMode': true,
@@ -6298,18 +6300,15 @@ export default class bitget extends Exchange {
6298
6300
  'info': interest,
6299
6301
  }, market);
6300
6302
  }
6301
- async borrowMargin(code, amount, symbol = undefined, params = {}) {
6303
+ async borrowCrossMargin(code, amount, params = {}) {
6302
6304
  /**
6303
6305
  * @method
6304
- * @name bitget#borrowMargin
6306
+ * @name bitget#borrowCrossMargin
6305
6307
  * @description create a loan to borrow margin
6306
6308
  * @see https://bitgetlimited.github.io/apidoc/en/margin/#cross-borrow
6307
- * @see https://bitgetlimited.github.io/apidoc/en/margin/#isolated-borrow
6308
6309
  * @param {string} code unified currency code of the currency to borrow
6309
6310
  * @param {string} amount the amount to borrow
6310
- * @param {string} [symbol] unified market symbol
6311
6311
  * @param {object} [params] extra parameters specific to the bitget api endpoint
6312
- * @param {string} [params.marginMode] 'isolated' or 'cross', symbol is required for 'isolated'
6313
6312
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6314
6313
  */
6315
6314
  await this.loadMarkets();
@@ -6318,91 +6317,91 @@ export default class bitget extends Exchange {
6318
6317
  'coin': currency['info']['coinName'],
6319
6318
  'borrowAmount': this.currencyToPrecision(code, amount),
6320
6319
  };
6321
- let response = undefined;
6322
- let marginMode = undefined;
6323
- [marginMode, params] = this.handleMarginModeAndParams('borrowMargin', params);
6324
- if ((symbol !== undefined) || (marginMode === 'isolated')) {
6325
- if (symbol === undefined) {
6326
- throw new ArgumentsRequired(this.id + ' borrowMargin() requires a symbol argument');
6327
- }
6328
- const market = this.market(symbol);
6329
- const marketId = market['id'];
6330
- const parts = marketId.split('_');
6331
- const marginMarketId = this.safeStringUpper(parts, 0);
6332
- request['symbol'] = marginMarketId;
6333
- response = await this.privateMarginPostMarginV1IsolatedAccountBorrow(this.extend(request, params));
6334
- }
6335
- else {
6336
- response = await this.privateMarginPostMarginV1CrossAccountBorrow(this.extend(request, params));
6337
- }
6320
+ const response = await this.privateMarginPostMarginV1CrossAccountBorrow(this.extend(request, params));
6338
6321
  //
6339
- // isolated
6322
+ // cross
6340
6323
  //
6341
6324
  // {
6342
6325
  // "code": "00000",
6343
6326
  // "msg": "success",
6344
- // "requestTime": 1697250952516,
6327
+ // "requestTime": 1697251314271,
6345
6328
  // "data": {
6346
6329
  // "clientOid": null,
6347
- // "symbol": "BTCUSDT",
6348
6330
  // "coin": "BTC",
6349
- // "borrowAmount": "0.001"
6331
+ // "borrowAmount": "0.0001"
6350
6332
  // }
6351
6333
  // }
6352
6334
  //
6353
- // cross
6335
+ const data = this.safeValue(response, 'data', {});
6336
+ return this.parseMarginLoan(data, currency);
6337
+ }
6338
+ async borrowIsolatedMargin(symbol, code, amount, params = {}) {
6339
+ /**
6340
+ * @method
6341
+ * @name bitget#borrowIsolatedMargin
6342
+ * @description create a loan to borrow margin
6343
+ * @see https://bitgetlimited.github.io/apidoc/en/margin/#isolated-borrow
6344
+ * @param {string} symbol unified market symbol
6345
+ * @param {string} code unified currency code of the currency to borrow
6346
+ * @param {string} amount the amount to borrow
6347
+ * @param {object} [params] extra parameters specific to the bitget api endpoint
6348
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6349
+ */
6350
+ await this.loadMarkets();
6351
+ const currency = this.currency(code);
6352
+ const market = this.market(symbol);
6353
+ const marketId = market['id'];
6354
+ const parts = marketId.split('_');
6355
+ const marginMarketId = this.safeStringUpper(parts, 0);
6356
+ const request = {
6357
+ 'coin': currency['info']['coinName'],
6358
+ 'borrowAmount': this.currencyToPrecision(code, amount),
6359
+ 'symbol': marginMarketId,
6360
+ };
6361
+ const response = await this.privateMarginPostMarginV1IsolatedAccountBorrow(this.extend(request, params));
6362
+ //
6363
+ // isolated
6354
6364
  //
6355
6365
  // {
6356
6366
  // "code": "00000",
6357
6367
  // "msg": "success",
6358
- // "requestTime": 1697251314271,
6368
+ // "requestTime": 1697250952516,
6359
6369
  // "data": {
6360
6370
  // "clientOid": null,
6371
+ // "symbol": "BTCUSDT",
6361
6372
  // "coin": "BTC",
6362
- // "borrowAmount": "0.0001"
6373
+ // "borrowAmount": "0.001"
6363
6374
  // }
6364
6375
  // }
6365
6376
  //
6366
6377
  const data = this.safeValue(response, 'data', {});
6367
6378
  return this.parseMarginLoan(data, currency);
6368
6379
  }
6369
- async repayMargin(code, amount, symbol = undefined, params = {}) {
6380
+ async repayIsolatedMargin(symbol, code, amount, params = {}) {
6370
6381
  /**
6371
6382
  * @method
6372
- * @name bitget#repayMargin
6383
+ * @name bitget#repayIsolatedMargin
6373
6384
  * @description repay borrowed margin and interest
6374
6385
  * @see https://bitgetlimited.github.io/apidoc/en/margin/#cross-repay
6375
6386
  * @see https://bitgetlimited.github.io/apidoc/en/margin/#isolated-repay
6387
+ * @param {string} symbol unified market symbol
6376
6388
  * @param {string} code unified currency code of the currency to repay
6377
6389
  * @param {string} amount the amount to repay
6378
- * @param {string} [symbol] unified market symbol
6379
6390
  * @param {object} [params] extra parameters specific to the bitget api endpoint
6380
- * @param {string} [params.marginMode] 'isolated' or 'cross', symbol is required for 'isolated'
6381
6391
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6382
6392
  */
6383
6393
  await this.loadMarkets();
6384
6394
  const currency = this.currency(code);
6395
+ const market = this.market(symbol);
6396
+ const marketId = market['id'];
6397
+ const parts = marketId.split('_');
6398
+ const marginMarketId = this.safeStringUpper(parts, 0);
6385
6399
  const request = {
6386
6400
  'coin': currency['info']['coinName'],
6387
6401
  'repayAmount': this.currencyToPrecision(code, amount),
6402
+ 'symbol': marginMarketId,
6388
6403
  };
6389
- let response = undefined;
6390
- let marginMode = undefined;
6391
- [marginMode, params] = this.handleMarginModeAndParams('repayMargin', params);
6392
- if ((symbol !== undefined) || (marginMode === 'isolated')) {
6393
- if (symbol === undefined) {
6394
- throw new ArgumentsRequired(this.id + ' repayMargin() requires a symbol argument');
6395
- }
6396
- const market = this.market(symbol);
6397
- const marketId = market['id'];
6398
- const parts = marketId.split('_');
6399
- const marginMarketId = this.safeStringUpper(parts, 0);
6400
- request['symbol'] = marginMarketId;
6401
- response = await this.privateMarginPostMarginV1IsolatedAccountRepay(this.extend(request, params));
6402
- }
6403
- else {
6404
- response = await this.privateMarginPostMarginV1CrossAccountRepay(this.extend(request, params));
6405
- }
6404
+ const response = await this.privateMarginPostMarginV1IsolatedAccountRepay(this.extend(request, params));
6406
6405
  //
6407
6406
  // isolated
6408
6407
  //
@@ -6419,6 +6418,29 @@ export default class bitget extends Exchange {
6419
6418
  // }
6420
6419
  // }
6421
6420
  //
6421
+ const data = this.safeValue(response, 'data', {});
6422
+ return this.parseMarginLoan(data, currency);
6423
+ }
6424
+ async repayCrossMargin(code, amount, params = {}) {
6425
+ /**
6426
+ * @method
6427
+ * @name bitget#repayCrossMargin
6428
+ * @description repay borrowed margin and interest
6429
+ * @see https://bitgetlimited.github.io/apidoc/en/margin/#cross-repay
6430
+ * @see https://bitgetlimited.github.io/apidoc/en/margin/#isolated-repay
6431
+ * @param {string} code unified currency code of the currency to repay
6432
+ * @param {string} amount the amount to repay
6433
+ * @param {object} [params] extra parameters specific to the bitget api endpoint
6434
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6435
+ */
6436
+ await this.loadMarkets();
6437
+ const currency = this.currency(code);
6438
+ const request = {
6439
+ 'coin': currency['info']['coinName'],
6440
+ 'repayAmount': this.currencyToPrecision(code, amount),
6441
+ };
6442
+ const response = await this.privateMarginPostMarginV1CrossAccountRepay(this.extend(request, params));
6443
+ //
6422
6444
  // cross
6423
6445
  //
6424
6446
  // {
@@ -101,8 +101,8 @@ export default class bitmart extends Exchange {
101
101
  fetchWithdrawals(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Transaction[]>;
102
102
  parseTransactionStatus(status: any): string;
103
103
  parseTransaction(transaction: any, currency?: Currency): Transaction;
104
- repayMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<any>;
105
- borrowMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<any>;
104
+ repayIsolatedMargin(symbol: string, code: string, amount: any, params?: {}): Promise<any>;
105
+ borrowIsolatedMargin(symbol: string, code: string, amount: any, params?: {}): Promise<any>;
106
106
  parseMarginLoan(info: any, currency?: Currency): {
107
107
  id: string;
108
108
  currency: string;
package/js/src/bitmart.js CHANGED
@@ -34,7 +34,8 @@ export default class bitmart extends Exchange {
34
34
  'swap': true,
35
35
  'future': false,
36
36
  'option': false,
37
- 'borrowMargin': true,
37
+ 'borrowCrossMargin': false,
38
+ 'borrowIsolatedMargin': true,
38
39
  'cancelAllOrders': true,
39
40
  'cancelOrder': true,
40
41
  'cancelOrders': false,
@@ -96,7 +97,8 @@ export default class bitmart extends Exchange {
96
97
  'fetchWithdrawal': true,
97
98
  'fetchWithdrawals': true,
98
99
  'reduceMargin': false,
99
- 'repayMargin': true,
100
+ 'repayCrossMargin': false,
101
+ 'repayIsolatedMargin': true,
100
102
  'setLeverage': true,
101
103
  'setMarginMode': false,
102
104
  'transfer': true,
@@ -3200,22 +3202,18 @@ export default class bitmart extends Exchange {
3200
3202
  'fee': fee,
3201
3203
  };
3202
3204
  }
3203
- async repayMargin(code, amount, symbol = undefined, params = {}) {
3205
+ async repayIsolatedMargin(symbol, code, amount, params = {}) {
3204
3206
  /**
3205
3207
  * @method
3206
- * @name bitmart#repayMargin
3208
+ * @name bitmart#repayIsolatedMargin
3207
3209
  * @description repay borrowed margin and interest
3208
3210
  * @see https://developer-pro.bitmart.com/en/spot/#margin-repay-isolated
3211
+ * @param {string} symbol unified market symbol
3209
3212
  * @param {string} code unified currency code of the currency to repay
3210
3213
  * @param {string} amount the amount to repay
3211
- * @param {string} symbol unified market symbol
3212
3214
  * @param {object} [params] extra parameters specific to the bitmart api endpoint
3213
- * @param {string} [params.marginMode] 'isolated' is the default and 'cross' is unavailable
3214
3215
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
3215
3216
  */
3216
- if (symbol === undefined) {
3217
- throw new ArgumentsRequired(this.id + ' repayMargin() requires a symbol argument');
3218
- }
3219
3217
  await this.loadMarkets();
3220
3218
  const market = this.market(symbol);
3221
3219
  const currency = this.currency(code);
@@ -3224,7 +3222,6 @@ export default class bitmart extends Exchange {
3224
3222
  'currency': currency['id'],
3225
3223
  'amount': this.currencyToPrecision(code, amount),
3226
3224
  };
3227
- params = this.omit(params, 'marginMode');
3228
3225
  const response = await this.privatePostSpotV1MarginIsolatedRepay(this.extend(request, params));
3229
3226
  //
3230
3227
  // {
@@ -3243,22 +3240,18 @@ export default class bitmart extends Exchange {
3243
3240
  'symbol': symbol,
3244
3241
  });
3245
3242
  }
3246
- async borrowMargin(code, amount, symbol = undefined, params = {}) {
3243
+ async borrowIsolatedMargin(symbol, code, amount, params = {}) {
3247
3244
  /**
3248
3245
  * @method
3249
- * @name bitmart#borrowMargin
3246
+ * @name bitmart#borrowIsolatedMargin
3250
3247
  * @description create a loan to borrow margin
3251
3248
  * @see https://developer-pro.bitmart.com/en/spot/#margin-borrow-isolated
3249
+ * @param {string} symbol unified market symbol
3252
3250
  * @param {string} code unified currency code of the currency to borrow
3253
3251
  * @param {string} amount the amount to borrow
3254
- * @param {string} symbol unified market symbol
3255
3252
  * @param {object} [params] extra parameters specific to the bitmart api endpoint
3256
- * @param {string} [params.marginMode] 'isolated' is the default and 'cross' is unavailable
3257
3253
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
3258
3254
  */
3259
- if (symbol === undefined) {
3260
- throw new ArgumentsRequired(this.id + ' borrowMargin() requires a symbol argument');
3261
- }
3262
3255
  await this.loadMarkets();
3263
3256
  const market = this.market(symbol);
3264
3257
  const currency = this.currency(code);
@@ -3267,7 +3260,6 @@ export default class bitmart extends Exchange {
3267
3260
  'currency': currency['id'],
3268
3261
  'amount': this.currencyToPrecision(code, amount),
3269
3262
  };
3270
- params = this.omit(params, 'marginMode');
3271
3263
  const response = await this.privatePostSpotV1MarginIsolatedBorrow(this.extend(request, params));
3272
3264
  //
3273
3265
  // {
package/js/src/bitrue.js CHANGED
@@ -96,7 +96,7 @@ export default class bitrue extends Exchange {
96
96
  'kline': 'https://www.bitrue.com/kline-api',
97
97
  },
98
98
  'www': 'https://www.bitrue.com',
99
- 'referral': 'https://www.bitrue.com/activity/task/task-landing?inviteCode=EZWETQE&cn=900000',
99
+ 'referral': 'https://www.bitrue.com/affiliate/landing?cn=600000&inviteCode=EZWETQE',
100
100
  'doc': [
101
101
  'https://github.com/Bitrue-exchange/bitrue-official-api-docs',
102
102
  ],
package/js/src/bybit.d.ts CHANGED
@@ -157,8 +157,8 @@ export default class bybit extends Exchange {
157
157
  };
158
158
  transfer(code: string, amount: any, fromAccount: any, toAccount: any, params?: {}): Promise<any>;
159
159
  fetchTransfers(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
160
- borrowMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<any>;
161
- repayMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<any>;
160
+ borrowCrossMargin(code: string, amount: any, params?: {}): Promise<any>;
161
+ repayCrossMargin(code: string, amount: any, params?: {}): Promise<any>;
162
162
  parseMarginLoan(info: any, currency?: Currency): {
163
163
  id: string;
164
164
  currency: string;
package/js/src/bybit.js CHANGED
@@ -35,6 +35,7 @@ export default class bybit extends Exchange {
35
35
  'swap': true,
36
36
  'future': true,
37
37
  'option': true,
38
+ 'borrowCrossMargin': true,
38
39
  'cancelAllOrders': true,
39
40
  'cancelOrder': true,
40
41
  'createOrder': true,
@@ -97,6 +98,7 @@ export default class bybit extends Exchange {
97
98
  'fetchUnderlyingAssets': false,
98
99
  'fetchVolatilityHistory': true,
99
100
  'fetchWithdrawals': true,
101
+ 'repayCrossMargin': true,
100
102
  'setLeverage': true,
101
103
  'setMarginMode': true,
102
104
  'setPositionMode': true,
@@ -3434,7 +3436,9 @@ export default class bybit extends Exchange {
3434
3436
  const result = await this.fetchOrders(symbol, undefined, undefined, this.extend(request, params));
3435
3437
  const length = result.length;
3436
3438
  if (length === 0) {
3437
- throw new OrderNotFound('Order ' + id.toString() + ' does not exist.');
3439
+ const isTrigger = this.safeValueN(params, ['trigger', 'stop'], false);
3440
+ const extra = isTrigger ? '' : 'If you are trying to fetch SL/TP conditional order, you might try setting params["trigger"] = true';
3441
+ throw new OrderNotFound('Order ' + id.toString() + ' was not found.' + extra);
3438
3442
  }
3439
3443
  if (length > 1) {
3440
3444
  throw new InvalidOrder(this.id + ' returned more than one order');
@@ -3460,7 +3464,7 @@ export default class bybit extends Exchange {
3460
3464
  * @param {boolean} [params.isLeverage] *unified spot only* false then spot trading true then margin trading
3461
3465
  * @param {string} [params.tpslMode] *contract only* 'full' or 'partial'
3462
3466
  * @param {string} [params.mmp] *option only* market maker protection
3463
- * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'up' or 'down'
3467
+ * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'above' or 'below'
3464
3468
  * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
3465
3469
  * @param {float} [params.stopLossPrice] The price at which a stop loss order is triggered at
3466
3470
  * @param {float} [params.takeProfitPrice] The price at which a take profit order is triggered at
@@ -3592,21 +3596,30 @@ export default class bybit extends Exchange {
3592
3596
  const isStopLoss = stopLoss !== undefined;
3593
3597
  const isTakeProfit = takeProfit !== undefined;
3594
3598
  const isBuy = side === 'buy';
3595
- const setTriggerDirection = (stopLossTriggerPrice || triggerPrice) ? !isBuy : isBuy;
3596
- const defaultTriggerDirection = setTriggerDirection ? 2 : 1;
3597
- const triggerDirection = this.safeString(params, 'triggerDirection');
3598
- params = this.omit(params, 'triggerDirection');
3599
- let selectedDirection = defaultTriggerDirection;
3600
- if (triggerDirection !== undefined) {
3601
- const isAsending = ((triggerDirection === 'up') || (triggerDirection === '1'));
3602
- selectedDirection = isAsending ? 1 : 2;
3603
- }
3604
3599
  if (triggerPrice !== undefined) {
3605
- request['triggerDirection'] = selectedDirection;
3600
+ const triggerDirection = this.safeString(params, 'triggerDirection');
3601
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'triggerDirection']);
3602
+ if (market['spot']) {
3603
+ if (triggerDirection !== undefined) {
3604
+ throw new NotSupported(this.id + ' createOrder() : trigger order does not support triggerDirection for spot markets yet');
3605
+ }
3606
+ }
3607
+ else {
3608
+ if (triggerDirection === undefined) {
3609
+ throw new ArgumentsRequired(this.id + ' stop/trigger orders require a triggerDirection parameter, either "above" or "below" to determine the direction of the trigger.');
3610
+ }
3611
+ const isAsending = ((triggerDirection === 'above') || (triggerDirection === '1'));
3612
+ request['triggerDirection'] = isAsending ? 1 : 2;
3613
+ }
3606
3614
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
3607
3615
  }
3608
3616
  else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
3609
- request['triggerDirection'] = selectedDirection;
3617
+ if (isBuy) {
3618
+ request['triggerDirection'] = isStopLossTriggerOrder ? 1 : 2;
3619
+ }
3620
+ else {
3621
+ request['triggerDirection'] = isStopLossTriggerOrder ? 2 : 1;
3622
+ }
3610
3623
  triggerPrice = isStopLossTriggerOrder ? stopLossTriggerPrice : takeProfitTriggerPrice;
3611
3624
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
3612
3625
  request['reduceOnly'] = true;
@@ -4406,8 +4419,8 @@ export default class bybit extends Exchange {
4406
4419
  return await this.fetchUsdcOrders(symbol, since, limit, params);
4407
4420
  }
4408
4421
  request['category'] = type;
4409
- const isStop = this.safeValue(params, 'stop', false);
4410
- params = this.omit(params, ['stop']);
4422
+ const isStop = this.safeValueN(params, ['trigger', 'stop'], false);
4423
+ params = this.omit(params, ['trigger', 'stop']);
4411
4424
  if (isStop) {
4412
4425
  if (type === 'spot') {
4413
4426
  request['orderFilter'] = 'tpslOrder';
@@ -6613,29 +6626,24 @@ export default class bybit extends Exchange {
6613
6626
  const data = this.addPaginationCursorToResult(response);
6614
6627
  return this.parseTransfers(data, currency, since, limit);
6615
6628
  }
6616
- async borrowMargin(code, amount, symbol = undefined, params = {}) {
6629
+ async borrowCrossMargin(code, amount, params = {}) {
6617
6630
  /**
6618
6631
  * @method
6619
- * @name bybit#borrowMargin
6632
+ * @name bybit#borrowCrossMargin
6620
6633
  * @description create a loan to borrow margin
6621
6634
  * @see https://bybit-exchange.github.io/docs/v5/spot-margin-normal/borrow
6622
6635
  * @param {string} code unified currency code of the currency to borrow
6623
6636
  * @param {float} amount the amount to borrow
6624
- * @param {string} symbol not used by bybit.borrowMargin ()
6625
6637
  * @param {object} [params] extra parameters specific to the bybit api endpoint
6626
6638
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6627
6639
  */
6628
6640
  await this.loadMarkets();
6629
6641
  const currency = this.currency(code);
6630
- const [marginMode, query] = this.handleMarginModeAndParams('borrowMargin', params);
6631
- if (marginMode === 'isolated') {
6632
- throw new NotSupported(this.id + ' borrowMargin () cannot use isolated margin');
6633
- }
6634
6642
  const request = {
6635
6643
  'coin': currency['id'],
6636
6644
  'qty': this.currencyToPrecision(code, amount),
6637
6645
  };
6638
- const response = await this.privatePostV5SpotCrossMarginTradeLoan(this.extend(request, query));
6646
+ const response = await this.privatePostV5SpotCrossMarginTradeLoan(this.extend(request, params));
6639
6647
  //
6640
6648
  // {
6641
6649
  // "retCode": 0,
@@ -6650,33 +6658,28 @@ export default class bybit extends Exchange {
6650
6658
  const result = this.safeValue(response, 'result', {});
6651
6659
  const transaction = this.parseMarginLoan(result, currency);
6652
6660
  return this.extend(transaction, {
6653
- 'symbol': symbol,
6661
+ 'symbol': undefined,
6654
6662
  'amount': amount,
6655
6663
  });
6656
6664
  }
6657
- async repayMargin(code, amount, symbol = undefined, params = {}) {
6665
+ async repayCrossMargin(code, amount, params = {}) {
6658
6666
  /**
6659
6667
  * @method
6660
- * @name bybit#repayMargin
6668
+ * @name bybit#repayCrossMargin
6661
6669
  * @description repay borrowed margin and interest
6662
6670
  * @see https://bybit-exchange.github.io/docs/v5/spot-margin-normal/repay
6663
6671
  * @param {string} code unified currency code of the currency to repay
6664
6672
  * @param {float} amount the amount to repay
6665
- * @param {string} symbol not used by bybit.repayMargin ()
6666
6673
  * @param {object} [params] extra parameters specific to the bybit api endpoint
6667
6674
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
6668
6675
  */
6669
6676
  await this.loadMarkets();
6670
6677
  const currency = this.currency(code);
6671
- const [marginMode, query] = this.handleMarginModeAndParams('repayMargin', params);
6672
- if (marginMode === 'isolated') {
6673
- throw new NotSupported(this.id + ' repayMargin () cannot use isolated margin');
6674
- }
6675
6678
  const request = {
6676
6679
  'coin': currency['id'],
6677
6680
  'qty': this.numberToString(amount),
6678
6681
  };
6679
- const response = await this.privatePostV5SpotCrossMarginTradeRepay(this.extend(request, query));
6682
+ const response = await this.privatePostV5SpotCrossMarginTradeRepay(this.extend(request, params));
6680
6683
  //
6681
6684
  // {
6682
6685
  // "retCode": 0,
@@ -6691,7 +6694,7 @@ export default class bybit extends Exchange {
6691
6694
  const result = this.safeValue(response, 'result', {});
6692
6695
  const transaction = this.parseMarginLoan(result, currency);
6693
6696
  return this.extend(transaction, {
6694
- 'symbol': symbol,
6697
+ 'symbol': undefined,
6695
6698
  'amount': amount,
6696
6699
  });
6697
6700
  }
@@ -190,8 +190,8 @@ export default class coinex extends Exchange {
190
190
  datetime: string;
191
191
  info: any;
192
192
  };
193
- borrowMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<any>;
194
- repayMargin(code: string, amount: any, symbol?: Str, params?: {}): Promise<any>;
193
+ borrowIsolatedMargin(symbol: string, code: string, amount: any, params?: {}): Promise<any>;
194
+ repayIsolatedMargin(symbol: string, code: string, amount: any, params?: {}): Promise<any>;
195
195
  parseMarginLoan(info: any, currency?: Currency): {
196
196
  id: number;
197
197
  currency: string;
package/js/src/coinex.js CHANGED
@@ -41,7 +41,8 @@ export default class coinex extends Exchange {
41
41
  'future': false,
42
42
  'option': false,
43
43
  'addMargin': true,
44
- 'borrowMargin': true,
44
+ 'borrowCrossMargin': false,
45
+ 'borrowIsolatedMargin': true,
45
46
  'cancelAllOrders': true,
46
47
  'cancelOrder': true,
47
48
  'createDepositAddress': true,
@@ -94,7 +95,8 @@ export default class coinex extends Exchange {
94
95
  'fetchWithdrawal': false,
95
96
  'fetchWithdrawals': true,
96
97
  'reduceMargin': true,
97
- 'repayMargin': true,
98
+ 'repayCrossMargin': false,
99
+ 'repayIsolatedMargin': true,
98
100
  'setLeverage': true,
99
101
  'setMarginMode': true,
100
102
  'setPositionMode': false,
@@ -3259,16 +3261,19 @@ export default class coinex extends Exchange {
3259
3261
  const maintenanceMargin = this.safeString(position, 'mainten_margin_amount');
3260
3262
  const maintenanceMarginPercentage = this.safeString(position, 'mainten_margin');
3261
3263
  const collateral = this.safeString(position, 'margin_amount');
3262
- const leverage = this.safeNumber(position, 'leverage');
3264
+ const leverage = this.safeString(position, 'leverage');
3265
+ const notional = this.safeString(position, 'open_val');
3266
+ const initialMargin = Precise.stringDiv(notional, leverage);
3267
+ const initialMarginPercentage = Precise.stringDiv('1', leverage);
3263
3268
  return this.safePosition({
3264
3269
  'info': position,
3265
3270
  'id': positionId,
3266
3271
  'symbol': symbol,
3267
- 'notional': undefined,
3272
+ 'notional': this.parseNumber(notional),
3268
3273
  'marginMode': marginMode,
3269
3274
  'liquidationPrice': liquidationPrice,
3270
- 'entryPrice': entryPrice,
3271
- 'unrealizedPnl': unrealizedPnl,
3275
+ 'entryPrice': this.parseNumber(entryPrice),
3276
+ 'unrealizedPnl': this.parseNumber(unrealizedPnl),
3272
3277
  'percentage': undefined,
3273
3278
  'contracts': contracts,
3274
3279
  'contractSize': this.safeNumber(market, 'contractSize'),
@@ -3279,15 +3284,15 @@ export default class coinex extends Exchange {
3279
3284
  'timestamp': timestamp,
3280
3285
  'datetime': this.iso8601(timestamp),
3281
3286
  'lastUpdateTimestamp': undefined,
3282
- 'maintenanceMargin': maintenanceMargin,
3283
- 'maintenanceMarginPercentage': maintenanceMarginPercentage,
3284
- 'collateral': collateral,
3285
- 'initialMargin': undefined,
3286
- 'initialMarginPercentage': undefined,
3287
- 'leverage': leverage,
3287
+ 'maintenanceMargin': this.parseNumber(maintenanceMargin),
3288
+ 'maintenanceMarginPercentage': this.parseNumber(maintenanceMarginPercentage),
3289
+ 'collateral': this.parseNumber(collateral),
3290
+ 'initialMargin': this.parseNumber(initialMargin),
3291
+ 'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
3292
+ 'leverage': this.parseNumber(leverage),
3288
3293
  'marginRatio': undefined,
3289
- 'stopLossPrice': this.safeNumber(position, 'stop_loss_price'),
3290
- 'takeProfitPrice': this.safeNumber(position, 'take_profit_price'),
3294
+ 'stopLossPrice': this.omitZero(this.safeString(position, 'stop_loss_price')),
3295
+ 'takeProfitPrice': this.omitZero(this.safeString(position, 'take_profit_price')),
3291
3296
  });
3292
3297
  }
3293
3298
  async setMarginMode(marginMode, symbol = undefined, params = {}) {
@@ -4606,21 +4611,18 @@ export default class coinex extends Exchange {
4606
4611
  'info': info,
4607
4612
  };
4608
4613
  }
4609
- async borrowMargin(code, amount, symbol = undefined, params = {}) {
4614
+ async borrowIsolatedMargin(symbol, code, amount, params = {}) {
4610
4615
  /**
4611
4616
  * @method
4612
- * @name coinex#borrowMargin
4617
+ * @name coinex#borrowIsolatedMargin
4613
4618
  * @description create a loan to borrow margin
4614
4619
  * @see https://github.com/coinexcom/coinex_exchange_api/wiki/086margin_loan
4620
+ * @param {string} symbol unified market symbol, required for coinex
4615
4621
  * @param {string} code unified currency code of the currency to borrow
4616
4622
  * @param {float} amount the amount to borrow
4617
- * @param {string} symbol unified market symbol, required for coinex
4618
4623
  * @param {object} [params] extra parameters specific to the coinex api endpoint
4619
4624
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
4620
4625
  */
4621
- if (symbol === undefined) {
4622
- throw new ArgumentsRequired(this.id + ' borrowMargin() requires a symbol argument');
4623
- }
4624
4626
  await this.loadMarkets();
4625
4627
  const market = this.market(symbol);
4626
4628
  const currency = this.currency(code);
@@ -4646,22 +4648,19 @@ export default class coinex extends Exchange {
4646
4648
  'symbol': symbol,
4647
4649
  });
4648
4650
  }
4649
- async repayMargin(code, amount, symbol = undefined, params = {}) {
4651
+ async repayIsolatedMargin(symbol, code, amount, params = {}) {
4650
4652
  /**
4651
4653
  * @method
4652
- * @name coinex#repayMargin
4654
+ * @name coinex#repayIsolatedMargin
4653
4655
  * @description repay borrowed margin and interest
4654
4656
  * @see https://github.com/coinexcom/coinex_exchange_api/wiki/087margin_flat
4657
+ * @param {string} symbol unified market symbol, required for coinex
4655
4658
  * @param {string} code unified currency code of the currency to repay
4656
4659
  * @param {float} amount the amount to repay
4657
- * @param {string} symbol unified market symbol, required for coinex
4658
4660
  * @param {object} [params] extra parameters specific to the coinex api endpoint
4659
4661
  * @param {string} [params.loan_id] extra parameter that is not required
4660
4662
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
4661
4663
  */
4662
- if (symbol === undefined) {
4663
- throw new ArgumentsRequired(this.id + ' repayMargin() requires a symbol argument');
4664
- }
4665
4664
  await this.loadMarkets();
4666
4665
  const market = this.market(symbol);
4667
4666
  const currency = this.currency(code);
@@ -4670,10 +4669,6 @@ export default class coinex extends Exchange {
4670
4669
  'coin_type': currency['id'],
4671
4670
  'amount': this.currencyToPrecision(code, amount),
4672
4671
  };
4673
- const loanId = this.safeInteger(params, 'loan_id');
4674
- if (loanId !== undefined) {
4675
- request['loan_id'] = loanId;
4676
- }
4677
4672
  const response = await this.privatePostMarginFlat(this.extend(request, params));
4678
4673
  //
4679
4674
  // {