ccxt 4.5.26 → 4.5.28

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 (60) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +4 -1
  4. package/dist/cjs/src/abstract/zebpay.js +11 -0
  5. package/dist/cjs/src/base/Exchange.js +2 -2
  6. package/dist/cjs/src/binance.js +18 -7
  7. package/dist/cjs/src/bingx.js +5 -5
  8. package/dist/cjs/src/bitget.js +18 -17
  9. package/dist/cjs/src/bitmex.js +5 -1
  10. package/dist/cjs/src/blofin.js +5 -5
  11. package/dist/cjs/src/bybit.js +58 -29
  12. package/dist/cjs/src/coincatch.js +9 -9
  13. package/dist/cjs/src/coinex.js +93 -0
  14. package/dist/cjs/src/coinmate.js +20 -0
  15. package/dist/cjs/src/coinsph.js +23 -0
  16. package/dist/cjs/src/cryptocom.js +7 -0
  17. package/dist/cjs/src/gate.js +2 -0
  18. package/dist/cjs/src/hyperliquid.js +12 -15
  19. package/dist/cjs/src/pro/binance.js +1 -1
  20. package/dist/cjs/src/pro/bybit.js +1 -1
  21. package/dist/cjs/src/whitebit.js +4 -2
  22. package/dist/cjs/src/zebpay.js +1908 -0
  23. package/js/ccxt.d.ts +5 -2
  24. package/js/ccxt.js +4 -2
  25. package/js/src/abstract/binance.d.ts +3 -1
  26. package/js/src/abstract/binancecoinm.d.ts +3 -1
  27. package/js/src/abstract/binanceus.d.ts +3 -1
  28. package/js/src/abstract/binanceusdm.d.ts +3 -1
  29. package/js/src/abstract/coinex.d.ts +16 -0
  30. package/js/src/abstract/coinmate.d.ts +3 -0
  31. package/js/src/abstract/coinsph.d.ts +21 -0
  32. package/js/src/abstract/cryptocom.d.ts +7 -0
  33. package/js/src/abstract/gate.d.ts +2 -0
  34. package/js/src/abstract/gateio.d.ts +2 -0
  35. package/js/src/abstract/zebpay.d.ts +49 -0
  36. package/js/src/abstract/zebpay.js +11 -0
  37. package/js/src/base/Exchange.js +2 -2
  38. package/js/src/binance.d.ts +1 -0
  39. package/js/src/binance.js +18 -7
  40. package/js/src/bingx.js +5 -5
  41. package/js/src/bitget.js +19 -18
  42. package/js/src/bitmex.js +5 -1
  43. package/js/src/blofin.js +5 -5
  44. package/js/src/bybit.d.ts +3 -0
  45. package/js/src/bybit.js +58 -29
  46. package/js/src/coincatch.js +9 -9
  47. package/js/src/coinex.d.ts +11 -0
  48. package/js/src/coinex.js +93 -0
  49. package/js/src/coinmate.d.ts +9 -0
  50. package/js/src/coinmate.js +20 -0
  51. package/js/src/coinsph.js +23 -0
  52. package/js/src/cryptocom.js +7 -0
  53. package/js/src/gate.js +2 -0
  54. package/js/src/hyperliquid.js +12 -15
  55. package/js/src/pro/binance.js +1 -1
  56. package/js/src/pro/bybit.js +1 -1
  57. package/js/src/whitebit.js +4 -2
  58. package/js/src/zebpay.d.ts +361 -0
  59. package/js/src/zebpay.js +1907 -0
  60. package/package.json +1 -1
package/dist/cjs/ccxt.js CHANGED
@@ -116,6 +116,7 @@ var woofipro = require('./src/woofipro.js');
116
116
  var xt = require('./src/xt.js');
117
117
  var yobit = require('./src/yobit.js');
118
118
  var zaif = require('./src/zaif.js');
119
+ var zebpay = require('./src/zebpay.js');
119
120
  var zonda = require('./src/zonda.js');
120
121
  var alpaca$1 = require('./src/pro/alpaca.js');
121
122
  var apex$1 = require('./src/pro/apex.js');
@@ -196,7 +197,7 @@ var xt$1 = require('./src/pro/xt.js');
196
197
 
197
198
  //-----------------------------------------------------------------------------
198
199
  // this is updated by vss.js when building
199
- const version = '4.5.26';
200
+ const version = '4.5.28';
200
201
  Exchange["default"].ccxtVersion = version;
201
202
  const exchanges = {
202
203
  'alpaca': alpaca["default"],
@@ -307,6 +308,7 @@ const exchanges = {
307
308
  'xt': xt["default"],
308
309
  'yobit': yobit["default"],
309
310
  'zaif': zaif["default"],
311
+ 'zebpay': zebpay["default"],
310
312
  'zonda': zonda["default"],
311
313
  };
312
314
  const pro = {
@@ -546,6 +548,7 @@ exports.woofipro = woofipro["default"];
546
548
  exports.xt = xt["default"];
547
549
  exports.yobit = yobit["default"];
548
550
  exports.zaif = zaif["default"];
551
+ exports.zebpay = zebpay["default"];
549
552
  exports.zonda = zonda["default"];
550
553
  exports["default"] = ccxt;
551
554
  exports.exchanges = exchanges;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Exchange$1 = require('../base/Exchange.js');
6
+
7
+ // ----------------------------------------------------------------------------
8
+ class Exchange extends Exchange$1["default"] {
9
+ }
10
+
11
+ exports["default"] = Exchange;
@@ -4999,8 +4999,8 @@ class Exchange {
4999
4999
  throw new errors.NotSupported(this.id + ' fetchLedgerEntry() is not supported yet');
5000
5000
  }
5001
5001
  parseBidAsk(bidask, priceKey = 0, amountKey = 1, countOrIdKey = 2) {
5002
- const price = this.safeNumber(bidask, priceKey);
5003
- const amount = this.safeNumber(bidask, amountKey);
5002
+ const price = this.safeFloat(bidask, priceKey);
5003
+ const amount = this.safeFloat(bidask, amountKey);
5004
5004
  const countOrId = this.safeInteger(bidask, countOrIdKey);
5005
5005
  const bidAsk = [price, amount];
5006
5006
  if (countOrId !== undefined) {
@@ -849,6 +849,8 @@ class binance extends binance$1["default"] {
849
849
  'lvtKlines': 1,
850
850
  'convert/exchangeInfo': 4,
851
851
  'insuranceBalance': 1,
852
+ 'symbolAdlRisk': 1,
853
+ 'tradingSchedule': 5,
852
854
  },
853
855
  },
854
856
  'fapiData': {
@@ -880,7 +882,6 @@ class binance extends binance$1["default"] {
880
882
  'commissionRate': 20,
881
883
  'rateLimit/order': 1,
882
884
  'apiTradingStatus': 1,
883
- 'symbolAdlRisk': 1,
884
885
  'multiAssetsMargin': 30,
885
886
  // broker endpoints
886
887
  'apiReferral/ifNewUser': 1,
@@ -908,6 +909,7 @@ class binance extends binance$1["default"] {
908
909
  'algoOrder': 1,
909
910
  'openAlgoOrders': { 'cost': 1, 'noSymbol': 40 },
910
911
  'allAlgoOrders': 5,
912
+ 'stock/contract': 50,
911
913
  },
912
914
  'post': {
913
915
  'batchOrders': 5,
@@ -2627,7 +2629,8 @@ class binance extends binance$1["default"] {
2627
2629
  },
2628
2630
  'broad': {
2629
2631
  'has no operation privilege': errors.PermissionDenied,
2630
- 'MAX_POSITION': errors.BadRequest, // {"code":-2010,"msg":"Filter failure: MAX_POSITION"}
2632
+ 'MAX_POSITION': errors.BadRequest,
2633
+ 'PERCENT_PRICE_BY_SIDE': errors.InvalidOrder, // {"code":-1013,"msg":"Filter failure: PERCENT_PRICE_BY_SIDE"}
2631
2634
  },
2632
2635
  },
2633
2636
  });
@@ -5664,6 +5667,17 @@ class binance extends binance$1["default"] {
5664
5667
  };
5665
5668
  return this.safeString(statuses, status, status);
5666
5669
  }
5670
+ parseOrderType(type) {
5671
+ const types = {
5672
+ 'limit_maker': 'limit',
5673
+ 'stop': 'limit',
5674
+ 'stop_market': 'market',
5675
+ 'take_profit': 'limit',
5676
+ 'take_profit_market': 'market',
5677
+ 'trailing_stop_market': 'market',
5678
+ };
5679
+ return this.safeString(types, type, type);
5680
+ }
5667
5681
  parseOrder(order, market = undefined) {
5668
5682
  //
5669
5683
  // spot
@@ -6220,7 +6234,7 @@ class binance extends binance$1["default"] {
6220
6234
  // Note this is not the actual cost, since Binance futures uses leverage to calculate margins.
6221
6235
  let cost = this.safeString2(order, 'cummulativeQuoteQty', 'cumQuote');
6222
6236
  cost = this.safeString(order, 'cumBase', cost);
6223
- let type = this.safeStringLower(order, 'type');
6237
+ const type = this.safeStringLower2(order, 'type', 'orderType');
6224
6238
  const side = this.safeStringLower(order, 'side');
6225
6239
  const fills = this.safeList(order, 'fills', []);
6226
6240
  let timeInForce = this.safeString(order, 'timeInForce');
@@ -6229,9 +6243,6 @@ class binance extends binance$1["default"] {
6229
6243
  timeInForce = 'PO';
6230
6244
  }
6231
6245
  const postOnly = (type === 'limit_maker') || (timeInForce === 'PO');
6232
- if (type === 'limit_maker') {
6233
- type = 'limit';
6234
- }
6235
6246
  const stopPriceString = this.safeString2(order, 'stopPrice', 'triggerPrice');
6236
6247
  const triggerPrice = this.parseNumber(this.omitZero(stopPriceString));
6237
6248
  const feeCost = this.safeNumber(order, 'fee');
@@ -6252,7 +6263,7 @@ class binance extends binance$1["default"] {
6252
6263
  'lastTradeTimestamp': lastTradeTimestamp,
6253
6264
  'lastUpdateTimestamp': lastUpdateTimestamp,
6254
6265
  'symbol': symbol,
6255
- 'type': type,
6266
+ 'type': this.parseOrderType(type),
6256
6267
  'timeInForce': timeInForce,
6257
6268
  'postOnly': postOnly,
6258
6269
  'reduceOnly': this.safeBool(order, 'reduceOnly'),
@@ -3033,8 +3033,8 @@ class bingx extends bingx$1["default"] {
3033
3033
  const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
3034
3034
  const stopLoss = this.safeValue(params, 'stopLoss');
3035
3035
  const takeProfit = this.safeValue(params, 'takeProfit');
3036
- const isStopLoss = stopLoss !== undefined;
3037
- const isTakeProfit = takeProfit !== undefined;
3036
+ const hasStopLoss = stopLoss !== undefined;
3037
+ const hasTakeProfit = takeProfit !== undefined;
3038
3038
  if (((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) && !isTrailing) {
3039
3039
  request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
3040
3040
  }
@@ -3080,9 +3080,9 @@ class bingx extends bingx$1["default"] {
3080
3080
  request['priceRate'] = this.parseToNumeric(requestTrailingPercent);
3081
3081
  }
3082
3082
  }
3083
- if (isStopLoss || isTakeProfit) {
3083
+ if (hasStopLoss || hasTakeProfit) {
3084
3084
  const stringifiedAmount = this.numberToString(amount);
3085
- if (isStopLoss) {
3085
+ if (hasStopLoss) {
3086
3086
  const slTriggerPrice = this.safeString2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss);
3087
3087
  const slWorkingType = this.safeString(stopLoss, 'workingType', 'MARK_PRICE');
3088
3088
  const slType = this.safeString(stopLoss, 'type', 'STOP_MARKET');
@@ -3099,7 +3099,7 @@ class bingx extends bingx$1["default"] {
3099
3099
  slRequest['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, slQuantity));
3100
3100
  request['stopLoss'] = this.json(slRequest);
3101
3101
  }
3102
- if (isTakeProfit) {
3102
+ if (hasTakeProfit) {
3103
3103
  const tkTriggerPrice = this.safeString2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit);
3104
3104
  const tkWorkingType = this.safeString(takeProfit, 'workingType', 'MARK_PRICE');
3105
3105
  const tpType = this.safeString(takeProfit, 'type', 'TAKE_PROFIT_MARKET');
@@ -1410,6 +1410,7 @@ class bitget extends bitget$1["default"] {
1410
1410
  'invalid end time': errors.BadRequest,
1411
1411
  '20003': errors.ExchangeError,
1412
1412
  '01001': errors.ExchangeError,
1413
+ '40024': errors.RestrictedLocation,
1413
1414
  '43111': errors.PermissionDenied, // {"code":"43111","msg":"参数错误 address not in address book","requestTime":1665394201164,"data":null}
1414
1415
  },
1415
1416
  'broad': {
@@ -5181,8 +5182,8 @@ class bitget extends bitget$1["default"] {
5181
5182
  const takeProfitTriggerPrice = this.safeNumber(params, 'takeProfitPrice');
5182
5183
  const stopLoss = this.safeValue(params, 'stopLoss');
5183
5184
  const takeProfit = this.safeValue(params, 'takeProfit');
5184
- const isStopLoss = stopLoss !== undefined;
5185
- const isTakeProfit = takeProfit !== undefined;
5185
+ const hasStopLoss = stopLoss !== undefined;
5186
+ const hasTakeProfit = takeProfit !== undefined;
5186
5187
  const isStopLossTrigger = stopLossTriggerPrice !== undefined;
5187
5188
  const isTakeProfitTrigger = takeProfitTriggerPrice !== undefined;
5188
5189
  const isStopLossOrTakeProfitTrigger = isStopLossTrigger || isTakeProfitTrigger;
@@ -5214,7 +5215,7 @@ class bitget extends bitget$1["default"] {
5214
5215
  params = this.omit(params, ['stopLossPrice', 'takeProfitPrice']);
5215
5216
  }
5216
5217
  else {
5217
- if (isStopLoss) {
5218
+ if (hasStopLoss) {
5218
5219
  const slTriggerPrice = this.safeNumber2(stopLoss, 'triggerPrice', 'stopPrice');
5219
5220
  const slLimitPrice = this.safeNumber(stopLoss, 'price');
5220
5221
  request['stopLoss'] = this.priceToPrecision(symbol, slTriggerPrice);
@@ -5226,7 +5227,7 @@ class bitget extends bitget$1["default"] {
5226
5227
  request['slOrderType'] = this.safeString(params, 'slOrderType', 'market');
5227
5228
  }
5228
5229
  }
5229
- if (isTakeProfit) {
5230
+ if (hasTakeProfit) {
5230
5231
  const tpTriggerPrice = this.safeNumber2(takeProfit, 'triggerPrice', 'stopPrice');
5231
5232
  const tpLimitPrice = this.safeNumber(takeProfit, 'price');
5232
5233
  request['takeProfit'] = this.priceToPrecision(symbol, tpTriggerPrice);
@@ -5309,10 +5310,10 @@ class bitget extends bitget$1["default"] {
5309
5310
  const isTriggerOrder = triggerPrice !== undefined;
5310
5311
  const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
5311
5312
  const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
5312
- const isStopLoss = stopLoss !== undefined;
5313
- const isTakeProfit = takeProfit !== undefined;
5313
+ const hasStopLoss = stopLoss !== undefined;
5314
+ const hasTakeProfit = takeProfit !== undefined;
5314
5315
  const isStopLossOrTakeProfitTrigger = isStopLossTriggerOrder || isTakeProfitTriggerOrder;
5315
- const isStopLossOrTakeProfit = isStopLoss || isTakeProfit;
5316
+ const isStopLossOrTakeProfit = hasStopLoss || hasTakeProfit;
5316
5317
  const trailingTriggerPrice = this.safeString(params, 'trailingTriggerPrice', this.numberToString(price));
5317
5318
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
5318
5319
  const isTrailingPercentOrder = trailingPercent !== undefined;
@@ -5372,7 +5373,7 @@ class bitget extends bitget$1["default"] {
5372
5373
  if (price !== undefined) {
5373
5374
  request['executePrice'] = this.priceToPrecision(symbol, price);
5374
5375
  }
5375
- if (isStopLoss) {
5376
+ if (hasStopLoss) {
5376
5377
  const slTriggerPrice = this.safeString2(stopLoss, 'triggerPrice', 'stopPrice');
5377
5378
  request['stopLossTriggerPrice'] = this.priceToPrecision(symbol, slTriggerPrice);
5378
5379
  const slPrice = this.safeString(stopLoss, 'price');
@@ -5380,7 +5381,7 @@ class bitget extends bitget$1["default"] {
5380
5381
  const slType = this.safeString(stopLoss, 'type', 'mark_price');
5381
5382
  request['stopLossTriggerType'] = slType;
5382
5383
  }
5383
- if (isTakeProfit) {
5384
+ if (hasTakeProfit) {
5384
5385
  const tpTriggerPrice = this.safeString2(takeProfit, 'triggerPrice', 'stopPrice');
5385
5386
  request['stopSurplusTriggerPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
5386
5387
  const tpPrice = this.safeString(takeProfit, 'price');
@@ -5409,11 +5410,11 @@ class bitget extends bitget$1["default"] {
5409
5410
  }
5410
5411
  }
5411
5412
  else {
5412
- if (isStopLoss) {
5413
+ if (hasStopLoss) {
5413
5414
  const slTriggerPrice = this.safeValue2(stopLoss, 'triggerPrice', 'stopPrice');
5414
5415
  request['presetStopLossPrice'] = this.priceToPrecision(symbol, slTriggerPrice);
5415
5416
  }
5416
- if (isTakeProfit) {
5417
+ if (hasTakeProfit) {
5417
5418
  const tpTriggerPrice = this.safeValue2(takeProfit, 'triggerPrice', 'stopPrice');
5418
5419
  request['presetStopSurplusPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
5419
5420
  }
@@ -5732,8 +5733,8 @@ class bitget extends bitget$1["default"] {
5732
5733
  const isTakeProfitOrder = takeProfitPrice !== undefined;
5733
5734
  const stopLoss = this.safeValue(params, 'stopLoss');
5734
5735
  const takeProfit = this.safeValue(params, 'takeProfit');
5735
- const isStopLoss = stopLoss !== undefined;
5736
- const isTakeProfit = takeProfit !== undefined;
5736
+ const hasStopLoss = stopLoss !== undefined;
5737
+ const hasTakeProfit = takeProfit !== undefined;
5737
5738
  const trailingTriggerPrice = this.safeString(params, 'trailingTriggerPrice', this.numberToString(price));
5738
5739
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'newCallbackRatio');
5739
5740
  const isTrailingPercentOrder = trailingPercent !== undefined;
@@ -5857,7 +5858,7 @@ class bitget extends bitget$1["default"] {
5857
5858
  }
5858
5859
  else if (isTriggerOrder) {
5859
5860
  request['newTriggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
5860
- if (isStopLoss) {
5861
+ if (hasStopLoss) {
5861
5862
  const slTriggerPrice = this.safeNumber2(stopLoss, 'triggerPrice', 'stopPrice');
5862
5863
  request['newStopLossTriggerPrice'] = this.priceToPrecision(symbol, slTriggerPrice);
5863
5864
  const slPrice = this.safeNumber(stopLoss, 'price');
@@ -5865,7 +5866,7 @@ class bitget extends bitget$1["default"] {
5865
5866
  const slType = this.safeString(stopLoss, 'type', 'mark_price');
5866
5867
  request['newStopLossTriggerType'] = slType;
5867
5868
  }
5868
- if (isTakeProfit) {
5869
+ if (hasTakeProfit) {
5869
5870
  const tpTriggerPrice = this.safeNumber2(takeProfit, 'triggerPrice', 'stopPrice');
5870
5871
  request['newSurplusTriggerPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
5871
5872
  const tpPrice = this.safeNumber(takeProfit, 'price');
@@ -5880,11 +5881,11 @@ class bitget extends bitget$1["default"] {
5880
5881
  const newClientOrderId = this.safeString2(params, 'newClientOid', 'newClientOrderId', defaultNewClientOrderId);
5881
5882
  params = this.omit(params, 'newClientOrderId');
5882
5883
  request['newClientOid'] = newClientOrderId;
5883
- if (isStopLoss) {
5884
+ if (hasStopLoss) {
5884
5885
  const slTriggerPrice = this.safeValue2(stopLoss, 'triggerPrice', 'stopPrice');
5885
5886
  request['newPresetStopLossPrice'] = this.priceToPrecision(symbol, slTriggerPrice);
5886
5887
  }
5887
- if (isTakeProfit) {
5888
+ if (hasTakeProfit) {
5888
5889
  const tpTriggerPrice = this.safeValue2(takeProfit, 'triggerPrice', 'stopPrice');
5889
5890
  request['newPresetStopSurplusPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
5890
5891
  }
@@ -706,7 +706,7 @@ class bitmex extends bitmex$1["default"] {
706
706
  // 'positionCurrency' may be empty ("", as Bitmex currently returns for ETHUSD)
707
707
  // so let's take the settlCurrency first and then adjust if needed
708
708
  const typ = this.safeString(market, 'typ'); // type definitions at: https://www.bitmex.com/api/explorer/#!/Instrument/Instrument_get
709
- let type;
709
+ let type = undefined;
710
710
  let swap = false;
711
711
  let spot = false;
712
712
  let future = false;
@@ -729,6 +729,10 @@ class bitmex extends bitmex$1["default"] {
729
729
  type = 'future';
730
730
  future = true;
731
731
  }
732
+ else if (typ === 'FFSCSX') {
733
+ type = 'swap';
734
+ swap = true;
735
+ }
732
736
  const base = this.safeCurrencyCode(baseId);
733
737
  const quote = this.safeCurrencyCode(quoteId);
734
738
  const contract = swap || future;
@@ -1191,16 +1191,16 @@ class blofin extends blofin$1["default"] {
1191
1191
  const stopLoss = this.safeDict(params, 'stopLoss');
1192
1192
  const takeProfit = this.safeDict(params, 'takeProfit');
1193
1193
  params = this.omit(params, ['stopLoss', 'takeProfit', 'hedged']);
1194
- const isStopLoss = stopLoss !== undefined;
1195
- const isTakeProfit = takeProfit !== undefined;
1196
- if (isStopLoss || isTakeProfit) {
1197
- if (isStopLoss) {
1194
+ const hasStopLoss = stopLoss !== undefined;
1195
+ const hasTakeProfit = takeProfit !== undefined;
1196
+ if (hasStopLoss || hasTakeProfit) {
1197
+ if (hasStopLoss) {
1198
1198
  const slTriggerPrice = this.safeString2(stopLoss, 'triggerPrice', 'stopPrice');
1199
1199
  request['slTriggerPrice'] = this.priceToPrecision(symbol, slTriggerPrice);
1200
1200
  const slOrderPrice = this.safeString(stopLoss, 'price', '-1');
1201
1201
  request['slOrderPrice'] = this.priceToPrecision(symbol, slOrderPrice);
1202
1202
  }
1203
- if (isTakeProfit) {
1203
+ if (hasTakeProfit) {
1204
1204
  const tpTriggerPrice = this.safeString2(takeProfit, 'triggerPrice', 'stopPrice');
1205
1205
  request['tpTriggerPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
1206
1206
  const tpPrice = this.safeString(takeProfit, 'price', '-1');
@@ -3987,13 +3987,16 @@ class bybit extends bybit$1["default"] {
3987
3987
  * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'ascending' or 'descending'
3988
3988
  * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
3989
3989
  * @param {float} [params.stopLossPrice] The price at which a stop loss order is triggered at
3990
+ * @param {float} [params.stopLossLimitPrice] The limit price for a stoploss order (only when used in OCO with takeProfitPrice)
3990
3991
  * @param {float} [params.takeProfitPrice] The price at which a take profit order is triggered at
3992
+ * @param {float} [params.takeProfitLimitPrice] The limit price for a takeprofit order (only when used in OCO combination with stopLossPrice)
3991
3993
  * @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
3992
3994
  * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
3993
3995
  * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
3994
3996
  * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
3995
3997
  * @param {string} [params.trailingAmount] the quote amount to trail away from the current market price
3996
3998
  * @param {string} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
3999
+ * @param {boolean} [params.tradingStopEndpoint] whether to enforce using the tradingStop (https://bybit-exchange.github.io/docs/v5/position/trading-stop) endpoint, makes difference when submitting single tp/sl order
3997
4000
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3998
4001
  */
3999
4002
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
@@ -4005,8 +4008,9 @@ class bybit extends bybit$1["default"] {
4005
4008
  const isStopLossOrder = this.safeString(params, 'stopLossPrice') !== undefined;
4006
4009
  const isTakeProfitOrder = this.safeString(params, 'takeProfitPrice') !== undefined;
4007
4010
  const orderRequest = this.createOrderRequest(symbol, type, side, amount, price, params, enableUnifiedAccount);
4011
+ const switchToOco = (isStopLossOrder && isTakeProfitOrder) || this.safeBool(params, 'tradingStopEndpoint', false);
4008
4012
  let defaultMethod = undefined;
4009
- if ((isTrailingOrder || isStopLossOrder || isTakeProfitOrder) && !market['spot']) {
4013
+ if ((isTrailingOrder || switchToOco) && !market['spot']) {
4010
4014
  defaultMethod = 'privatePostV5PositionTradingStop';
4011
4015
  }
4012
4016
  else {
@@ -4019,7 +4023,7 @@ class bybit extends bybit$1["default"] {
4019
4023
  response = await this.privatePostV5PositionTradingStop(orderRequest);
4020
4024
  }
4021
4025
  else {
4022
- response = await this.privatePostV5OrderCreate(orderRequest); // already extended inside createOrderRequest
4026
+ response = await this.privatePostV5OrderCreate(orderRequest);
4023
4027
  }
4024
4028
  //
4025
4029
  // {
@@ -4040,9 +4044,6 @@ class bybit extends bybit$1["default"] {
4040
4044
  const market = this.market(symbol);
4041
4045
  symbol = market['symbol'];
4042
4046
  const lowerCaseType = type.toLowerCase();
4043
- if ((price === undefined) && (lowerCaseType === 'limit')) {
4044
- throw new errors.ArgumentsRequired(this.id + ' createOrder requires a price argument for limit orders');
4045
- }
4046
4047
  const request = {
4047
4048
  'symbol': market['id'],
4048
4049
  // 'side': this.capitalize (side),
@@ -4082,12 +4083,13 @@ class bybit extends bybit$1["default"] {
4082
4083
  const isStopLossOrder = stopLossTriggerPrice !== undefined;
4083
4084
  const isTakeProfitOrder = takeProfitTriggerPrice !== undefined;
4084
4085
  const hasStopLoss = stopLoss !== undefined;
4085
- const isTakeProfit = takeProfit !== undefined;
4086
+ const hasTakeProfit = takeProfit !== undefined;
4086
4087
  const isMarket = lowerCaseType === 'market';
4087
4088
  const isLimit = lowerCaseType === 'limit';
4088
4089
  const isBuy = side === 'buy';
4090
+ const switchToOco = (isStopLossOrder && isTakeProfitOrder) || this.safeBool(params, 'tradingStopEndpoint', false);
4089
4091
  let defaultMethod = undefined;
4090
- if ((isTrailingOrder || isStopLossOrder || isTakeProfitOrder) && !market['spot']) {
4092
+ if (isTrailingOrder || switchToOco) {
4091
4093
  defaultMethod = 'privatePostV5PositionTradingStop';
4092
4094
  }
4093
4095
  else {
@@ -4096,40 +4098,67 @@ class bybit extends bybit$1["default"] {
4096
4098
  let method = undefined;
4097
4099
  [method, params] = this.handleOptionAndParams(params, 'createOrder', 'method', defaultMethod);
4098
4100
  const endpointIsTradingStop = method === 'privatePostV5PositionTradingStop';
4099
- const amountString = this.getAmount(symbol, amount);
4101
+ if ((price === undefined) && (lowerCaseType === 'limit') && !endpointIsTradingStop) {
4102
+ throw new errors.ArgumentsRequired(this.id + ' createOrder requires a price argument for limit orders');
4103
+ }
4104
+ // workaround, bcz for some langs we have to allow 0.0 as input (bcz of type)
4105
+ if (!Precise["default"].stringGt(this.numberToString(amount), '0')) {
4106
+ amount = undefined;
4107
+ }
4108
+ const amountString = (amount !== undefined) ? this.getAmount(symbol, amount) : undefined;
4100
4109
  const priceString = (price !== undefined) ? this.getPrice(symbol, this.numberToString(price)) : undefined;
4101
- if (isTrailingOrder || endpointIsTradingStop) {
4102
- if (hasStopLoss || isTakeProfit || isTriggerOrder || market['spot']) {
4110
+ if (endpointIsTradingStop) {
4111
+ if (hasStopLoss || hasTakeProfit || isTriggerOrder || market['spot']) {
4103
4112
  throw new errors.InvalidOrder(this.id + ' the API endpoint used only supports contract trailingAmount, stopLossPrice and takeProfitPrice orders');
4104
4113
  }
4105
4114
  if (isStopLossOrder || isTakeProfitOrder) {
4106
- const tpslMode = this.safeString(params, 'tpslMode', 'Partial');
4107
- const isFullTpsl = tpslMode === 'Full';
4108
- const isPartialTpsl = tpslMode === 'Partial';
4109
- if (isLimit && isFullTpsl) {
4110
- throw new errors.InvalidOrder(this.id + ' tpsl orders with "full" tpslMode only support "market" type');
4111
- }
4112
- request['tpslMode'] = tpslMode;
4115
+ let tpslModeSl = undefined;
4116
+ let tpslModeTp = undefined;
4113
4117
  if (isStopLossOrder) {
4114
4118
  request['stopLoss'] = this.getPrice(symbol, stopLossTriggerPrice);
4115
- if (isPartialTpsl) {
4119
+ const stopLossLimitPrice = this.safeString2(params, 'stopLossLimitPrice', 'slLimitPrice');
4120
+ if (stopLossLimitPrice !== undefined) {
4121
+ tpslModeSl = 'Partial';
4122
+ request['slOrderType'] = 'Limit';
4123
+ request['slLimitPrice'] = stopLossLimitPrice;
4116
4124
  request['slSize'] = amountString;
4117
4125
  }
4118
- if (isLimit) {
4119
- request['slOrderType'] = 'Limit';
4120
- request['slLimitPrice'] = priceString;
4126
+ else {
4127
+ request['slOrderType'] = 'Market';
4128
+ if (amountString !== undefined) {
4129
+ request['slSize'] = amountString;
4130
+ tpslModeSl = 'Partial';
4131
+ }
4132
+ else {
4133
+ tpslModeSl = 'Full';
4134
+ }
4121
4135
  }
4122
4136
  }
4123
- else if (isTakeProfitOrder) {
4137
+ if (isTakeProfitOrder) {
4124
4138
  request['takeProfit'] = this.getPrice(symbol, takeProfitTriggerPrice);
4125
- if (isPartialTpsl) {
4139
+ const takeProfitLimitPrice = this.safeString2(params, 'takeProfitLimitPrice', 'tpLimitPrice');
4140
+ if (takeProfitLimitPrice !== undefined) {
4141
+ tpslModeTp = 'Partial';
4142
+ request['tpOrderType'] = 'Limit';
4143
+ request['tpLimitPrice'] = takeProfitLimitPrice;
4126
4144
  request['tpSize'] = amountString;
4127
4145
  }
4128
- if (isLimit) {
4129
- request['tpOrderType'] = 'Limit';
4130
- request['tpLimitPrice'] = priceString;
4146
+ else {
4147
+ request['tpOrderType'] = 'Market';
4148
+ if (amountString !== undefined) {
4149
+ request['tpSize'] = amountString;
4150
+ tpslModeTp = 'Partial';
4151
+ }
4152
+ else {
4153
+ tpslModeTp = 'Full';
4154
+ }
4131
4155
  }
4132
4156
  }
4157
+ if (tpslModeSl !== tpslModeTp) {
4158
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires both stopLoss and takeProfit to be full or partial when using as OCO combination');
4159
+ }
4160
+ request['tpslMode'] = tpslModeSl; // same as tpslModeTp
4161
+ params = this.omit(params, ['stopLossLimitPrice', 'takeProfitLimitPrice']);
4133
4162
  }
4134
4163
  }
4135
4164
  else {
@@ -4264,7 +4293,7 @@ class bybit extends bybit$1["default"] {
4264
4293
  request['triggerPrice'] = this.getPrice(symbol, triggerPrice);
4265
4294
  request['reduceOnly'] = true;
4266
4295
  }
4267
- if ((hasStopLoss || isTakeProfit) && !endpointIsTradingStop) {
4296
+ if ((hasStopLoss || hasTakeProfit) && !endpointIsTradingStop) {
4268
4297
  if (hasStopLoss) {
4269
4298
  const slTriggerPrice = this.safeValue2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss);
4270
4299
  request['stopLoss'] = this.getPrice(symbol, slTriggerPrice);
@@ -4285,7 +4314,7 @@ class bybit extends bybit$1["default"] {
4285
4314
  throw new errors.InvalidOrder(this.id + ' createOrder(): attached stopLoss is not supported for spot market orders');
4286
4315
  }
4287
4316
  }
4288
- if (isTakeProfit) {
4317
+ if (hasTakeProfit) {
4289
4318
  const tpTriggerPrice = this.safeValue2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit);
4290
4319
  request['takeProfit'] = this.getPrice(symbol, tpTriggerPrice);
4291
4320
  const tpLimitPrice = this.safeValue(takeProfit, 'price');
@@ -4313,7 +4342,7 @@ class bybit extends bybit$1["default"] {
4313
4342
  }
4314
4343
  request['positionIdx'] = (side === 'buy') ? 1 : 2;
4315
4344
  }
4316
- params = this.omit(params, ['stopPrice', 'timeInForce', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'clientOrderId', 'triggerPrice', 'stopLoss', 'takeProfit', 'trailingAmount', 'trailingTriggerPrice', 'hedged', 'tpslMode']);
4345
+ params = this.omit(params, ['stopPrice', 'timeInForce', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'clientOrderId', 'triggerPrice', 'stopLoss', 'takeProfit', 'trailingAmount', 'trailingTriggerPrice', 'hedged']);
4317
4346
  return this.extend(request, params);
4318
4347
  }
4319
4348
  /**
@@ -1147,7 +1147,7 @@ class coincatch extends coincatch$1["default"] {
1147
1147
  await this.loadMarkets();
1148
1148
  symbols = this.marketSymbols(symbols, undefined, true, true);
1149
1149
  const market = this.getMarketFromSymbols(symbols);
1150
- let marketType = 'spot';
1150
+ let marketType = undefined;
1151
1151
  [marketType, params] = this.handleMarketTypeAndParams(methodName, market, params, marketType);
1152
1152
  let response = undefined;
1153
1153
  if (marketType === 'spot') {
@@ -2654,22 +2654,22 @@ class coincatch extends coincatch$1["default"] {
2654
2654
  let stopLossPrice = this.safeString(params, 'stopLossPrice');
2655
2655
  let takeProfitPrice = this.safeString(params, 'takeProfitPrice');
2656
2656
  let requestTriggerPrice = undefined;
2657
- const takeProfitParams = this.safeDict(params, 'takeProfit');
2658
- const stopLossParams = this.safeDict(params, 'stopLoss');
2657
+ const takeProfit = this.safeDict(params, 'takeProfit');
2658
+ const stopLoss = this.safeDict(params, 'stopLoss');
2659
2659
  const triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
2660
2660
  const isTrigger = (triggerPrice !== undefined);
2661
2661
  const trailingPercent = this.safeString(params, 'trailingPercent');
2662
2662
  const trailingTriggerPrice = this.safeString(params, 'trailingTriggerPrice');
2663
2663
  let hasTPPrice = (takeProfitPrice !== undefined);
2664
2664
  let hasSLPrice = (stopLossPrice !== undefined);
2665
- const hasTPParams = (takeProfitParams !== undefined);
2666
- if (hasTPParams && !hasTPPrice) {
2667
- takeProfitPrice = this.safeString(takeProfitParams, 'triggerPrice');
2665
+ const hasTakeProfit = (takeProfit !== undefined);
2666
+ if (hasTakeProfit && !hasTPPrice) {
2667
+ takeProfitPrice = this.safeString(takeProfit, 'triggerPrice');
2668
2668
  hasTPPrice = (takeProfitPrice !== undefined);
2669
2669
  }
2670
- const hasSLParams = (stopLossParams !== undefined);
2671
- if (hasSLParams && !hasSLPrice) {
2672
- stopLossPrice = this.safeString(stopLossParams, 'triggerPrice');
2670
+ const hasStopLoss = (stopLoss !== undefined);
2671
+ if (hasStopLoss && !hasSLPrice) {
2672
+ stopLossPrice = this.safeString(stopLoss, 'triggerPrice');
2673
2673
  hasSLPrice = (stopLossPrice !== undefined);
2674
2674
  }
2675
2675
  const hasBothTPAndSL = hasTPPrice && hasSLPrice;