ccxt 4.0.100 → 4.0.101

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 (52) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +390 -142
  3. package/dist/ccxt.browser.min.js +2 -2
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/binance.js +28 -1
  6. package/dist/cjs/src/bitbank.js +11 -0
  7. package/dist/cjs/src/bitfinex.js +12 -8
  8. package/dist/cjs/src/bitflyer.js +39 -10
  9. package/dist/cjs/src/bitforex.js +0 -8
  10. package/dist/cjs/src/bitget.js +15 -5
  11. package/dist/cjs/src/bitstamp1.js +22 -0
  12. package/dist/cjs/src/bl3p.js +24 -0
  13. package/dist/cjs/src/bybit.js +111 -36
  14. package/dist/cjs/src/coinbasepro.js +11 -0
  15. package/dist/cjs/src/currencycom.js +1 -1
  16. package/dist/cjs/src/huobi.js +1 -1
  17. package/dist/cjs/src/huobijp.js +1 -1
  18. package/dist/cjs/src/idex.js +1 -1
  19. package/dist/cjs/src/kucoinfutures.js +46 -51
  20. package/dist/cjs/src/lbank.js +1 -1
  21. package/dist/cjs/src/lbank2.js +1 -1
  22. package/dist/cjs/src/pro/huobijp.js +1 -2
  23. package/dist/cjs/src/pro/krakenfutures.js +7 -7
  24. package/dist/cjs/src/pro/kucoin.js +51 -2
  25. package/dist/cjs/src/pro/kucoinfutures.js +3 -3
  26. package/dist/cjs/src/pro/phemex.js +2 -2
  27. package/js/ccxt.d.ts +1 -1
  28. package/js/ccxt.js +1 -1
  29. package/js/src/binance.js +28 -1
  30. package/js/src/bitbank.js +11 -0
  31. package/js/src/bitfinex.js +12 -8
  32. package/js/src/bitflyer.js +39 -10
  33. package/js/src/bitforex.js +0 -8
  34. package/js/src/bitget.js +15 -5
  35. package/js/src/bitstamp1.js +22 -0
  36. package/js/src/bl3p.js +24 -0
  37. package/js/src/bybit.js +111 -36
  38. package/js/src/coinbasepro.js +11 -0
  39. package/js/src/currencycom.js +1 -1
  40. package/js/src/huobi.js +1 -1
  41. package/js/src/huobijp.js +1 -1
  42. package/js/src/idex.js +1 -1
  43. package/js/src/kucoinfutures.js +46 -51
  44. package/js/src/lbank.js +1 -1
  45. package/js/src/lbank2.js +1 -1
  46. package/js/src/pro/huobijp.js +1 -2
  47. package/js/src/pro/krakenfutures.js +7 -7
  48. package/js/src/pro/kucoin.d.ts +1 -0
  49. package/js/src/pro/kucoin.js +51 -2
  50. package/js/src/pro/kucoinfutures.js +3 -3
  51. package/js/src/pro/phemex.js +2 -2
  52. package/package.json +1 -1
package/dist/cjs/ccxt.js CHANGED
@@ -180,7 +180,7 @@ var woo$1 = require('./src/pro/woo.js');
180
180
 
181
181
  //-----------------------------------------------------------------------------
182
182
  // this is updated by vss.js when building
183
- const version = '4.0.100';
183
+ const version = '4.0.101';
184
184
  Exchange["default"].ccxtVersion = version;
185
185
  const exchanges = {
186
186
  'ace': ace,
@@ -3420,6 +3420,18 @@ class binance extends binance$1 {
3420
3420
  // "M": true // Was the trade the best price match?
3421
3421
  // }
3422
3422
  //
3423
+ // REST: aggregate trades for swap & future (both linear and inverse)
3424
+ //
3425
+ // {
3426
+ // "a": "269772814",
3427
+ // "p": "25864.1",
3428
+ // "q": "3",
3429
+ // "f": "662149354",
3430
+ // "l": "662149355",
3431
+ // "T": "1694209776022",
3432
+ // "m": false,
3433
+ // }
3434
+ //
3423
3435
  // recent public trades and old public trades
3424
3436
  // https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#recent-trades-list
3425
3437
  // https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#old-trade-lookup-market_data
@@ -3673,7 +3685,8 @@ class binance extends binance$1 {
3673
3685
  }
3674
3686
  }
3675
3687
  if (limit !== undefined) {
3676
- request['limit'] = limit; // default = 500, maximum = 1000
3688
+ const isFutureOrSwap = (market['swap'] || market['future']);
3689
+ request['limit'] = isFutureOrSwap ? Math.min(limit, 1000) : limit; // default = 500, maximum = 1000
3677
3690
  }
3678
3691
  params = this.omit(params, ['until', 'fetchTradesMethod']);
3679
3692
  //
@@ -3702,6 +3715,20 @@ class binance extends binance$1 {
3702
3715
  // }
3703
3716
  // ]
3704
3717
  //
3718
+ // inverse (swap & future)
3719
+ //
3720
+ // [
3721
+ // {
3722
+ // "a": "269772814",
3723
+ // "p": "25864.1",
3724
+ // "q": "3",
3725
+ // "f": "662149354",
3726
+ // "l": "662149355",
3727
+ // "T": "1694209776022",
3728
+ // "m": false,
3729
+ // },
3730
+ // ]
3731
+ //
3705
3732
  // recent public trades and historical public trades
3706
3733
  //
3707
3734
  // [
@@ -316,6 +316,17 @@ class bitbank extends bitbank$1 {
316
316
  return this.parseOrderBook(orderbook, market['symbol'], timestamp);
317
317
  }
318
318
  parseTrade(trade, market = undefined) {
319
+ //
320
+ // fetchTrades
321
+ //
322
+ // {
323
+ // "transaction_id": "1143247037",
324
+ // "side": "buy",
325
+ // "price": "3836025",
326
+ // "amount": "0.0005",
327
+ // "executed_at": "1694249441593"
328
+ // }
329
+ //
319
330
  const timestamp = this.safeInteger(trade, 'executed_at');
320
331
  market = this.safeMarket(undefined, market);
321
332
  const priceString = this.safeString(trade, 'price');
@@ -919,14 +919,6 @@ class bitfinex extends bitfinex$1 {
919
919
  // "type":"sell"
920
920
  // }
921
921
  //
922
- // { "timestamp":1637258238,
923
- // "tid":894452800,
924
- // "price":"0.99958",
925
- // "amount":"261.90514",
926
- // "exchange":"bitfinex",
927
- // "type":"buy"
928
- // }
929
- //
930
922
  // fetchMyTrades (private) v1
931
923
  //
932
924
  // {
@@ -1005,6 +997,18 @@ class bitfinex extends bitfinex$1 {
1005
997
  request['timestamp'] = this.parseToInt(since / 1000);
1006
998
  }
1007
999
  const response = await this.publicGetTradesSymbol(this.extend(request, params));
1000
+ //
1001
+ // [
1002
+ // {
1003
+ // "timestamp": "1694284565",
1004
+ // "tid": "1415415034",
1005
+ // "price": "25862.0",
1006
+ // "amount": "0.00020685",
1007
+ // "exchange": "bitfinex",
1008
+ // "type": "buy"
1009
+ // },
1010
+ // ]
1011
+ //
1008
1012
  return this.parseTrades(response, market, since, limit);
1009
1013
  }
1010
1014
  async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -406,7 +406,7 @@ class bitflyer extends bitflyer$1 {
406
406
  //
407
407
  // fetchTrades (public) v1
408
408
  //
409
- // {
409
+ // {
410
410
  // "id":2278466664,
411
411
  // "side":"SELL",
412
412
  // "price":56810.7,
@@ -416,16 +416,18 @@ class bitflyer extends bitflyer$1 {
416
416
  // "sell_child_order_acceptance_id":"JRF20211119-114639-236919"
417
417
  // }
418
418
  //
419
- // {
420
- // "id":2278463423,
421
- // "side":"BUY",
422
- // "price":56757.83,
423
- // "size":0.6003,"exec_date":"2021-11-19T11:28:00.523",
424
- // "buy_child_order_acceptance_id":"JRF20211119-112800-236526",
425
- // "sell_child_order_acceptance_id":"JRF20211119-112734-062017"
426
- // }
427
- //
419
+ // fetchMyTrades
428
420
  //
421
+ // {
422
+ // "id": 37233,
423
+ // "side": "BUY",
424
+ // "price": 33470,
425
+ // "size": 0.01,
426
+ // "exec_date": "2015-07-07T09:57:40.397",
427
+ // "child_order_id": "JOR20150707-060559-021935",
428
+ // "child_order_acceptance_id": "JRF20150707-060559-396699"
429
+ // "commission": 0,
430
+ // },
429
431
  //
430
432
  let side = this.safeStringLower(trade, 'side');
431
433
  if (side !== undefined) {
@@ -484,6 +486,19 @@ class bitflyer extends bitflyer$1 {
484
486
  request['count'] = limit;
485
487
  }
486
488
  const response = await this.publicGetGetexecutions(this.extend(request, params));
489
+ //
490
+ // [
491
+ // {
492
+ // "id": 39287,
493
+ // "side": "BUY",
494
+ // "price": 31690,
495
+ // "size": 27.04,
496
+ // "exec_date": "2015-07-08T02:43:34.823",
497
+ // "buy_child_order_acceptance_id": "JRF20150707-200203-452209",
498
+ // "sell_child_order_acceptance_id": "JRF20150708-024334-060234"
499
+ // },
500
+ // ]
501
+ //
487
502
  return this.parseTrades(response, market, since, limit);
488
503
  }
489
504
  async fetchTradingFee(symbol, params = {}) {
@@ -720,6 +735,20 @@ class bitflyer extends bitflyer$1 {
720
735
  request['count'] = limit;
721
736
  }
722
737
  const response = await this.privateGetGetexecutions(this.extend(request, params));
738
+ //
739
+ // [
740
+ // {
741
+ // "id": 37233,
742
+ // "side": "BUY",
743
+ // "price": 33470,
744
+ // "size": 0.01,
745
+ // "exec_date": "2015-07-07T09:57:40.397",
746
+ // "child_order_id": "JOR20150707-060559-021935",
747
+ // "child_order_acceptance_id": "JRF20150707-060559-396699"
748
+ // "commission": 0,
749
+ // },
750
+ // ]
751
+ //
723
752
  return this.parseTrades(response, market, since, limit);
724
753
  }
725
754
  async fetchPositions(symbols = undefined, params = {}) {
@@ -246,14 +246,6 @@ class bitforex extends bitforex$1 {
246
246
  // "tid":"1131019666"
247
247
  // }
248
248
  //
249
- // {
250
- // "price":57591.33,
251
- // "amount":0.002,
252
- // "time":1637329685322,
253
- // "direction":1,
254
- // "tid":"1131019639"
255
- // }
256
- //
257
249
  // fetchMyTrades (private)
258
250
  //
259
251
  // {
@@ -2149,7 +2149,7 @@ class bitget extends bitget$1 {
2149
2149
  // "fillTime": "1692073691000"
2150
2150
  // }
2151
2151
  //
2152
- // swap
2152
+ // swap (public trades)
2153
2153
  //
2154
2154
  // {
2155
2155
  // "tradeId": "1075199767891652609",
@@ -2281,6 +2281,16 @@ class bitget extends bitget$1 {
2281
2281
  params = this.omit(params, 'method');
2282
2282
  if (swapMethod === 'publicMixGetMarketFillsHistory') {
2283
2283
  response = await this.publicMixGetMarketFillsHistory(this.extend(request, params));
2284
+ //
2285
+ // {
2286
+ // "tradeId": "1084459062491590657",
2287
+ // "price": "25874",
2288
+ // "size": "1.624",
2289
+ // "side": "Buy",
2290
+ // "timestamp": "1694281109000",
2291
+ // "symbol": "BTCUSDT_UMCBL",
2292
+ // }
2293
+ //
2284
2294
  }
2285
2295
  else if (swapMethod === 'publicMixGetMarketFills') {
2286
2296
  response = await this.publicMixGetMarketFills(this.extend(request, params));
@@ -2981,12 +2991,12 @@ class bitget extends bitget$1 {
2981
2991
  }
2982
2992
  else if (isStopLossOrTakeProfit) {
2983
2993
  if (isStopLoss) {
2984
- const stopLossTriggerPrice = this.safeValue2(stopLoss, 'triggerPrice', 'stopPrice');
2985
- request['presetStopLossPrice'] = this.priceToPrecision(symbol, stopLossTriggerPrice);
2994
+ const slTriggerPrice = this.safeValue2(stopLoss, 'triggerPrice', 'stopPrice');
2995
+ request['presetStopLossPrice'] = this.priceToPrecision(symbol, slTriggerPrice);
2986
2996
  }
2987
2997
  if (isTakeProfit) {
2988
- const takeProfitTriggerPrice = this.safeValue2(takeProfit, 'triggerPrice', 'stopPrice');
2989
- request['presetTakeProfitPrice'] = this.priceToPrecision(symbol, takeProfitTriggerPrice);
2998
+ const tpTriggerPrice = this.safeValue2(takeProfit, 'triggerPrice', 'stopPrice');
2999
+ request['presetTakeProfitPrice'] = this.priceToPrecision(symbol, tpTriggerPrice);
2990
3000
  }
2991
3001
  }
2992
3002
  }
@@ -215,6 +215,17 @@ class bitstamp1 extends bitstamp1$1 {
215
215
  return this.parseTicker(ticker, market);
216
216
  }
217
217
  parseTrade(trade, market = undefined) {
218
+ //
219
+ // public trade
220
+ //
221
+ // {
222
+ // "amount": "0.00114000",
223
+ // "date": "1694287856",
224
+ // "price": "25865",
225
+ // "tid": 298730788,
226
+ // "type": 0
227
+ // }
228
+ //
218
229
  const timestamp = this.safeTimestamp2(trade, 'date', 'datetime');
219
230
  const side = (trade['type'] === 0) ? 'buy' : 'sell';
220
231
  const orderId = this.safeString(trade, 'order_id');
@@ -259,6 +270,17 @@ class bitstamp1 extends bitstamp1$1 {
259
270
  'time': 'minute',
260
271
  };
261
272
  const response = await this.publicGetTransactions(this.extend(request, params));
273
+ //
274
+ // [
275
+ // {
276
+ // "amount": "0.00114000",
277
+ // "date": "1694287856",
278
+ // "price": "25865",
279
+ // "tid": 298730788,
280
+ // "type": 0
281
+ // },
282
+ // ]
283
+ //
262
284
  return this.parseTrades(response, market, since, limit);
263
285
  }
264
286
  parseBalance(response) {
@@ -241,6 +241,16 @@ class bl3p extends bl3p$1 {
241
241
  return this.parseTicker(ticker, market);
242
242
  }
243
243
  parseTrade(trade, market = undefined) {
244
+ //
245
+ // fetchTrades
246
+ //
247
+ // {
248
+ // "trade_id": "2518789",
249
+ // "date": "1694348697745",
250
+ // "amount_int": "2959153",
251
+ // "price_int": "2416231440"
252
+ // }
253
+ //
244
254
  const id = this.safeString(trade, 'trade_id');
245
255
  const timestamp = this.safeInteger(trade, 'date');
246
256
  const price = this.safeString(trade, 'price_int');
@@ -277,6 +287,20 @@ class bl3p extends bl3p$1 {
277
287
  const response = await this.publicGetMarketTrades(this.extend({
278
288
  'market': market['id'],
279
289
  }, params));
290
+ //
291
+ // {
292
+ // "result": "success",
293
+ // "data": {
294
+ // "trades": [
295
+ // {
296
+ // "trade_id": "2518789",
297
+ // "date": "1694348697745",
298
+ // "amount_int": "2959153",
299
+ // "price_int": "2416231440"
300
+ // },
301
+ // ]
302
+ // }
303
+ // }
280
304
  const result = this.parseTrades(response['data']['trades'], market, since, limit);
281
305
  return result;
282
306
  }
@@ -726,7 +726,7 @@ class bybit extends bybit$1 {
726
726
  '110023': errors.InvalidOrder,
727
727
  '110024': errors.InvalidOrder,
728
728
  '110025': errors.InvalidOrder,
729
- '110026': errors.InvalidOrder,
729
+ '110026': errors.BadRequest,
730
730
  '110027': errors.InvalidOrder,
731
731
  '110028': errors.InvalidOrder,
732
732
  '110029': errors.InvalidOrder,
@@ -2401,20 +2401,14 @@ class bybit extends bybit$1 {
2401
2401
  request['limit'] = limit; // max 1000, default 1000
2402
2402
  }
2403
2403
  request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
2404
- let method = undefined;
2404
+ let response = undefined;
2405
2405
  if (market['spot']) {
2406
2406
  request['category'] = 'spot';
2407
- method = 'publicGetV5MarketKline';
2407
+ response = await this.publicGetV5MarketKline(this.extend(request, params));
2408
2408
  }
2409
2409
  else {
2410
2410
  const price = this.safeString(params, 'price');
2411
2411
  params = this.omit(params, 'price');
2412
- const methods = {
2413
- 'mark': 'publicGetV5MarketMarkPriceKline',
2414
- 'index': 'publicGetV5MarketIndexPriceKline',
2415
- 'premiumIndex': 'publicGetV5MarketPremiumIndexPriceKline',
2416
- };
2417
- method = this.safeValue(methods, price, 'publicGetV5MarketKline');
2418
2412
  if (market['linear']) {
2419
2413
  request['category'] = 'linear';
2420
2414
  }
@@ -2424,8 +2418,19 @@ class bybit extends bybit$1 {
2424
2418
  else {
2425
2419
  throw new errors.NotSupported(this.id + ' fetchOHLCV() is not supported for option markets');
2426
2420
  }
2421
+ if (price === 'mark') {
2422
+ response = await this.publicGetV5MarketMarkPriceKline(this.extend(request, params));
2423
+ }
2424
+ else if (price === 'index') {
2425
+ response = await this.publicGetV5MarketIndexPriceKline(this.extend(request, params));
2426
+ }
2427
+ else if (price === 'premiumIndex') {
2428
+ response = await this.publicGetV5MarketPremiumIndexPriceKline(this.extend(request, params));
2429
+ }
2430
+ else {
2431
+ response = await this.publicGetV5MarketKline(this.extend(request, params));
2432
+ }
2427
2433
  }
2428
- const response = await this[method](this.extend(request, params));
2429
2434
  //
2430
2435
  // {
2431
2436
  // "retCode": 0,
@@ -3598,6 +3603,7 @@ class bybit extends bybit$1 {
3598
3603
  * @param {boolean} [params.isLeverage] *unified spot only* false then spot trading true then margin trading
3599
3604
  * @param {string} [params.tpslMode] *contract only* 'full' or 'partial'
3600
3605
  * @param {string} [params.mmp] *option only* market maker protection
3606
+ * @param {int} [params.triggerDirection] *contract only* conditional orders, 1: triggered when market price rises to triggerPrice, 2: triggered when market price falls to triggerPrice
3601
3607
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
3602
3608
  */
3603
3609
  await this.loadMarkets();
@@ -3705,7 +3711,6 @@ class bybit extends bybit$1 {
3705
3711
  const isBuy = side === 'buy';
3706
3712
  const ascending = stopLossTriggerPrice ? !isBuy : isBuy;
3707
3713
  if (triggerPrice !== undefined) {
3708
- request['triggerDirection'] = ascending ? 2 : 1;
3709
3714
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
3710
3715
  }
3711
3716
  else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
@@ -3851,8 +3856,13 @@ class bybit extends bybit$1 {
3851
3856
  request['orderLinkId'] = this.uuid16();
3852
3857
  }
3853
3858
  params = this.omit(params, ['stopPrice', 'timeInForce', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'postOnly', 'clientOrderId']);
3854
- const method = market['option'] ? 'privatePostOptionUsdcOpenapiPrivateV1PlaceOrder' : 'privatePostPerpetualUsdcOpenapiPrivateV1PlaceOrder';
3855
- const response = await this[method](this.extend(request, params));
3859
+ let response = undefined;
3860
+ if (market['option']) {
3861
+ response = await this.privatePostOptionUsdcOpenapiPrivateV1PlaceOrder(this.extend(request, params));
3862
+ }
3863
+ else {
3864
+ response = await this.privatePostPerpetualUsdcOpenapiPrivateV1PlaceOrder(this.extend(request, params));
3865
+ }
3856
3866
  //
3857
3867
  // {
3858
3868
  // "retCode":0,
@@ -3894,12 +3904,11 @@ class bybit extends bybit$1 {
3894
3904
  if (price !== undefined) {
3895
3905
  request['orderPrice'] = this.priceToPrecision(symbol, price);
3896
3906
  }
3897
- let method = undefined;
3907
+ let response = undefined;
3898
3908
  if (market['option']) {
3899
- method = 'privatePostOptionUsdcOpenapiPrivateV1ReplaceOrder';
3909
+ response = await this.privatePostOptionUsdcOpenapiPrivateV1ReplaceOrder(this.extend(request, params));
3900
3910
  }
3901
3911
  else {
3902
- method = 'privatePostPerpetualUsdcOpenapiPrivateV1ReplaceOrder';
3903
3912
  const isStop = this.safeValue(params, 'stop', false);
3904
3913
  const triggerPrice = this.safeValue2(params, 'stopPrice', 'triggerPrice');
3905
3914
  const stopLossPrice = this.safeValue(params, 'stopLossPrice');
@@ -3920,8 +3929,8 @@ class bybit extends bybit$1 {
3920
3929
  }
3921
3930
  }
3922
3931
  params = this.omit(params, ['stop', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
3932
+ response = await this.privatePostPerpetualUsdcOpenapiPrivateV1ReplaceOrder(this.extend(request, params));
3923
3933
  }
3924
- const response = await this[method](this.extend(request, params));
3925
3934
  //
3926
3935
  // {
3927
3936
  // "retCode": 0,
@@ -4055,18 +4064,17 @@ class bybit extends bybit$1 {
4055
4064
  };
4056
4065
  const isStop = this.safeValue(params, 'stop', false);
4057
4066
  params = this.omit(params, ['stop']);
4058
- let method = undefined;
4059
4067
  if (id !== undefined) { // The user can also use argument params["order_link_id"]
4060
4068
  request['orderId'] = id;
4061
4069
  }
4070
+ let response = undefined;
4062
4071
  if (market['option']) {
4063
- method = 'privatePostOptionUsdcOpenapiPrivateV1CancelOrder';
4072
+ response = await this.privatePostOptionUsdcOpenapiPrivateV1CancelOrder(this.extend(request, params));
4064
4073
  }
4065
4074
  else {
4066
- method = 'privatePostPerpetualUsdcOpenapiPrivateV1CancelOrder';
4067
4075
  request['orderFilter'] = isStop ? 'StopOrder' : 'Order';
4076
+ response = await this.privatePostPerpetualUsdcOpenapiPrivateV1CancelOrder(this.extend(request, params));
4068
4077
  }
4069
- const response = await this[method](this.extend(request, params));
4070
4078
  //
4071
4079
  // {
4072
4080
  // "retCode": 0,
@@ -5239,7 +5247,6 @@ class bybit extends bybit$1 {
5239
5247
  request['start_date'] = this.yyyymmdd(since);
5240
5248
  }
5241
5249
  }
5242
- const method = (enableUnified[1]) ? 'privateGetV5AccountTransactionLog' : 'privateGetV2PrivateWalletFundRecords';
5243
5250
  if (code !== undefined) {
5244
5251
  currency = this.currency(code);
5245
5252
  request[currencyKey] = currency['id'];
@@ -5247,7 +5254,13 @@ class bybit extends bybit$1 {
5247
5254
  if (limit !== undefined) {
5248
5255
  request['limit'] = limit;
5249
5256
  }
5250
- const response = await this[method](this.extend(request, params));
5257
+ let response = undefined;
5258
+ if (enableUnified[1]) {
5259
+ response = await this.privateGetV5AccountTransactionLog(this.extend(request, params));
5260
+ }
5261
+ else {
5262
+ response = await this.privateGetV2PrivateWalletFundRecords(this.extend(request, params));
5263
+ }
5251
5264
  //
5252
5265
  // {
5253
5266
  // "ret_code": 0,
@@ -5968,21 +5981,83 @@ class bybit extends bybit$1 {
5968
5981
  });
5969
5982
  }
5970
5983
  async setMarginMode(marginMode, symbol = undefined, params = {}) {
5984
+ /**
5985
+ * @method
5986
+ * @name bybit#setMarginMode
5987
+ * @description set margin mode (account) or trade mode (symbol)
5988
+ * @see https://bybit-exchange.github.io/docs/v5/account/set-margin-mode
5989
+ * @see https://bybit-exchange.github.io/docs/v5/position/cross-isolate
5990
+ * @param {string} marginMode account mode must be either [isolated, cross, portfolio], trade mode must be either [isolated, cross]
5991
+ * @param {string} symbol unified market symbol of the market the position is held in, default is undefined
5992
+ * @param {object} [params] extra parameters specific to the bybit api endpoint
5993
+ * @param {string} [params.leverage] the rate of leverage, is required if setting trade mode (symbol)
5994
+ * @returns {object} response from the exchange
5995
+ */
5971
5996
  await this.loadMarkets();
5972
5997
  const [enableUnifiedMargin, enableUnifiedAccount] = await this.isUnifiedEnabled();
5973
5998
  const isUnifiedAccount = (enableUnifiedMargin || enableUnifiedAccount);
5974
- if (marginMode === 'ISOLATED_MARGIN') {
5975
- if (!isUnifiedAccount) {
5976
- throw new errors.NotSupported(this.id + ' setMarginMode() Normal Account not support ISOLATED_MARGIN');
5999
+ let response = undefined;
6000
+ if (symbol === undefined) {
6001
+ if (marginMode === 'isolated') {
6002
+ if (!isUnifiedAccount) {
6003
+ throw new errors.NotSupported(this.id + ' setMarginMode() Normal Account not support ISOLATED_MARGIN');
6004
+ }
6005
+ marginMode = 'ISOLATED_MARGIN';
5977
6006
  }
6007
+ else if (marginMode === 'cross') {
6008
+ marginMode = 'REGULAR_MARGIN';
6009
+ }
6010
+ else if (marginMode === 'portfolio') {
6011
+ marginMode = 'PORTFOLIO_MARGIN';
6012
+ }
6013
+ else {
6014
+ throw new errors.NotSupported(this.id + ' setMarginMode() marginMode must be either [isolated, cross, portfolio]');
6015
+ }
6016
+ const request = {
6017
+ 'setMarginMode': marginMode,
6018
+ };
6019
+ response = await this.privatePostV5AccountSetMarginMode(this.extend(request, params));
5978
6020
  }
5979
- else if ((marginMode !== 'REGULAR_MARGIN') && (marginMode !== 'PORTFOLIO_MARGIN')) {
5980
- throw new errors.NotSupported(this.id + ' setMarginMode() marginMode must be either ISOLATED_MARGIN or REGULAR_MARGIN or PORTFOLIO_MARGIN');
6021
+ else {
6022
+ const market = this.market(symbol);
6023
+ let type = undefined;
6024
+ [type, params] = this.getBybitType('setMarginMode', market, params);
6025
+ if (type === 'linear') {
6026
+ if (isUnifiedAccount) {
6027
+ throw new errors.NotSupported(this.id + ' setMarginMode() with symbol Unified Account only support inverse contract');
6028
+ }
6029
+ const isUsdtSettled = market['settle'] === 'USDT';
6030
+ if (!isUsdtSettled) {
6031
+ throw new errors.NotSupported(this.id + ' setMarginMode() with symbol only support USDT perpetual / inverse contract');
6032
+ }
6033
+ }
6034
+ else if (type !== 'inverse') {
6035
+ throw new errors.NotSupported(this.id + ' setMarginMode() does not support this market type');
6036
+ }
6037
+ let tradeMode = undefined;
6038
+ if (marginMode === 'cross') {
6039
+ tradeMode = 0;
6040
+ }
6041
+ else if (marginMode === 'isolated') {
6042
+ tradeMode = 1;
6043
+ }
6044
+ else {
6045
+ throw new errors.NotSupported(this.id + ' setMarginMode() with symbol marginMode must be either [isolated, cross]');
6046
+ }
6047
+ const leverage = this.safeString(params, 'leverage');
6048
+ params = this.omit(params, ['leverage']);
6049
+ if (leverage === undefined) {
6050
+ throw new errors.ArgumentsRequired(this.id + ' setMarginMode() with symbol requires leverage');
6051
+ }
6052
+ const request = {
6053
+ 'category': type,
6054
+ 'symbol': market['id'],
6055
+ 'tradeMode': tradeMode,
6056
+ 'buyLeverage': leverage,
6057
+ 'sellLeverage': leverage,
6058
+ };
6059
+ response = await this.privatePostV5PositionSwitchIsolated(this.extend(request, params));
5981
6060
  }
5982
- const request = {
5983
- 'setMarginMode': marginMode,
5984
- };
5985
- const response = await this.privatePostV5AccountSetMarginMode(this.extend(request, params));
5986
6061
  return response;
5987
6062
  }
5988
6063
  async setLeverage(leverage, symbol = undefined, params = {}) {
@@ -6014,15 +6089,14 @@ class bybit extends bybit$1 {
6014
6089
  'buyLeverage': leverage,
6015
6090
  'sellLeverage': leverage,
6016
6091
  };
6017
- let method = undefined;
6092
+ let response = undefined;
6018
6093
  if (isUsdcSettled && !isUnifiedAccount) {
6019
6094
  request['leverage'] = leverage;
6020
- method = 'privatePostPerpetualUsdcOpenapiPrivateV1PositionLeverageSave';
6095
+ response = await this.privatePostPerpetualUsdcOpenapiPrivateV1PositionLeverageSave(this.extend(request, params));
6021
6096
  }
6022
6097
  else {
6023
6098
  request['buyLeverage'] = leverage;
6024
6099
  request['sellLeverage'] = leverage;
6025
- method = 'privatePostV5PositionSetLeverage';
6026
6100
  if (market['linear']) {
6027
6101
  request['category'] = 'linear';
6028
6102
  }
@@ -6032,8 +6106,9 @@ class bybit extends bybit$1 {
6032
6106
  else {
6033
6107
  throw new errors.NotSupported(this.id + ' setLeverage() only support linear and inverse market');
6034
6108
  }
6109
+ response = await this.privatePostV5PositionSetLeverage(this.extend(request, params));
6035
6110
  }
6036
- return await this[method](this.extend(request, params));
6111
+ return response;
6037
6112
  }
6038
6113
  async setPositionMode(hedged, symbol = undefined, params = {}) {
6039
6114
  /**
@@ -815,6 +815,17 @@ class coinbasepro extends coinbasepro$1 {
815
815
  request['limit'] = limit; // default 100
816
816
  }
817
817
  const response = await this.publicGetProductsIdTrades(this.extend(request, params));
818
+ //
819
+ // [
820
+ // {
821
+ // "trade_id": "15035219",
822
+ // "side": "sell",
823
+ // "size": "0.27426731",
824
+ // "price": "25820.42000000",
825
+ // "time": "2023-09-10T13:47:41.447577Z"
826
+ // },
827
+ // ]
828
+ //
818
829
  return this.parseTrades(response, market, since, limit);
819
830
  }
820
831
  async fetchTradingFees(params = {}) {
@@ -1081,7 +1081,7 @@ class currencycom extends currencycom$1 {
1081
1081
  // 'limit': 500, // default 500, max 1000
1082
1082
  };
1083
1083
  if (limit !== undefined) {
1084
- request['limit'] = limit; // default 500, max 1000
1084
+ request['limit'] = Math.min(limit, 1000); // default 500, max 1000
1085
1085
  }
1086
1086
  if (since !== undefined) {
1087
1087
  request['startTime'] = since;
@@ -2551,7 +2551,7 @@ class huobi extends huobi$1 {
2551
2551
  }
2552
2552
  request[fieldName] = market['id'];
2553
2553
  if (limit !== undefined) {
2554
- request['size'] = limit; // max 2000
2554
+ request['size'] = Math.min(limit, 2000); // max 2000
2555
2555
  }
2556
2556
  const response = await this[method](this.extend(request, params));
2557
2557
  //
@@ -869,7 +869,7 @@ class huobijp extends huobijp$1 {
869
869
  'symbol': market['id'],
870
870
  };
871
871
  if (limit !== undefined) {
872
- request['size'] = limit;
872
+ request['size'] = Math.min(limit, 2000);
873
873
  }
874
874
  const response = await this.marketGetHistoryTrade(this.extend(request, params));
875
875
  //
@@ -508,7 +508,7 @@ class idex extends idex$1 {
508
508
  request['start'] = since;
509
509
  }
510
510
  if (limit !== undefined) {
511
- request['limit'] = limit;
511
+ request['limit'] = Math.min(limit, 1000);
512
512
  }
513
513
  // [
514
514
  // {