ccxt 4.0.109 → 4.0.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -214,13 +214,13 @@ console.log(version, Object.keys(exchanges));
214
214
 
215
215
  All-in-one browser bundle (dependencies included), served from a CDN of your choice:
216
216
 
217
- * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.0.109/dist/ccxt.browser.js
218
- * unpkg: https://unpkg.com/ccxt@4.0.109/dist/ccxt.browser.js
217
+ * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.0.110/dist/ccxt.browser.js
218
+ * unpkg: https://unpkg.com/ccxt@4.0.110/dist/ccxt.browser.js
219
219
 
220
220
  CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.
221
221
 
222
222
  ```HTML
223
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.0.109/dist/ccxt.browser.js"></script>
223
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.0.110/dist/ccxt.browser.js"></script>
224
224
  ```
225
225
 
226
226
  Creates a global `ccxt` object:
@@ -38471,6 +38471,7 @@ class bitget extends _abstract_bitget_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
38471
38471
  '40712': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InsufficientFunds,
38472
38472
  '40713': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ExchangeError,
38473
38473
  '40714': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ExchangeError,
38474
+ '40768': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.OrderNotFound,
38474
38475
  '41114': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.OnMaintenance,
38475
38476
  '43011': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder,
38476
38477
  '43025': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder,
@@ -71238,10 +71239,11 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
71238
71239
  '10027': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.PermissionDenied,
71239
71240
  '10028': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.PermissionDenied,
71240
71241
  '10029': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.PermissionDenied,
71242
+ '12137': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder,
71241
71243
  '12201': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest,
71242
71244
  '12141': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest,
71243
71245
  '100028': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.PermissionDenied,
71244
- '110001': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder,
71246
+ '110001': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.OrderNotFound,
71245
71247
  '110003': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder,
71246
71248
  '110004': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InsufficientFunds,
71247
71249
  '110005': _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder,
@@ -74064,11 +74066,38 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
74064
74066
  if ((clientOrderId !== undefined) && (clientOrderId.length < 1)) {
74065
74067
  clientOrderId = undefined;
74066
74068
  }
74069
+ const avgPrice = this.omitZero(this.safeString(order, 'avgPrice'));
74067
74070
  const rawTimeInForce = this.safeString(order, 'timeInForce');
74068
74071
  const timeInForce = this.parseTimeInForce(rawTimeInForce);
74069
74072
  const stopPrice = this.omitZero(this.safeString(order, 'triggerPrice'));
74070
- const takeProfitPrice = this.omitZero(this.safeString(order, 'takeProfit'));
74071
- const stopLossPrice = this.omitZero(this.safeString(order, 'stopLoss'));
74073
+ const reduceOnly = this.safeValue(order, 'reduceOnly');
74074
+ let takeProfitPrice = this.omitZero(this.safeString(order, 'takeProfit'));
74075
+ let stopLossPrice = this.omitZero(this.safeString(order, 'stopLoss'));
74076
+ const triggerDirection = this.safeString(order, 'triggerDirection');
74077
+ const isAscending = (triggerDirection === '1');
74078
+ const isStopOrderType2 = (stopPrice !== undefined) && reduceOnly;
74079
+ if ((stopLossPrice === undefined) && isStopOrderType2) {
74080
+ // check if order is stop order type 2 - stopLossPrice
74081
+ if (isAscending && (side === 'buy')) {
74082
+ // stopLoss order against short position
74083
+ stopLossPrice = stopPrice;
74084
+ }
74085
+ if (!isAscending && (side === 'sell')) {
74086
+ // stopLoss order against a long position
74087
+ stopLossPrice = stopPrice;
74088
+ }
74089
+ }
74090
+ if ((takeProfitPrice === undefined) && isStopOrderType2) {
74091
+ // check if order is stop order type 2 - takeProfitPrice
74092
+ if (isAscending && (side === 'sell')) {
74093
+ // takeprofit order against a long position
74094
+ takeProfitPrice = stopPrice;
74095
+ }
74096
+ if (!isAscending && (side === 'buy')) {
74097
+ // takeprofit order against a short position
74098
+ takeProfitPrice = stopPrice;
74099
+ }
74100
+ }
74072
74101
  return this.safeOrder({
74073
74102
  'info': order,
74074
74103
  'id': id,
@@ -74090,7 +74119,7 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
74090
74119
  'stopLossPrice': stopLossPrice,
74091
74120
  'amount': amount,
74092
74121
  'cost': cost,
74093
- 'average': undefined,
74122
+ 'average': avgPrice,
74094
74123
  'filled': filled,
74095
74124
  'remaining': remaining,
74096
74125
  'status': status,
@@ -74142,6 +74171,14 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
74142
74171
  * @param {boolean} [params.isLeverage] *unified spot only* false then spot trading true then margin trading
74143
74172
  * @param {string} [params.tpslMode] *contract only* 'full' or 'partial'
74144
74173
  * @param {string} [params.mmp] *option only* market maker protection
74174
+ * @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'up' or 'down'
74175
+ * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
74176
+ * @param {float} [params.stopLossPrice] The price at which a stop loss order is triggered at
74177
+ * @param {float} [params.takeProfitPrice] The price at which a take profit order is triggered at
74178
+ * @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
74179
+ * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
74180
+ * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
74181
+ * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
74145
74182
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
74146
74183
  */
74147
74184
  await this.loadMarkets();
@@ -74247,13 +74284,21 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
74247
74284
  const isStopLoss = stopLoss !== undefined;
74248
74285
  const isTakeProfit = takeProfit !== undefined;
74249
74286
  const isBuy = side === 'buy';
74250
- const ascending = stopLossTriggerPrice ? !isBuy : isBuy;
74287
+ const setTriggerDirection = (stopLossTriggerPrice || triggerPrice) ? !isBuy : isBuy;
74288
+ const defaultTriggerDirection = setTriggerDirection ? 2 : 1;
74289
+ const triggerDirection = this.safeString(params, 'triggerDirection');
74290
+ params = this.omit(params, 'triggerDirection');
74291
+ let selectedDirection = defaultTriggerDirection;
74292
+ if (triggerDirection !== undefined) {
74293
+ const isAsending = ((triggerDirection === 'up') || (triggerDirection === '1'));
74294
+ selectedDirection = isAsending ? 1 : 2;
74295
+ }
74251
74296
  if (triggerPrice !== undefined) {
74252
- request['triggerDirection'] = ascending ? 2 : 1;
74297
+ request['triggerDirection'] = selectedDirection;
74253
74298
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
74254
74299
  }
74255
74300
  else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
74256
- request['triggerDirection'] = ascending ? 2 : 1;
74301
+ request['triggerDirection'] = selectedDirection;
74257
74302
  triggerPrice = isStopLossTriggerOrder ? stopLossTriggerPrice : takeProfitTriggerPrice;
74258
74303
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
74259
74304
  request['reduceOnly'] = true;
@@ -183573,9 +183618,10 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
183573
183618
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#query-kline
183574
183619
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
183575
183620
  * @param {string} timeframe the length of time each candle represents
183576
- * @param {int} [since] *emulated not supported by the exchange* timestamp in ms of the earliest candle to fetch
183621
+ * @param {int} [since] *only used for USDT settled contracts, otherwise is emulated and not supported by the exchange* timestamp in ms of the earliest candle to fetch
183577
183622
  * @param {int} [limit] the maximum amount of candles to fetch
183578
183623
  * @param {object} [params] extra parameters specific to the phemex api endpoint
183624
+ * @param {int} [params.until] *USDT settled/ linear swaps only* end time in ms
183579
183625
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
183580
183626
  */
183581
183627
  await this.loadMarkets();
@@ -183585,34 +183631,55 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
183585
183631
  'symbol': market['id'],
183586
183632
  'resolution': this.safeString(this.timeframes, timeframe, timeframe),
183587
183633
  };
183588
- const possibleLimitValues = [5, 10, 50, 100, 500, 1000];
183589
- const maxLimit = 1000;
183590
- if (limit === undefined && since === undefined) {
183591
- limit = possibleLimitValues[5];
183592
- }
183593
- if (since !== undefined) {
183594
- // phemex also provides kline query with from/to, however, this interface is NOT recommended and does not work properly.
183595
- // we do not send since param to the exchange, instead we calculate appropriate limit param
183596
- const duration = this.parseTimeframe(timeframe) * 1000;
183597
- const timeDelta = this.milliseconds() - since;
183598
- limit = this.parseToInt(timeDelta / duration); // setting limit to the number of candles after since
183634
+ const until = this.safeInteger2(params, 'until', 'to');
183635
+ params = this.omit(params, ['until']);
183636
+ const usesSpecialFromToEndpoint = ((market['linear'] || market['settle'] === 'USDT')) && ((since !== undefined) || (until !== undefined));
183637
+ let maxLimit = 1000;
183638
+ if (usesSpecialFromToEndpoint) {
183639
+ maxLimit = 2000;
183599
183640
  }
183600
- if (limit > maxLimit) {
183641
+ if (limit === undefined) {
183601
183642
  limit = maxLimit;
183602
183643
  }
183603
- else {
183604
- for (let i = 0; i < possibleLimitValues.length; i++) {
183605
- if (limit <= possibleLimitValues[i]) {
183606
- limit = possibleLimitValues[i];
183607
- }
183608
- }
183609
- }
183610
- request['limit'] = limit;
183644
+ request['limit'] = Math.min(limit, maxLimit);
183611
183645
  let response = undefined;
183612
183646
  if (market['linear'] || market['settle'] === 'USDT') {
183613
- response = await this.publicGetMdV2KlineLast(this.extend(request, params));
183647
+ if ((until !== undefined) || (since !== undefined)) {
183648
+ const candleDuration = this.parseTimeframe(timeframe);
183649
+ if (since !== undefined) {
183650
+ since = Math.round(since / 1000);
183651
+ request['from'] = since;
183652
+ }
183653
+ else {
183654
+ // when 'to' is defined since is mandatory
183655
+ since = (until / 100) - (maxLimit * candleDuration);
183656
+ }
183657
+ if (until !== undefined) {
183658
+ request['to'] = Math.round(until / 1000);
183659
+ }
183660
+ else {
183661
+ // when since is defined 'to' is mandatory
183662
+ let to = since + (maxLimit * candleDuration);
183663
+ const now = this.seconds();
183664
+ if (to > now) {
183665
+ to = now;
183666
+ }
183667
+ request['to'] = to;
183668
+ }
183669
+ response = await this.publicGetMdV2KlineList(this.extend(request, params));
183670
+ }
183671
+ else {
183672
+ response = await this.publicGetMdV2KlineLast(this.extend(request, params));
183673
+ }
183614
183674
  }
183615
183675
  else {
183676
+ if (since !== undefined) {
183677
+ // phemex also provides kline query with from/to, however, this interface is NOT recommended and does not work properly.
183678
+ // we do not send since param to the exchange, instead we calculate appropriate limit param
183679
+ const duration = this.parseTimeframe(timeframe) * 1000;
183680
+ const timeDelta = this.milliseconds() - since;
183681
+ limit = this.parseToInt(timeDelta / duration); // setting limit to the number of candles after since
183682
+ }
183616
183683
  response = await this.publicGetMdV2Kline(this.extend(request, params));
183617
183684
  }
183618
183685
  //
@@ -273297,7 +273364,7 @@ SOFTWARE.
273297
273364
 
273298
273365
  //-----------------------------------------------------------------------------
273299
273366
  // this is updated by vss.js when building
273300
- const version = '4.0.109';
273367
+ const version = '4.0.110';
273301
273368
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange.ccxtVersion */ .e.ccxtVersion = version;
273302
273369
  //-----------------------------------------------------------------------------
273303
273370