ccxt 4.1.61 → 4.1.63

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.
@@ -2550,7 +2550,7 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
2550
2550
  'createOrder': true,
2551
2551
  'fetchBalance': true,
2552
2552
  'fetchBidsAsks': false,
2553
- 'fetchClosedOrders': false,
2553
+ 'fetchClosedOrders': true,
2554
2554
  'fetchCurrencies': false,
2555
2555
  'fetchDepositAddress': false,
2556
2556
  'fetchDepositAddressesByNetwork': false,
@@ -2568,12 +2568,12 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
2568
2568
  'fetchOpenOrders': true,
2569
2569
  'fetchOrder': true,
2570
2570
  'fetchOrderBook': true,
2571
- 'fetchOrders': false,
2571
+ 'fetchOrders': true,
2572
2572
  'fetchPositions': false,
2573
2573
  'fetchStatus': false,
2574
2574
  'fetchTicker': false,
2575
2575
  'fetchTickers': false,
2576
- 'fetchTime': false,
2576
+ 'fetchTime': true,
2577
2577
  'fetchTrades': true,
2578
2578
  'fetchTradingFee': false,
2579
2579
  'fetchTradingFees': false,
@@ -2761,42 +2761,90 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
2761
2761
  },
2762
2762
  });
2763
2763
  }
2764
+ async fetchTime(params = {}) {
2765
+ /**
2766
+ * @method
2767
+ * @name alpaca#fetchTime
2768
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
2769
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
2770
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
2771
+ */
2772
+ const response = await this.traderPrivateGetV2Clock(params);
2773
+ //
2774
+ // {
2775
+ // timestamp: '2023-11-22T08:07:57.654738097-05:00',
2776
+ // is_open: false,
2777
+ // next_open: '2023-11-22T09:30:00-05:00',
2778
+ // next_close: '2023-11-22T16:00:00-05:00'
2779
+ // }
2780
+ //
2781
+ const timestamp = this.safeString(response, 'timestamp');
2782
+ const localTime = timestamp.slice(0, 23);
2783
+ const jetlagStrStart = timestamp.length - 6;
2784
+ const jetlagStrEnd = timestamp.length - 3;
2785
+ const jetlag = timestamp.slice(jetlagStrStart, jetlagStrEnd);
2786
+ const iso = this.parse8601(localTime) - this.parseToNumeric(jetlag) * 3600 * 1000;
2787
+ return iso;
2788
+ }
2764
2789
  async fetchMarkets(params = {}) {
2765
2790
  /**
2766
2791
  * @method
2767
2792
  * @name alpaca#fetchMarkets
2768
2793
  * @description retrieves data on all markets for alpaca
2794
+ * @see https://docs.alpaca.markets/reference/get-v2-assets
2769
2795
  * @param {object} [params] extra parameters specific to the exchange api endpoint
2770
2796
  * @returns {object[]} an array of objects representing market data
2771
2797
  */
2772
2798
  const request = {
2773
2799
  'asset_class': 'crypto',
2774
- 'tradeable': true,
2800
+ 'status': 'active',
2775
2801
  };
2776
2802
  const assets = await this.traderPrivateGetV2Assets(this.extend(request, params));
2777
2803
  //
2778
- // [
2779
- // {
2780
- // "id":"a3ba8ac0-166d-460b-b17a-1f035622dd47",
2781
- // "class":"crypto",
2782
- // "exchange":"FTXU",
2783
- // "symbol":"DOGEUSD",
2784
- // "name":"Dogecoin",
2785
- // "status":"active",
2786
- // "tradable":true,
2787
- // "marginable":false,
2788
- // "shortable":false,
2789
- // "easy_to_borrow":false,
2790
- // "fractionable":true,
2791
- // "min_order_size":"1",
2792
- // "min_trade_increment":"1",
2793
- // "price_increment":"0.0000005"
2794
- // }
2795
- // ]
2804
+ // [
2805
+ // {
2806
+ // "id": "c150e086-1e75-44e6-9c2c-093bb1e93139",
2807
+ // "class": "crypto",
2808
+ // "exchange": "CRYPTO",
2809
+ // "symbol": "BTC/USDT",
2810
+ // "name": "Bitcoin / USD Tether",
2811
+ // "status": "active",
2812
+ // "tradable": true,
2813
+ // "marginable": false,
2814
+ // "maintenance_margin_requirement": 100,
2815
+ // "shortable": false,
2816
+ // "easy_to_borrow": false,
2817
+ // "fractionable": true,
2818
+ // "attributes": [],
2819
+ // "min_order_size": "0.000026873",
2820
+ // "min_trade_increment": "0.000000001",
2821
+ // "price_increment": "1"
2822
+ // }
2823
+ // ]
2796
2824
  //
2797
2825
  return this.parseMarkets(assets);
2798
2826
  }
2799
2827
  parseMarket(asset) {
2828
+ //
2829
+ // {
2830
+ // "id": "c150e086-1e75-44e6-9c2c-093bb1e93139",
2831
+ // "class": "crypto",
2832
+ // "exchange": "CRYPTO",
2833
+ // "symbol": "BTC/USDT",
2834
+ // "name": "Bitcoin / USD Tether",
2835
+ // "status": "active",
2836
+ // "tradable": true,
2837
+ // "marginable": false,
2838
+ // "maintenance_margin_requirement": 100,
2839
+ // "shortable": false,
2840
+ // "easy_to_borrow": false,
2841
+ // "fractionable": true,
2842
+ // "attributes": [],
2843
+ // "min_order_size": "0.000026873",
2844
+ // "min_trade_increment": "0.000000001",
2845
+ // "price_increment": "1"
2846
+ // }
2847
+ //
2800
2848
  const marketId = this.safeString(asset, 'symbol');
2801
2849
  const parts = marketId.split('/');
2802
2850
  const baseId = this.safeString(parts, 0);
@@ -2936,21 +2984,17 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
2936
2984
  return this.parseTrades(symbolTrades, market, since, limit);
2937
2985
  }
2938
2986
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
2939
- //
2940
- // @method
2941
- // @name alpaca#fetchOrderBook
2942
- // @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
2943
- // @see https://docs.alpaca.markets/reference/cryptolatestorderbooks
2944
- // @param {string} symbol unified symbol of the market to fetch the order book for
2945
- // @param {int} [limit] the maximum amount of order book entries to return
2946
- // @param {object} [params] extra parameters specific to the alpaca api endpoint
2947
- // <<<<<<< HEAD
2948
- // @param {string} [params.loc] crypto location, default: us
2949
- // @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
2950
- // =======
2951
- // @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
2952
- // >>>>>>> f68b1b599ee41469fefa424f0efc9b6891549278
2953
- //
2987
+ /**
2988
+ * @method
2989
+ * @name alpaca#fetchOrderBook
2990
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
2991
+ * @see https://docs.alpaca.markets/reference/cryptolatestorderbooks
2992
+ * @param {string} symbol unified symbol of the market to fetch the order book for
2993
+ * @param {int} [limit] the maximum amount of order book entries to return
2994
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
2995
+ * @param {string} [params.loc] crypto location, default: us
2996
+ * @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
2997
+ */
2954
2998
  await this.loadMarkets();
2955
2999
  const market = this.market(symbol);
2956
3000
  const id = market['id'];
@@ -3125,6 +3169,7 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
3125
3169
  * @method
3126
3170
  * @name alpaca#createOrder
3127
3171
  * @description create a trade order
3172
+ * @see https://docs.alpaca.markets/reference/postorder
3128
3173
  * @param {string} symbol unified symbol of the market to create an order in
3129
3174
  * @param {string} type 'market', 'limit' or 'stop_limit'
3130
3175
  * @param {string} side 'buy' or 'sell'
@@ -3213,6 +3258,7 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
3213
3258
  * @method
3214
3259
  * @name alpaca#cancelOrder
3215
3260
  * @description cancels an open order
3261
+ * @see https://docs.alpaca.markets/reference/deleteorderbyorderid
3216
3262
  * @param {string} id order id
3217
3263
  * @param {string} symbol unified symbol of the market the order was made in
3218
3264
  * @param {object} [params] extra parameters specific to the alpaca api endpoint
@@ -3230,11 +3276,31 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
3230
3276
  //
3231
3277
  return this.safeValue(response, 'message', {});
3232
3278
  }
3279
+ async cancelAllOrders(symbol = undefined, params = {}) {
3280
+ /**
3281
+ * @method
3282
+ * @name alpaca#cancelAllOrders
3283
+ * @description cancel all open orders in a market
3284
+ * @see https://docs.alpaca.markets/reference/deleteallorders
3285
+ * @param {string} symbol alpaca cancelAllOrders cannot setting symbol, it will cancel all open orders
3286
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
3287
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3288
+ */
3289
+ await this.loadMarkets();
3290
+ const response = await this.traderPrivateDeleteV2Orders(params);
3291
+ if (Array.isArray(response)) {
3292
+ return this.parseOrders(response, undefined);
3293
+ }
3294
+ else {
3295
+ return response;
3296
+ }
3297
+ }
3233
3298
  async fetchOrder(id, symbol = undefined, params = {}) {
3234
3299
  /**
3235
3300
  * @method
3236
3301
  * @name alpaca#fetchOrder
3237
3302
  * @description fetches information on an order made by the user
3303
+ * @see https://docs.alpaca.markets/reference/getorderbyorderid
3238
3304
  * @param {string} symbol unified symbol of the market the order was made in
3239
3305
  * @param {object} [params] extra parameters specific to the alpaca api endpoint
3240
3306
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -3248,24 +3314,117 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
3248
3314
  const market = this.safeMarket(marketId);
3249
3315
  return this.parseOrder(order, market);
3250
3316
  }
3251
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3317
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3252
3318
  /**
3253
3319
  * @method
3254
- * @name alpaca#fetchOpenOrders
3255
- * @description fetch all unfilled currently open orders
3256
- * @param {string} symbol unified market symbol
3257
- * @param {int} [since] the earliest time in ms to fetch open orders for
3258
- * @param {int} [limit] the maximum number of open orders structures to retrieve
3320
+ * @name alpaca#fetchOrders
3321
+ * @description fetches information on multiple orders made by the user
3322
+ * @see https://docs.alpaca.markets/reference/getallorders
3323
+ * @param {string} symbol unified market symbol of the market orders were made in
3324
+ * @param {int} [since] the earliest time in ms to fetch orders for
3325
+ * @param {int} [limit] the maximum number of order structures to retrieve
3259
3326
  * @param {object} [params] extra parameters specific to the alpaca api endpoint
3327
+ * @param {int} [params.until] the latest time in ms to fetch orders for
3260
3328
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3261
3329
  */
3262
3330
  await this.loadMarkets();
3331
+ const request = {
3332
+ 'status': 'all',
3333
+ };
3263
3334
  let market = undefined;
3264
3335
  if (symbol !== undefined) {
3265
3336
  market = this.market(symbol);
3337
+ request['symbols'] = market['id'];
3266
3338
  }
3267
- const orders = await this.traderPrivateGetV2Orders(params);
3268
- return this.parseOrders(orders, market, since, limit);
3339
+ const until = this.safeInteger(params, 'until');
3340
+ if (until !== undefined) {
3341
+ params = this.omit(params, 'until');
3342
+ request['endTime'] = until;
3343
+ }
3344
+ if (since !== undefined) {
3345
+ request['after'] = since;
3346
+ }
3347
+ if (limit !== undefined) {
3348
+ request['limit'] = limit;
3349
+ }
3350
+ const response = await this.traderPrivateGetV2Orders(this.extend(request, params));
3351
+ //
3352
+ // [
3353
+ // {
3354
+ // "id": "cbaf12d7-69b8-49c0-a31b-b46af35c755c",
3355
+ // "client_order_id": "ccxt_b36156ae6fd44d098ac9c179bab33efd",
3356
+ // "created_at": "2023-11-17T04:21:42.234579Z",
3357
+ // "updated_at": "2023-11-17T04:22:34.442765Z",
3358
+ // "submitted_at": "2023-11-17T04:21:42.233357Z",
3359
+ // "filled_at": null,
3360
+ // "expired_at": null,
3361
+ // "canceled_at": "2023-11-17T04:22:34.399019Z",
3362
+ // "failed_at": null,
3363
+ // "replaced_at": null,
3364
+ // "replaced_by": null,
3365
+ // "replaces": null,
3366
+ // "asset_id": "77c6f47f-0939-4b23-b41e-47b4469c4bc8",
3367
+ // "symbol": "LTC/USDT",
3368
+ // "asset_class": "crypto",
3369
+ // "notional": null,
3370
+ // "qty": "0.001",
3371
+ // "filled_qty": "0",
3372
+ // "filled_avg_price": null,
3373
+ // "order_class": "",
3374
+ // "order_type": "limit",
3375
+ // "type": "limit",
3376
+ // "side": "sell",
3377
+ // "time_in_force": "gtc",
3378
+ // "limit_price": "1000",
3379
+ // "stop_price": null,
3380
+ // "status": "canceled",
3381
+ // "extended_hours": false,
3382
+ // "legs": null,
3383
+ // "trail_percent": null,
3384
+ // "trail_price": null,
3385
+ // "hwm": null,
3386
+ // "subtag": null,
3387
+ // "source": "access_key"
3388
+ // }
3389
+ // ]
3390
+ //
3391
+ return this.parseOrders(response, market, since, limit);
3392
+ }
3393
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3394
+ /**
3395
+ * @method
3396
+ * @name alpaca#fetchOpenOrders
3397
+ * @description fetch all unfilled currently open orders
3398
+ * @see https://docs.alpaca.markets/reference/getallorders
3399
+ * @param {string} symbol unified market symbol of the market orders were made in
3400
+ * @param {int} [since] the earliest time in ms to fetch orders for
3401
+ * @param {int} [limit] the maximum number of order structures to retrieve
3402
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
3403
+ * @param {int} [params.until] the latest time in ms to fetch orders for
3404
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3405
+ */
3406
+ const request = {
3407
+ 'status': 'open',
3408
+ };
3409
+ return await this.fetchOrders(symbol, since, limit, this.extend(request, params));
3410
+ }
3411
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3412
+ /**
3413
+ * @method
3414
+ * @name alpaca#fetchClosedOrders
3415
+ * @description fetches information on multiple closed orders made by the user
3416
+ * @see https://docs.alpaca.markets/reference/getallorders
3417
+ * @param {string} symbol unified market symbol of the market orders were made in
3418
+ * @param {int} [since] the earliest time in ms to fetch orders for
3419
+ * @param {int} [limit] the maximum number of order structures to retrieve
3420
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
3421
+ * @param {int} [params.until] the latest time in ms to fetch orders for
3422
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
3423
+ */
3424
+ const request = {
3425
+ 'status': 'closed',
3426
+ };
3427
+ return await this.fetchOrders(symbol, since, limit, this.extend(request, params));
3269
3428
  }
3270
3429
  parseOrder(order, market = undefined) {
3271
3430
  //
@@ -3320,9 +3479,11 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
3320
3479
  };
3321
3480
  }
3322
3481
  let orderType = this.safeString(order, 'order_type');
3323
- if (orderType.indexOf('limit') >= 0) {
3324
- // might be limit or stop-limit
3325
- orderType = 'limit';
3482
+ if (orderType !== undefined) {
3483
+ if (orderType.indexOf('limit') >= 0) {
3484
+ // might be limit or stop-limit
3485
+ orderType = 'limit';
3486
+ }
3326
3487
  }
3327
3488
  const datetime = this.safeString(order, 'submitted_at');
3328
3489
  const timestamp = this.parse8601(datetime);
@@ -8725,11 +8886,13 @@ class Exchange {
8725
8886
  }
8726
8887
  }
8727
8888
  if (!parseFee && (reducedLength === 0)) {
8728
- fee['cost'] = this.safeNumber(fee, 'cost');
8729
- if ('rate' in fee) {
8730
- fee['rate'] = this.safeNumber(fee, 'rate');
8889
+ // copy fee to avoid modification by reference
8890
+ const feeCopy = this.deepExtend(fee);
8891
+ feeCopy['cost'] = this.safeNumber(feeCopy, 'cost');
8892
+ if ('rate' in feeCopy) {
8893
+ feeCopy['rate'] = this.safeNumber(feeCopy, 'rate');
8731
8894
  }
8732
- reducedFees.push(fee);
8895
+ reducedFees.push(feeCopy);
8733
8896
  }
8734
8897
  order['fees'] = reducedFees;
8735
8898
  if (parseFee && (reducedLength === 1)) {
@@ -9014,11 +9177,13 @@ class Exchange {
9014
9177
  }
9015
9178
  }
9016
9179
  if (!parseFee && (reducedLength === 0)) {
9017
- fee['cost'] = this.safeNumber(fee, 'cost');
9018
- if ('rate' in fee) {
9019
- fee['rate'] = this.safeNumber(fee, 'rate');
9180
+ // copy fee to avoid modification by reference
9181
+ const feeCopy = this.deepExtend(fee);
9182
+ feeCopy['cost'] = this.safeNumber(feeCopy, 'cost');
9183
+ if ('rate' in feeCopy) {
9184
+ feeCopy['rate'] = this.safeNumber(feeCopy, 'rate');
9020
9185
  }
9021
- reducedFees.push(fee);
9186
+ reducedFees.push(feeCopy);
9022
9187
  }
9023
9188
  if (parseFees) {
9024
9189
  trade['fees'] = reducedFees;
@@ -17539,7 +17704,7 @@ class binance extends _abstract_binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
17539
17704
  'cm/income': 30,
17540
17705
  'um/account': 5,
17541
17706
  'cm/account': 5,
17542
- 'portfolio/repay-futures-switch': 3,
17707
+ 'repay-futures-switch': 3,
17543
17708
  'um/adlQuantile': 5,
17544
17709
  'cm/adlQuantile': 5,
17545
17710
  },
@@ -17558,8 +17723,8 @@ class binance extends _abstract_binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
17558
17723
  'cm/positionSide/dual': 1,
17559
17724
  'auto-collection': 0.6667,
17560
17725
  'bnb-transfer': 0.6667,
17561
- 'portfolio/repay-futures-switch': 150,
17562
- 'portfolio/repay-futures-negative-balance': 150,
17726
+ 'repay-futures-switch': 150,
17727
+ 'repay-futures-negative-balance': 150,
17563
17728
  'listenKey': 1,
17564
17729
  'asset-collection': 3,
17565
17730
  },
@@ -58733,10 +58898,10 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
58733
58898
  'CORS': undefined,
58734
58899
  'spot': true,
58735
58900
  'margin': false,
58736
- 'swap': undefined,
58737
- 'future': undefined,
58901
+ 'swap': true,
58902
+ 'future': false,
58738
58903
  'option': false,
58739
- 'cancelAllOrders': false,
58904
+ 'cancelAllOrders': true,
58740
58905
  'cancelOrder': true,
58741
58906
  'createOrder': true,
58742
58907
  'createStopLimitOrder': true,
@@ -58775,9 +58940,11 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
58775
58940
  'fetchTradingFees': false,
58776
58941
  'fetchTransactionFees': false,
58777
58942
  'fetchTransactions': false,
58778
- 'fetchTransfers': false,
58943
+ 'fetchTransfers': true,
58779
58944
  'fetchWithdrawals': true,
58780
- 'transfer': false,
58945
+ 'setLeverage': true,
58946
+ 'setMargin': true,
58947
+ 'transfer': true,
58781
58948
  'withdraw': true,
58782
58949
  },
58783
58950
  'timeframes': {
@@ -58794,66 +58961,142 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
58794
58961
  'urls': {
58795
58962
  'logo': 'https://user-images.githubusercontent.com/1294454/139516488-243a830d-05dd-446b-91c6-c1f18fe30c63.jpg',
58796
58963
  'api': {
58797
- 'v1': 'https://www.bitrue.com/api/v1',
58798
- 'v2': 'https://www.bitrue.com/api/v2',
58964
+ 'spot': 'https://www.bitrue.com/api',
58965
+ 'fapi': 'https://fapi.bitrue.com/fapi',
58966
+ 'dapi': 'https://fapi.bitrue.com/dapi',
58799
58967
  'kline': 'https://www.bitrue.com/kline-api',
58800
58968
  },
58801
58969
  'www': 'https://www.bitrue.com',
58802
58970
  'referral': 'https://www.bitrue.com/affiliate/landing?cn=600000&inviteCode=EZWETQE',
58803
58971
  'doc': [
58804
58972
  'https://github.com/Bitrue-exchange/bitrue-official-api-docs',
58973
+ 'https://www.bitrue.com/api-docs',
58805
58974
  ],
58806
58975
  'fees': 'https://bitrue.zendesk.com/hc/en-001/articles/4405479952537',
58807
58976
  },
58808
58977
  'api': {
58809
- 'kline': {
58810
- 'public': {
58811
- 'get': {
58812
- 'public.json': 1,
58813
- 'public{currency}.json': 1,
58978
+ 'spot': {
58979
+ 'kline': {
58980
+ 'public': {
58981
+ 'get': {
58982
+ 'public.json': 1,
58983
+ 'public{currency}.json': 1,
58984
+ },
58814
58985
  },
58815
58986
  },
58816
- },
58817
- 'v1': {
58818
- 'public': {
58819
- 'get': {
58820
- 'ping': 1,
58821
- 'time': 1,
58822
- 'exchangeInfo': 1,
58823
- 'depth': { 'cost': 1, 'byLimit': [[100, 1], [500, 5], [1000, 10]] },
58824
- 'trades': 1,
58825
- 'historicalTrades': 5,
58826
- 'aggTrades': 1,
58827
- 'ticker/24hr': { 'cost': 1, 'noSymbol': 40 },
58828
- 'ticker/price': { 'cost': 1, 'noSymbol': 2 },
58829
- 'ticker/bookTicker': { 'cost': 1, 'noSymbol': 2 },
58830
- 'market/kline': 1,
58987
+ 'v1': {
58988
+ 'public': {
58989
+ 'get': {
58990
+ 'ping': 1,
58991
+ 'time': 1,
58992
+ 'exchangeInfo': 1,
58993
+ 'depth': { 'cost': 1, 'byLimit': [[100, 1], [500, 5], [1000, 10]] },
58994
+ 'trades': 1,
58995
+ 'historicalTrades': 5,
58996
+ 'aggTrades': 1,
58997
+ 'ticker/24hr': { 'cost': 1, 'noSymbol': 40 },
58998
+ 'ticker/price': { 'cost': 1, 'noSymbol': 2 },
58999
+ 'ticker/bookTicker': { 'cost': 1, 'noSymbol': 2 },
59000
+ 'market/kline': 1,
59001
+ },
59002
+ },
59003
+ 'private': {
59004
+ 'get': {
59005
+ 'order': 1,
59006
+ 'openOrders': 1,
59007
+ 'allOrders': 5,
59008
+ 'account': 5,
59009
+ 'myTrades': { 'cost': 5, 'noSymbol': 40 },
59010
+ 'etf/net-value/{symbol}': 1,
59011
+ 'withdraw/history': 1,
59012
+ 'deposit/history': 1,
59013
+ },
59014
+ 'post': {
59015
+ 'order': 4,
59016
+ 'withdraw/commit': 1,
59017
+ },
59018
+ 'delete': {
59019
+ 'order': 1,
59020
+ },
58831
59021
  },
58832
59022
  },
58833
- 'private': {
58834
- 'get': {
58835
- 'order': 1,
58836
- 'openOrders': 1,
58837
- 'allOrders': 5,
58838
- 'account': 5,
58839
- 'myTrades': { 'cost': 5, 'noSymbol': 40 },
58840
- 'etf/net-value/{symbol}': 1,
58841
- 'withdraw/history': 1,
58842
- 'deposit/history': 1,
59023
+ 'v2': {
59024
+ 'private': {
59025
+ 'get': {
59026
+ 'myTrades': 5,
59027
+ },
58843
59028
  },
58844
- 'post': {
58845
- 'order': 4,
58846
- 'withdraw/commit': 1,
59029
+ },
59030
+ },
59031
+ 'fapi': {
59032
+ 'v1': {
59033
+ 'public': {
59034
+ 'get': {
59035
+ 'ping': 1,
59036
+ 'time': 1,
59037
+ 'contracts': 1,
59038
+ 'depth': 1,
59039
+ 'ticker': 1,
59040
+ 'klines': 1,
59041
+ },
58847
59042
  },
58848
- 'delete': {
58849
- 'order': 1,
59043
+ },
59044
+ 'v2': {
59045
+ 'private': {
59046
+ 'get': {
59047
+ 'myTrades': 1,
59048
+ 'openOrders': 1,
59049
+ 'order': 1,
59050
+ 'account': 1,
59051
+ 'leverageBracket': 1,
59052
+ 'commissionRate': 1,
59053
+ 'futures_transfer_history': 1,
59054
+ 'forceOrdersHistory': 1,
59055
+ },
59056
+ 'post': {
59057
+ 'positionMargin': 1,
59058
+ 'level_edit': 1,
59059
+ 'cancel': 1,
59060
+ 'order': 1,
59061
+ 'allOpenOrders': 1,
59062
+ 'futures_transfer': 1,
59063
+ },
58850
59064
  },
58851
59065
  },
58852
59066
  },
58853
- 'v2': {
58854
- 'private': {
58855
- 'get': {
58856
- 'myTrades': 5,
59067
+ 'dapi': {
59068
+ 'v1': {
59069
+ 'public': {
59070
+ 'get': {
59071
+ 'ping': 1,
59072
+ 'time': 1,
59073
+ 'contracts': 1,
59074
+ 'depth': 1,
59075
+ 'ticker': 1,
59076
+ 'klines': 1,
59077
+ },
59078
+ },
59079
+ },
59080
+ 'v2': {
59081
+ 'private': {
59082
+ 'get': {
59083
+ 'myTrades': 1,
59084
+ 'openOrders': 1,
59085
+ 'order': 1,
59086
+ 'account': 1,
59087
+ 'leverageBracket': 1,
59088
+ 'commissionRate': 1,
59089
+ 'futures_transfer_history': 1,
59090
+ 'forceOrdersHistory': 1,
59091
+ },
59092
+ 'post': {
59093
+ 'positionMargin': 1,
59094
+ 'level_edit': 1,
59095
+ 'cancel': 1,
59096
+ 'order': 1,
59097
+ 'allOpenOrders': 1,
59098
+ 'futures_transfer': 1,
59099
+ },
58857
59100
  },
58858
59101
  },
58859
59102
  },
@@ -58939,6 +59182,12 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
58939
59182
  },
58940
59183
  // exchange-specific options
58941
59184
  'options': {
59185
+ 'createMarketBuyOrderRequiresPrice': true,
59186
+ 'fetchMarkets': [
59187
+ 'spot',
59188
+ 'linear',
59189
+ 'inverse',
59190
+ ],
58942
59191
  // 'fetchTradesMethod': 'publicGetAggTrades', // publicGetTrades, publicGetHistoricalTrades
58943
59192
  'fetchMyTradesMethod': 'v2PrivateGetMyTrades',
58944
59193
  'hasAlreadyAuthenticatedSuccessfully': false,
@@ -58954,6 +59203,39 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
58954
59203
  'ERC20': 'ETH',
58955
59204
  'TRC20': 'TRX',
58956
59205
  },
59206
+ 'defaultType': 'spot',
59207
+ 'timeframes': {
59208
+ 'spot': {
59209
+ '1m': '1m',
59210
+ '5m': '5m',
59211
+ '15m': '15m',
59212
+ '30m': '30m',
59213
+ '1h': '1H',
59214
+ '2h': '2H',
59215
+ '4h': '4H',
59216
+ '12h': '12H',
59217
+ '1d': '1D',
59218
+ '1w': '1W',
59219
+ },
59220
+ 'future': {
59221
+ '1m': '1min',
59222
+ '5m': '5min',
59223
+ '15m': '15min',
59224
+ '30m': '30min',
59225
+ '1h': '1h',
59226
+ '1d': '1day',
59227
+ '1w': '1week',
59228
+ '1M': '1month',
59229
+ },
59230
+ },
59231
+ 'accountsByType': {
59232
+ 'spot': 'wallet',
59233
+ 'future': 'contract',
59234
+ 'swap': 'contract',
59235
+ 'funding': 'wallet',
59236
+ 'fund': 'wallet',
59237
+ 'contract': 'contract',
59238
+ },
58957
59239
  },
58958
59240
  'commonCurrencies': {
58959
59241
  'MIM': 'MIM Swarm',
@@ -58997,6 +59279,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
58997
59279
  '-1115': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
58998
59280
  '-1116': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
58999
59281
  '-1117': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
59282
+ '-1166': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder,
59000
59283
  '-1118': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
59001
59284
  '-1119': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
59002
59285
  '-1120': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
@@ -59006,12 +59289,15 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59006
59289
  '-1128': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
59007
59290
  '-1130': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
59008
59291
  '-1131': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest,
59292
+ '-1160': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder,
59293
+ '-1156': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder,
59009
59294
  '-2008': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.AuthenticationError,
59010
59295
  '-2010': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ExchangeError,
59011
59296
  '-2011': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.OrderNotFound,
59012
59297
  '-2013': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.OrderNotFound,
59013
59298
  '-2014': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.AuthenticationError,
59014
59299
  '-2015': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.AuthenticationError,
59300
+ '-2017': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InsufficientFunds,
59015
59301
  '-2019': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InsufficientFunds,
59016
59302
  '-3005': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InsufficientFunds,
59017
59303
  '-3006': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InsufficientFunds,
@@ -59033,9 +59319,6 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59033
59319
  },
59034
59320
  });
59035
59321
  }
59036
- costToPrecision(symbol, cost) {
59037
- return this.decimalToPrecision(cost, _base_functions_number_js__WEBPACK_IMPORTED_MODULE_1__/* .TRUNCATE */ .tk, this.markets[symbol]['precision']['quote'], this.precisionMode, this.paddingMode);
59038
- }
59039
59322
  currencyToPrecision(code, fee, networkCode = undefined) {
59040
59323
  // info is available in currencies only if the user has configured his api keys
59041
59324
  if (this.safeValue(this.currencies[code], 'precision') !== undefined) {
@@ -59053,10 +59336,11 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59053
59336
  * @method
59054
59337
  * @name bitrue#fetchStatus
59055
59338
  * @description the latest known information on the availability of the exchange API
59339
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#test-connectivity
59056
59340
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
59057
59341
  * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
59058
59342
  */
59059
- const response = await this.v1PublicGetPing(params);
59343
+ const response = await this.spotV1PublicGetPing(params);
59060
59344
  //
59061
59345
  // empty means working status.
59062
59346
  //
@@ -59078,10 +59362,11 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59078
59362
  * @method
59079
59363
  * @name bitrue#fetchTime
59080
59364
  * @description fetches the current integer timestamp in milliseconds from the exchange server
59365
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#check-server-time
59081
59366
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
59082
59367
  * @returns {int} the current integer timestamp in milliseconds from the exchange server
59083
59368
  */
59084
- const response = await this.v1PublicGetTime(params);
59369
+ const response = await this.spotV1PublicGetTime(params);
59085
59370
  //
59086
59371
  // {
59087
59372
  // "serverTime":1635467280514
@@ -59168,7 +59453,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59168
59453
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
59169
59454
  * @returns {object} an associative dictionary of currencies
59170
59455
  */
59171
- const response = await this.v1PublicGetExchangeInfo(params);
59456
+ const response = await this.spotV1PublicGetExchangeInfo(params);
59172
59457
  //
59173
59458
  // {
59174
59459
  // "timezone":"CTT",
@@ -59293,10 +59578,38 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59293
59578
  * @method
59294
59579
  * @name bitrue#fetchMarkets
59295
59580
  * @description retrieves data on all markets for bitrue
59581
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#exchangeInfo_endpoint
59582
+ * @see https://www.bitrue.com/api-docs#current-open-contract
59583
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#current-open-contract
59296
59584
  * @param {object} [params] extra parameters specific to the exchange api endpoint
59297
59585
  * @returns {object[]} an array of objects representing market data
59298
59586
  */
59299
- const response = await this.v1PublicGetExchangeInfo(params);
59587
+ const promisesRaw = [];
59588
+ const fetchMarkets = this.safeValue(this.options, 'fetchMarkets', ['spot', 'linear', 'inverse']);
59589
+ for (let i = 0; i < fetchMarkets.length; i++) {
59590
+ const marketType = fetchMarkets[i];
59591
+ if (marketType === 'spot') {
59592
+ promisesRaw.push(this.spotV1PublicGetExchangeInfo(params));
59593
+ }
59594
+ else if (marketType === 'linear') {
59595
+ promisesRaw.push(this.fapiV1PublicGetContracts(params));
59596
+ }
59597
+ else if (marketType === 'inverse') {
59598
+ promisesRaw.push(this.dapiV1PublicGetContracts(params));
59599
+ }
59600
+ else {
59601
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ExchangeError(this.id + ' fetchMarkets() this.options fetchMarkets "' + marketType + '" is not a supported market type');
59602
+ }
59603
+ }
59604
+ const promises = await Promise.all(promisesRaw);
59605
+ const spotMarkets = this.safeValue(this.safeValue(promises, 0), 'symbols', []);
59606
+ const futureMarkets = this.safeValue(promises, 1);
59607
+ const deliveryMarkets = this.safeValue(promises, 2);
59608
+ let markets = spotMarkets;
59609
+ markets = this.arrayConcat(markets, futureMarkets);
59610
+ markets = this.arrayConcat(markets, deliveryMarkets);
59611
+ //
59612
+ // spot
59300
59613
  //
59301
59614
  // {
59302
59615
  // "timezone":"CTT",
@@ -59338,19 +59651,70 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59338
59651
  // ],
59339
59652
  // }
59340
59653
  //
59654
+ // swap / delivery
59655
+ //
59656
+ // [
59657
+ // {
59658
+ // "symbol": "H-HT-USDT",
59659
+ // "pricePrecision": 8,
59660
+ // "side": 1,
59661
+ // "maxMarketVolume": 100000,
59662
+ // "multiplier": 6,
59663
+ // "minOrderVolume": 1,
59664
+ // "maxMarketMoney": 10000000,
59665
+ // "type": "H", // E: perpetual contract, S: test contract, others are mixed contract
59666
+ // "maxLimitVolume": 1000000,
59667
+ // "maxValidOrder": 20,
59668
+ // "multiplierCoin": "HT",
59669
+ // "minOrderMoney": 0.001,
59670
+ // "maxLimitMoney": 1000000,
59671
+ // "status": 1
59672
+ // }
59673
+ // ]
59674
+ //
59341
59675
  if (this.options['adjustForTimeDifference']) {
59342
59676
  await this.loadTimeDifference();
59343
59677
  }
59344
- const markets = this.safeValue(response, 'symbols', []);
59345
59678
  return this.parseMarkets(markets);
59346
59679
  }
59347
59680
  parseMarket(market) {
59348
59681
  const id = this.safeString(market, 'symbol');
59349
59682
  const lowercaseId = this.safeStringLower(market, 'symbol');
59350
- const baseId = this.safeString(market, 'baseAsset');
59351
- const quoteId = this.safeString(market, 'quoteAsset');
59683
+ const side = this.safeInteger(market, 'side'); // 1 linear, 0 inverse, undefined spot
59684
+ let type = undefined;
59685
+ let isLinear = undefined;
59686
+ let isInverse = undefined;
59687
+ if (side === undefined) {
59688
+ type = 'spot';
59689
+ }
59690
+ else {
59691
+ type = 'swap';
59692
+ isLinear = (side === 1);
59693
+ isInverse = (side === 0);
59694
+ }
59695
+ const isContract = (type !== 'spot');
59696
+ let baseId = this.safeString(market, 'baseAsset');
59697
+ let quoteId = this.safeString(market, 'quoteAsset');
59698
+ let settleId = undefined;
59699
+ let settle = undefined;
59700
+ if (isContract) {
59701
+ const symbolSplit = id.split('-');
59702
+ baseId = this.safeString(symbolSplit, 1);
59703
+ quoteId = this.safeString(symbolSplit, 2);
59704
+ if (isLinear) {
59705
+ settleId = quoteId;
59706
+ }
59707
+ else {
59708
+ settleId = baseId;
59709
+ }
59710
+ settle = this.safeCurrencyCode(settleId);
59711
+ }
59352
59712
  const base = this.safeCurrencyCode(baseId);
59353
59713
  const quote = this.safeCurrencyCode(quoteId);
59714
+ let symbol = base + '/' + quote;
59715
+ if (settle !== undefined) {
59716
+ symbol += ':' + settle;
59717
+ }
59354
59718
  const filters = this.safeValue(market, 'filters', []);
59355
59719
  const filtersByType = this.indexBy(filters, 'filterType');
59356
59720
  const status = this.safeString(market, 'status');
@@ -59360,27 +59724,36 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59360
59724
  const defaultAmountPrecision = this.safeString(market, 'quantityPrecision');
59361
59725
  const pricePrecision = this.safeString(priceFilter, 'priceScale', defaultPricePrecision);
59362
59726
  const amountPrecision = this.safeString(amountFilter, 'volumeScale', defaultAmountPrecision);
59727
+ const multiplier = this.safeString(market, 'multiplier');
59728
+ let maxQuantity = this.safeNumber(amountFilter, 'maxQty');
59729
+ if (maxQuantity === undefined) {
59730
+ maxQuantity = this.safeNumber(market, 'maxValidOrder');
59731
+ }
59732
+ let minCost = this.safeNumber(amountFilter, 'minVal');
59733
+ if (minCost === undefined) {
59734
+ minCost = this.safeNumber(market, 'minOrderMoney');
59735
+ }
59363
59736
  return {
59364
59737
  'id': id,
59365
59738
  'lowercaseId': lowercaseId,
59366
- 'symbol': base + '/' + quote,
59739
+ 'symbol': symbol,
59367
59740
  'base': base,
59368
59741
  'quote': quote,
59369
- 'settle': undefined,
59742
+ 'settle': settle,
59370
59743
  'baseId': baseId,
59371
59744
  'quoteId': quoteId,
59372
- 'settleId': undefined,
59373
- 'type': 'spot',
59374
- 'spot': true,
59745
+ 'settleId': settleId,
59746
+ 'type': type,
59747
+ 'spot': (type === 'spot'),
59375
59748
  'margin': false,
59376
- 'swap': false,
59749
+ 'swap': isContract,
59377
59750
  'future': false,
59378
59751
  'option': false,
59379
59752
  'active': (status === 'TRADING'),
59380
- 'contract': false,
59381
- 'linear': undefined,
59382
- 'inverse': undefined,
59383
- 'contractSize': undefined,
59753
+ 'contract': isContract,
59754
+ 'linear': isLinear,
59755
+ 'inverse': isInverse,
59756
+ 'contractSize': this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAbs(multiplier)),
59384
59757
  'expiry': undefined,
59385
59758
  'expiryDatetime': undefined,
59386
59759
  'strike': undefined,
@@ -59396,14 +59769,14 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59396
59769
  },
59397
59770
  'amount': {
59398
59771
  'min': this.safeNumber(amountFilter, 'minQty'),
59399
- 'max': this.safeNumber(amountFilter, 'maxQty'),
59772
+ 'max': maxQuantity,
59400
59773
  },
59401
59774
  'price': {
59402
59775
  'min': this.safeNumber(priceFilter, 'minPrice'),
59403
59776
  'max': this.safeNumber(priceFilter, 'maxPrice'),
59404
59777
  },
59405
59778
  'cost': {
59406
- 'min': this.safeNumber(amountFilter, 'minVal'),
59779
+ 'min': minCost,
59407
59780
  'max': undefined,
59408
59781
  },
59409
59782
  },
@@ -59412,18 +59785,64 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59412
59785
  };
59413
59786
  }
59414
59787
  parseBalance(response) {
59788
+ //
59789
+ // spot
59790
+ //
59791
+ // {
59792
+ // "makerCommission":0,
59793
+ // "takerCommission":0,
59794
+ // "buyerCommission":0,
59795
+ // "sellerCommission":0,
59796
+ // "updateTime":null,
59797
+ // "balances":[
59798
+ // {"asset":"sbr","free":"0","locked":"0"},
59799
+ // {"asset":"ksm","free":"0","locked":"0"},
59800
+ // {"asset":"neo3s","free":"0","locked":"0"},
59801
+ // ],
59802
+ // "canTrade":false,
59803
+ // "canWithdraw":false,
59804
+ // "canDeposit":false
59805
+ // }
59806
+ //
59807
+ // swap
59808
+ //
59809
+ // {
59810
+ // "account":[
59811
+ // {
59812
+ // "marginCoin":"USDT",
59813
+ // "coinPrecious":4,
59814
+ // "accountNormal":1010.4043400372839856,
59815
+ // "accountLock":2.9827889600000006,
59816
+ // "partPositionNormal":0,
59817
+ // "totalPositionNormal":0,
59818
+ // "achievedAmount":0,
59819
+ // "unrealizedAmount":0,
59820
+ // "totalMarginRate":0,
59821
+ // "totalEquity":1010.4043400372839856,
59822
+ // "partEquity":0,
59823
+ // "totalCost":0,
59824
+ // "sumMarginRate":0,
59825
+ // "sumOpenRealizedAmount":0,
59826
+ // "canUseTrialFund":0,
59827
+ // "sumMaintenanceMargin":null,
59828
+ // "futureModel":null,
59829
+ // "positionVos":[]
59830
+ // }
59831
+ // ]
59832
+ // }
59833
+ //
59415
59834
  const result = {
59416
59835
  'info': response,
59417
59836
  };
59418
59837
  const timestamp = this.safeInteger(response, 'updateTime');
59419
- const balances = this.safeValue(response, 'balances', []);
59838
+ const balances = this.safeValue2(response, 'balances', 'account', []);
59420
59839
  for (let i = 0; i < balances.length; i++) {
59421
59840
  const balance = balances[i];
59422
- const currencyId = this.safeString(balance, 'asset');
59841
+ const currencyId = this.safeString2(balance, 'asset', 'marginCoin');
59423
59842
  const code = this.safeCurrencyCode(currencyId);
59424
59843
  const account = this.account();
59425
- account['free'] = this.safeString(balance, 'free');
59426
- account['used'] = this.safeString(balance, 'locked');
59844
+ account['free'] = this.safeString2(balance, 'free', 'accountNormal');
59845
+ account['used'] = this.safeString2(balance, 'locked', 'accountLock');
59427
59846
  result[code] = account;
59428
59847
  }
59429
59848
  result['timestamp'] = timestamp;
@@ -59435,35 +59854,122 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59435
59854
  * @method
59436
59855
  * @name bitrue#fetchBalance
59437
59856
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
59857
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#account-information-user_data
59858
+ * @see https://www.bitrue.com/api-docs#account-information-v2-user_data-hmac-sha256
59859
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#account-information-v2-user_data-hmac-sha256
59438
59860
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
59861
+ * @param {string} [params.type] 'future', 'delivery', 'spot', 'swap'
59862
+ * @param {string} [params.subType] 'linear', 'inverse'
59439
59863
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
59440
59864
  */
59441
59865
  await this.loadMarkets();
59442
- const response = await this.v1PrivateGetAccount(params);
59443
- //
59444
- // {
59445
- // "makerCommission":0,
59446
- // "takerCommission":0,
59447
- // "buyerCommission":0,
59448
- // "sellerCommission":0,
59449
- // "updateTime":null,
59450
- // "balances":[
59451
- // {"asset":"sbr","free":"0","locked":"0"},
59452
- // {"asset":"ksm","free":"0","locked":"0"},
59453
- // {"asset":"neo3s","free":"0","locked":"0"},
59454
- // ],
59455
- // "canTrade":false,
59456
- // "canWithdraw":false,
59457
- // "canDeposit":false
59458
- // }
59459
- //
59460
- return this.parseBalance(response);
59866
+ let type = undefined;
59867
+ [type, params] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
59868
+ let subType = undefined;
59869
+ [subType, params] = this.handleSubTypeAndParams('fetchBalance', undefined, params);
59870
+ let response = undefined;
59871
+ let result = undefined;
59872
+ if (type === 'swap') {
59873
+ if (subType !== undefined && subType === 'inverse') {
59874
+ response = await this.dapiV2PrivateGetAccount(params);
59875
+ result = this.safeValue(response, 'data', {});
59876
+ //
59877
+ // {
59878
+ // "code":"0",
59879
+ // "msg":"Success",
59880
+ // "data":{
59881
+ // "account":[
59882
+ // {
59883
+ // "marginCoin":"USD",
59884
+ // "coinPrecious":4,
59885
+ // "accountNormal":1010.4043400372839856,
59886
+ // "accountLock":2.9827889600000006,
59887
+ // "partPositionNormal":0,
59888
+ // "totalPositionNormal":0,
59889
+ // "achievedAmount":0,
59890
+ // "unrealizedAmount":0,
59891
+ // "totalMarginRate":0,
59892
+ // "totalEquity":1010.4043400372839856,
59893
+ // "partEquity":0,
59894
+ // "totalCost":0,
59895
+ // "sumMarginRate":0,
59896
+ // "sumOpenRealizedAmount":0,
59897
+ // "canUseTrialFund":0,
59898
+ // "sumMaintenanceMargin":null,
59899
+ // "futureModel":null,
59900
+ // "positionVos":[]
59901
+ // }
59902
+ // ]
59903
+ // }
59904
+ // }
59905
+ //
59906
+ }
59907
+ else {
59908
+ response = await this.fapiV2PrivateGetAccount(params);
59909
+ result = this.safeValue(response, 'data', {});
59910
+ //
59911
+ // {
59912
+ // "code":"0",
59913
+ // "msg":"Success",
59914
+ // "data":{
59915
+ // "account":[
59916
+ // {
59917
+ // "marginCoin":"USDT",
59918
+ // "coinPrecious":4,
59919
+ // "accountNormal":1010.4043400372839856,
59920
+ // "accountLock":2.9827889600000006,
59921
+ // "partPositionNormal":0,
59922
+ // "totalPositionNormal":0,
59923
+ // "achievedAmount":0,
59924
+ // "unrealizedAmount":0,
59925
+ // "totalMarginRate":0,
59926
+ // "totalEquity":1010.4043400372839856,
59927
+ // "partEquity":0,
59928
+ // "totalCost":0,
59929
+ // "sumMarginRate":0,
59930
+ // "sumOpenRealizedAmount":0,
59931
+ // "canUseTrialFund":0,
59932
+ // "sumMaintenanceMargin":null,
59933
+ // "futureModel":null,
59934
+ // "positionVos":[]
59935
+ // }
59936
+ // ]
59937
+ // }
59938
+ // }
59939
+ //
59940
+ }
59941
+ }
59942
+ else {
59943
+ response = await this.spotV1PrivateGetAccount(params);
59944
+ result = response;
59945
+ //
59946
+ // {
59947
+ // "makerCommission":0,
59948
+ // "takerCommission":0,
59949
+ // "buyerCommission":0,
59950
+ // "sellerCommission":0,
59951
+ // "updateTime":null,
59952
+ // "balances":[
59953
+ // {"asset":"sbr","free":"0","locked":"0"},
59954
+ // {"asset":"ksm","free":"0","locked":"0"},
59955
+ // {"asset":"neo3s","free":"0","locked":"0"},
59956
+ // ],
59957
+ // "canTrade":false,
59958
+ // "canWithdraw":false,
59959
+ // "canDeposit":false
59960
+ // }
59961
+ //
59962
+ }
59963
+ return this.parseBalance(result);
59461
59964
  }
59462
59965
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
59463
59966
  /**
59464
59967
  * @method
59465
59968
  * @name bitrue#fetchOrderBook
59466
59969
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
59970
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#order-book
59971
+ * @see https://www.bitrue.com/api-docs#order-book
59972
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#order-book
59467
59973
  * @param {string} symbol unified symbol of the market to fetch the order book for
59468
59974
  * @param {int} [limit] the maximum amount of order book entries to return
59469
59975
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
@@ -59471,13 +59977,41 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59471
59977
  */
59472
59978
  await this.loadMarkets();
59473
59979
  const market = this.market(symbol);
59474
- const request = {
59475
- 'symbol': market['id'],
59476
- };
59477
- if (limit !== undefined) {
59478
- request['limit'] = limit; // default 100, max 1000, see https://github.com/Bitrue-exchange/bitrue-official-api-docs#order-book
59980
+ let response = undefined;
59981
+ if (market['swap']) {
59982
+ const request = {
59983
+ 'contractName': market['id'],
59984
+ };
59985
+ if (limit !== undefined) {
59986
+ if (limit > 100) {
59987
+ limit = 100;
59988
+ }
59989
+ request['limit'] = limit; // default 100, max 100, see https://www.bitrue.com/api-docs#order-book
59990
+ }
59991
+ if (market['linear']) {
59992
+ response = await this.fapiV1PublicGetDepth(this.extend(request, params));
59993
+ }
59994
+ else if (market['inverse']) {
59995
+ response = await this.dapiV1PublicGetDepth(this.extend(request, params));
59996
+ }
59997
+ }
59998
+ else if (market['spot']) {
59999
+ const request = {
60000
+ 'symbol': market['id'],
60001
+ };
60002
+ if (limit !== undefined) {
60003
+ if (limit > 1000) {
60004
+ limit = 1000;
60005
+ }
60006
+ request['limit'] = limit; // default 100, max 1000, see https://github.com/Bitrue-exchange/bitrue-official-api-docs#order-book
60007
+ }
60008
+ response = await this.spotV1PublicGetDepth(this.extend(request, params));
60009
+ }
60010
+ else {
60011
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchOrderBook only support spot & swap markets');
59479
60012
  }
59480
- const response = await this.v1PublicGetDepth(this.extend(request, params));
60013
+ //
60014
+ // spot
59481
60015
  //
59482
60016
  // {
59483
60017
  // "lastUpdateId":1635474910177,
@@ -59493,7 +60027,16 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59493
60027
  // ]
59494
60028
  // }
59495
60029
  //
59496
- const orderbook = this.parseOrderBook(response, symbol);
60030
+ // swap
60031
+ //
60032
+ // {
60033
+ // "asks": [[34916.5, 2582], [34916.6, 2193], [34916.7, 2629], [34916.8, 3478], [34916.9, 2718]],
60034
+ // "bids": [[34916.4, 92065], [34916.3, 25703], [34916.2, 37259], [34916.1, 26446], [34916, 44456]],
60035
+ // "time": 1699338305000
60036
+ // }
60037
+ //
60038
+ const timestamp = this.safeInteger(response, 'time');
60039
+ const orderbook = this.parseOrderBook(response, symbol, timestamp);
59497
60040
  orderbook['nonce'] = this.safeInteger(response, 'lastUpdateId');
59498
60041
  return orderbook;
59499
60042
  }
@@ -59512,39 +60055,56 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59512
60055
  // fetchTicker
59513
60056
  //
59514
60057
  // {
59515
- // "id":397945892,
59516
- // "last":"1.143411",
59517
- // "lowestAsk":"1.144223",
59518
- // "highestBid":"1.141696",
59519
- // "percentChange":"-0.001432",
59520
- // "baseVolume":"338287",
59521
- // "quoteVolume":"415013.244366",
59522
- // "isFrozen":"0",
59523
- // "high24hr":"1.370087",
59524
- // "low24hr":"1.370087",
60058
+ // "symbol": "BNBBTC",
60059
+ // "priceChange": "0.000248",
60060
+ // "priceChangePercent": "3.5500",
60061
+ // "weightedAvgPrice": null,
60062
+ // "prevClosePrice": null,
60063
+ // "lastPrice": "0.007226",
60064
+ // "lastQty": null,
60065
+ // "bidPrice": "0.007208",
60066
+ // "askPrice": "0.007240",
60067
+ // "openPrice": "0.006978",
60068
+ // "highPrice": "0.007295",
60069
+ // "lowPrice": "0.006935",
60070
+ // "volume": "11749.86",
60071
+ // "quoteVolume": "84.1066211",
60072
+ // "openTime": 0,
60073
+ // "closeTime": 0,
60074
+ // "firstId": 0,
60075
+ // "lastId": 0,
60076
+ // "count": 0
59525
60077
  // }
59526
60078
  //
59527
60079
  const symbol = this.safeSymbol(undefined, market);
59528
- const last = this.safeString(ticker, 'last');
60080
+ const last = this.safeString2(ticker, 'lastPrice', 'last');
60081
+ const timestamp = this.safeInteger(ticker, 'time');
60082
+ let percentage = undefined;
60083
+ if (market['swap']) {
60084
+ percentage = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(this.safeString(ticker, 'rose'), '100');
60085
+ }
60086
+ else {
60087
+ percentage = this.safeString(ticker, 'priceChangePercent');
60088
+ }
59529
60089
  return this.safeTicker({
59530
60090
  'symbol': symbol,
59531
- 'timestamp': undefined,
59532
- 'datetime': undefined,
59533
- 'high': this.safeString(ticker, 'high24hr'),
59534
- 'low': this.safeString(ticker, 'low24hr'),
59535
- 'bid': this.safeString2(ticker, 'highestBid', 'bidPrice'),
60091
+ 'timestamp': timestamp,
60092
+ 'datetime': this.iso8601(timestamp),
60093
+ 'high': this.safeString2(ticker, 'highPrice', 'high'),
60094
+ 'low': this.safeString2(ticker, 'lowPrice', 'low'),
60095
+ 'bid': this.safeString2(ticker, 'bidPrice', 'buy'),
59536
60096
  'bidVolume': this.safeString(ticker, 'bidQty'),
59537
- 'ask': this.safeString2(ticker, 'lowestAsk', 'askPrice'),
60097
+ 'ask': this.safeString2(ticker, 'askPrice', 'sell'),
59538
60098
  'askVolume': this.safeString(ticker, 'askQty'),
59539
- 'vwap': undefined,
59540
- 'open': undefined,
60099
+ 'vwap': this.safeString(ticker, 'weightedAvgPrice'),
60100
+ 'open': this.safeString(ticker, 'openPrice'),
59541
60101
  'close': last,
59542
60102
  'last': last,
59543
60103
  'previousClose': undefined,
59544
- 'change': undefined,
59545
- 'percentage': _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(this.safeString(ticker, 'percentChange'), '10000'),
60104
+ 'change': this.safeString(ticker, 'priceChange'),
60105
+ 'percentage': percentage,
59546
60106
  'average': undefined,
59547
- 'baseVolume': this.safeString(ticker, 'baseVolume'),
60107
+ 'baseVolume': this.safeString2(ticker, 'volume', 'vol'),
59548
60108
  'quoteVolume': this.safeString(ticker, 'quoteVolume'),
59549
60109
  'info': ticker,
59550
60110
  }, market);
@@ -59554,52 +60114,87 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59554
60114
  * @method
59555
60115
  * @name bitrue#fetchTicker
59556
60116
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
60117
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#24hr-ticker-price-change-statistics
60118
+ * @see https://www.bitrue.com/api-docs#ticker
60119
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#ticker
59557
60120
  * @param {string} symbol unified symbol of the market to fetch the ticker for
59558
60121
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
59559
60122
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
59560
60123
  */
59561
60124
  await this.loadMarkets();
59562
60125
  const market = this.market(symbol);
59563
- const uppercaseBaseId = this.safeStringUpper(market, 'baseId');
59564
- const uppercaseQuoteId = this.safeStringUpper(market, 'quoteId');
59565
- const request = {
59566
- 'currency': uppercaseQuoteId,
59567
- 'command': 'returnTicker',
59568
- };
59569
- const response = await this.klinePublicGetPublicCurrencyJson(this.extend(request, params));
60126
+ let response = undefined;
60127
+ let data = undefined;
60128
+ if (market['swap']) {
60129
+ const request = {
60130
+ 'contractName': market['id'],
60131
+ };
60132
+ if (market['linear']) {
60133
+ response = await this.fapiV1PublicGetTicker(this.extend(request, params));
60134
+ }
60135
+ else if (market['inverse']) {
60136
+ response = await this.dapiV1PublicGetTicker(this.extend(request, params));
60137
+ }
60138
+ data = response;
60139
+ }
60140
+ else if (market['spot']) {
60141
+ const request = {
60142
+ 'symbol': market['id'],
60143
+ };
60144
+ response = await this.spotV1PublicGetTicker24hr(this.extend(request, params));
60145
+ data = this.safeValue(response, 0, {});
60146
+ }
60147
+ else {
60148
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchTicker only support spot & swap markets');
60149
+ }
60150
+ //
60151
+ // spot
60152
+ //
60153
+ // [{
60154
+ // symbol: 'BTCUSDT',
60155
+ // priceChange: '105.20',
60156
+ // priceChangePercent: '0.3000',
60157
+ // weightedAvgPrice: null,
60158
+ // prevClosePrice: null,
60159
+ // lastPrice: '34905.21',
60160
+ // lastQty: null,
60161
+ // bidPrice: '34905.21',
60162
+ // askPrice: '34905.22',
60163
+ // openPrice: '34800.01',
60164
+ // highPrice: '35276.33',
60165
+ // lowPrice: '34787.51',
60166
+ // volume: '12549.6481',
60167
+ // quoteVolume: '439390492.917',
60168
+ // openTime: '0',
60169
+ // closeTime: '0',
60170
+ // firstId: '0',
60171
+ // lastId: '0',
60172
+ // count: '0'
60173
+ // }]
60174
+ //
60175
+ // swap
59570
60176
  //
59571
60177
  // {
59572
- // "code":"200",
59573
- // "msg":"success",
59574
- // "data":{
59575
- // "DODO3S_USDT":{
59576
- // "id":397945892,
59577
- // "last":"1.143411",
59578
- // "lowestAsk":"1.144223",
59579
- // "highestBid":"1.141696",
59580
- // "percentChange":"-0.001432",
59581
- // "baseVolume":"338287",
59582
- // "quoteVolume":"415013.244366",
59583
- // "isFrozen":"0",
59584
- // "high24hr":"1.370087",
59585
- // "low24hr":"1.370087"
59586
- // }
59587
- // }
60178
+ // "high": "35296",
60179
+ // "vol": "779308354",
60180
+ // "last": "34884.1",
60181
+ // "low": "34806.7",
60182
+ // "buy": 34883.9,
60183
+ // "sell": 34884,
60184
+ // "rose": "-0.0027957315",
60185
+ // "time": 1699348013000
59588
60186
  // }
59589
60187
  //
59590
- const data = this.safeValue(response, 'data', {});
59591
- const id = uppercaseBaseId + '_' + uppercaseQuoteId;
59592
- const ticker = this.safeValue(data, id);
59593
- if (ticker === undefined) {
59594
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ExchangeError(this.id + ' fetchTicker() could not find the ticker for ' + market['symbol']);
59595
- }
59596
- return this.parseTicker(ticker, market);
60188
+ return this.parseTicker(data, market);
59597
60189
  }
59598
60190
  async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
59599
60191
  /**
59600
60192
  * @method
59601
60193
  * @name bitrue#fetchOHLCV
59602
60194
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
60195
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#kline-data
60196
+ * @see https://www.bitrue.com/api-docs#kline-candlestick-data
60197
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#kline-candlestick-data
59603
60198
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
59604
60199
  * @param {string} timeframe the length of time each candle represents
59605
60200
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -59609,14 +60204,54 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59609
60204
  */
59610
60205
  await this.loadMarkets();
59611
60206
  const market = this.market(symbol);
59612
- const request = {
59613
- 'symbol': market['id'],
59614
- 'scale': this.safeString(this.timeframes, timeframe, timeframe),
59615
- };
59616
- if (limit !== undefined) {
59617
- request['limit'] = limit;
60207
+ const timeframes = this.safeValue(this.options, 'timeframes', {});
60208
+ let response = undefined;
60209
+ let data = undefined;
60210
+ if (market['swap']) {
60211
+ const timeframesFuture = this.safeValue(timeframes, 'future', {});
60212
+ const request = {
60213
+ 'contractName': market['id'],
60214
+ // 1min / 5min / 15min / 30min / 1h / 1day / 1week / 1month
60215
+ 'interval': this.safeString(timeframesFuture, timeframe, '1min'),
60216
+ };
60217
+ if (limit !== undefined) {
60218
+ if (limit > 300) {
60219
+ limit = 300;
60220
+ }
60221
+ request['limit'] = limit;
60222
+ }
60223
+ if (market['linear']) {
60224
+ response = await this.fapiV1PublicGetKlines(this.extend(request, params));
60225
+ }
60226
+ else if (market['inverse']) {
60227
+ response = await this.dapiV1PublicGetKlines(this.extend(request, params));
60228
+ }
60229
+ data = response;
60230
+ }
60231
+ else if (market['spot']) {
60232
+ const timeframesSpot = this.safeValue(timeframes, 'spot', {});
60233
+ const request = {
60234
+ 'symbol': market['id'],
60235
+ // 1m / 5m / 15m / 30m / 1H / 2H / 4H / 12H / 1D / 1W
60236
+ 'scale': this.safeString(timeframesSpot, timeframe, '1m'),
60237
+ };
60238
+ if (limit !== undefined) {
60239
+ if (limit > 1440) {
60240
+ limit = 1440;
60241
+ }
60242
+ request['limit'] = limit;
60243
+ }
60244
+ if (since !== undefined) {
60245
+ request['fromIdx'] = since;
60246
+ }
60247
+ response = await this.spotV1PublicGetMarketKline(this.extend(request, params));
60248
+ data = this.safeValue(response, 'data', []);
60249
+ }
60250
+ else {
60251
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchOHLCV only support spot & swap markets');
59618
60252
  }
59619
- const response = await this.v1PublicGetMarketKline(this.extend(request, params));
60253
+ //
60254
+ // spot
59620
60255
  //
59621
60256
  // {
59622
60257
  // "symbol":"BTCUSDT",
@@ -59634,10 +60269,24 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59634
60269
  // ]
59635
60270
  // }
59636
60271
  //
59637
- const data = this.safeValue(response, 'data', []);
60272
+ // swap
60273
+ //
60274
+ // [
60275
+ // {
60276
+ // "high": "35360.7",
60277
+ // "vol": "110288",
60278
+ // "low": "35347.9",
60279
+ // "idx": 1699411680000,
60280
+ // "close": "35347.9",
60281
+ // "open": "35349.4"
60282
+ // }
60283
+ // ]
60284
+ //
59638
60285
  return this.parseOHLCVs(data, market, timeframe, since, limit);
59639
60286
  }
59640
60287
  parseOHLCV(ohlcv, market = undefined) {
60288
+ //
60289
+ // spot
59641
60290
  //
59642
60291
  // {
59643
60292
  // "i":"1660825020",
@@ -59649,13 +60298,28 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59649
60298
  // "o":"23508.34"
59650
60299
  // }
59651
60300
  //
60301
+ // swap
60302
+ //
60303
+ // {
60304
+ // "high": "35360.7",
60305
+ // "vol": "110288",
60306
+ // "low": "35347.9",
60307
+ // "idx": 1699411680000,
60308
+ // "close": "35347.9",
60309
+ // "open": "35349.4"
60310
+ // }
60311
+ //
60312
+ let timestamp = this.safeTimestamp(ohlcv, 'i');
60313
+ if (timestamp === undefined) {
60314
+ timestamp = this.safeInteger(ohlcv, 'idx');
60315
+ }
59652
60316
  return [
59653
- this.safeTimestamp(ohlcv, 'i'),
59654
- this.safeNumber(ohlcv, 'o'),
59655
- this.safeNumber(ohlcv, 'h'),
59656
- this.safeNumber(ohlcv, 'l'),
59657
- this.safeNumber(ohlcv, 'c'),
59658
- this.safeNumber(ohlcv, 'v'),
60317
+ timestamp,
60318
+ this.safeNumber2(ohlcv, 'o', 'open'),
60319
+ this.safeNumber2(ohlcv, 'h', 'high'),
60320
+ this.safeNumber2(ohlcv, 'l', 'low'),
60321
+ this.safeNumber2(ohlcv, 'c', 'close'),
60322
+ this.safeNumber2(ohlcv, 'v', 'vol'),
59659
60323
  ];
59660
60324
  }
59661
60325
  async fetchBidsAsks(symbols = undefined, params = {}) {
@@ -59664,20 +60328,40 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59664
60328
  * @name bitrue#fetchBidsAsks
59665
60329
  * @description fetches the bid and ask price and volume for multiple markets
59666
60330
  * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#symbol-order-book-ticker
60331
+ * @see https://www.bitrue.com/api-docs#ticker
60332
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#ticker
59667
60333
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
59668
60334
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
59669
60335
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
59670
60336
  */
59671
60337
  await this.loadMarkets();
59672
- symbols = this.marketSymbols(symbols);
59673
- let market = undefined;
59674
- const request = {};
59675
- if (symbols !== undefined) {
59676
- const first = this.safeString(symbols, 0);
59677
- market = this.market(first);
59678
- request['symbol'] = market['id'];
60338
+ symbols = this.marketSymbols(symbols, undefined, false);
60339
+ const first = this.safeString(symbols, 0);
60340
+ const market = this.market(first);
60341
+ let response = undefined;
60342
+ if (market['swap']) {
60343
+ const request = {
60344
+ 'contractName': market['id'],
60345
+ };
60346
+ if (market['linear']) {
60347
+ response = await this.fapiV1PublicGetTicker(this.extend(request, params));
60348
+ }
60349
+ else if (market['inverse']) {
60350
+ response = await this.dapiV1PublicGetTicker(this.extend(request, params));
60351
+ }
60352
+ }
60353
+ else if (market['spot']) {
60354
+ const request = {
60355
+ 'symbol': market['id'],
60356
+ };
60357
+ response = await this.spotV1PublicGetTickerBookTicker(this.extend(request, params));
60358
+ }
60359
+ else {
60360
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchBidsAsks only support spot & swap markets');
59679
60361
  }
59680
- const response = await this.v1PublicGetTickerBookTicker(this.extend(request, params));
60362
+ //
60363
+ // spot
60364
+ //
59681
60365
  // {
59682
60366
  // "symbol": "LTCBTC",
59683
60367
  // "bidPrice": "4.00000000",
@@ -59685,6 +60369,20 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59685
60369
  // "askPrice": "4.00000200",
59686
60370
  // "askQty": "9.00000000"
59687
60371
  // }
60372
+ //
60373
+ // swap
60374
+ //
60375
+ // {
60376
+ // "high": "35296",
60377
+ // "vol": "779308354",
60378
+ // "last": "34884.1",
60379
+ // "low": "34806.7",
60380
+ // "buy": 34883.9,
60381
+ // "sell": 34884,
60382
+ // "rose": "-0.0027957315",
60383
+ // "time": 1699348013000
60384
+ // }
60385
+ //
59688
60386
  const data = {};
59689
60387
  data[market['id']] = response;
59690
60388
  return this.parseTickers(data, symbols);
@@ -59694,65 +60392,102 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59694
60392
  * @method
59695
60393
  * @name bitrue#fetchTickers
59696
60394
  * @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market
60395
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#24hr-ticker-price-change-statistics
60396
+ * @see https://www.bitrue.com/api-docs#ticker
60397
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#ticker
59697
60398
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
59698
60399
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
59699
60400
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
59700
60401
  */
59701
60402
  await this.loadMarkets();
59702
- const request = {
59703
- 'command': 'returnTicker',
59704
- };
59705
- const response = await this.klinePublicGetPublicJson(this.extend(request, params));
60403
+ symbols = this.marketSymbols(symbols);
60404
+ let response = undefined;
60405
+ let data = undefined;
60406
+ const request = {};
60407
+ let type = undefined;
60408
+ if (symbols !== undefined) {
60409
+ const first = this.safeString(symbols, 0);
60410
+ const market = this.market(first);
60411
+ if (market['swap']) {
60412
+ request['contractName'] = market['id'];
60413
+ if (market['linear']) {
60414
+ response = await this.fapiV1PublicGetTicker(this.extend(request, params));
60415
+ }
60416
+ else if (market['inverse']) {
60417
+ response = await this.dapiV1PublicGetTicker(this.extend(request, params));
60418
+ }
60419
+ response['symbol'] = market['id'];
60420
+ data = [response];
60421
+ }
60422
+ else if (market['spot']) {
60423
+ request['symbol'] = market['id'];
60424
+ response = await this.spotV1PublicGetTicker24hr(this.extend(request, params));
60425
+ data = response;
60426
+ }
60427
+ else {
60428
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchTickers only support spot & swap markets');
60429
+ }
60430
+ }
60431
+ else {
60432
+ [type, params] = this.handleMarketTypeAndParams('fetchTickers', undefined, params);
60433
+ if (type !== 'spot') {
60434
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchTickers only support spot when symbols is not set');
60435
+ }
60436
+ response = await this.spotV1PublicGetTicker24hr(this.extend(request, params));
60437
+ data = response;
60438
+ }
60439
+ //
60440
+ // spot
60441
+ //
60442
+ // [{
60443
+ // symbol: 'BTCUSDT',
60444
+ // priceChange: '105.20',
60445
+ // priceChangePercent: '0.3000',
60446
+ // weightedAvgPrice: null,
60447
+ // prevClosePrice: null,
60448
+ // lastPrice: '34905.21',
60449
+ // lastQty: null,
60450
+ // bidPrice: '34905.21',
60451
+ // askPrice: '34905.22',
60452
+ // openPrice: '34800.01',
60453
+ // highPrice: '35276.33',
60454
+ // lowPrice: '34787.51',
60455
+ // volume: '12549.6481',
60456
+ // quoteVolume: '439390492.917',
60457
+ // openTime: '0',
60458
+ // closeTime: '0',
60459
+ // firstId: '0',
60460
+ // lastId: '0',
60461
+ // count: '0'
60462
+ // }]
60463
+ //
60464
+ // swap
59706
60465
  //
59707
60466
  // {
59708
- // "code":"200",
59709
- // "msg":"success",
59710
- // "data":{
59711
- // "DODO3S_USDT":{
59712
- // "id":397945892,
59713
- // "last":"1.143411",
59714
- // "lowestAsk":"1.144223",
59715
- // "highestBid":"1.141696",
59716
- // "percentChange":"-0.001432",
59717
- // "baseVolume":"338287",
59718
- // "quoteVolume":"415013.244366",
59719
- // "isFrozen":"0",
59720
- // "high24hr":"1.370087",
59721
- // "low24hr":"1.370087"
59722
- // }
59723
- // }
60467
+ // "high": "35296",
60468
+ // "vol": "779308354",
60469
+ // "last": "34884.1",
60470
+ // "low": "34806.7",
60471
+ // "buy": 34883.9,
60472
+ // "sell": 34884,
60473
+ // "rose": "-0.0027957315",
60474
+ // "time": 1699348013000
59724
60475
  // }
59725
60476
  //
59726
- const data = this.safeValue(response, 'data', {});
59727
60477
  // the exchange returns market ids with an underscore from the tickers endpoint
59728
60478
  // the market ids do not have an underscore, so it has to be removed
59729
60479
  // https://github.com/ccxt/ccxt/issues/13856
59730
60480
  const tickers = {};
59731
- const marketIds = Object.keys(data);
59732
- for (let i = 0; i < marketIds.length; i++) {
59733
- const marketId = marketIds[i].replace('_', '');
59734
- tickers[marketId] = data[marketIds[i]];
60481
+ for (let i = 0; i < data.length; i++) {
60482
+ const ticker = this.safeValue(data, i, {});
60483
+ const market = this.market(this.safeValue(ticker, 'symbol'));
60484
+ tickers[market['id']] = ticker;
59735
60485
  }
59736
60486
  return this.parseTickers(tickers, symbols);
59737
60487
  }
59738
60488
  parseTrade(trade, market = undefined) {
59739
60489
  //
59740
- // aggregate trades
59741
- // - "T" is timestamp of *api-call* not trades. Use more expensive v1PublicGetHistoricalTrades if actual timestamp of trades matter
59742
- // - Trades are aggregated by timestamp, price, and side. But "m" is always True. Use method above if side of trades matter
59743
- //
59744
- // {
59745
- // "a": 26129, // Aggregate tradeId
59746
- // "p": "0.01633102", // Price
59747
- // "q": "4.70443515", // Quantity
59748
- // "f": 27781, // First tradeId
59749
- // "l": 27781, // Last tradeId
59750
- // "T": 1498793709153, // Timestamp of *Api-call* not trade!
59751
- // "m": true, // Was the buyer the maker? // Always True -> ignore it and leave side undefined
59752
- // "M": true // Was the trade the best price match?
59753
- // }
59754
- //
59755
- // recent public trades and old public trades
60490
+ // fetchTrades
59756
60491
  //
59757
60492
  // {
59758
60493
  // "id": 28457,
@@ -59763,7 +60498,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59763
60498
  // "isBestMatch": true
59764
60499
  // }
59765
60500
  //
59766
- // private trades
60501
+ // fetchTrades - spot
59767
60502
  //
59768
60503
  // {
59769
60504
  // "symbol":"USDCUSDT",
@@ -59780,14 +60515,32 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59780
60515
  // "isBestMatch":true
59781
60516
  // }
59782
60517
  //
59783
- const timestamp = this.safeInteger2(trade, 'T', 'time');
59784
- const priceString = this.safeString2(trade, 'p', 'price');
59785
- const amountString = this.safeString2(trade, 'q', 'qty');
59786
- const marketId = this.safeString(trade, 'symbol');
60518
+ // fetchTrades - future
60519
+ //
60520
+ // {
60521
+ // "tradeId":12,
60522
+ // "price":0.9,
60523
+ // "qty":1,
60524
+ // "amount":9,
60525
+ // "contractName":"E-SAND-USDT",
60526
+ // "side":"BUY",
60527
+ // "fee":"0.0018",
60528
+ // "bidId":1558124009467904992,
60529
+ // "askId":1558124043827644908,
60530
+ // "bidUserId":10294,
60531
+ // "askUserId":10467,
60532
+ // "isBuyer":true,
60533
+ // "isMaker":true,
60534
+ // "ctime":1678426306000
60535
+ // }
60536
+ //
60537
+ const timestamp = this.safeInteger2(trade, 'ctime', 'time');
60538
+ const priceString = this.safeString(trade, 'price');
60539
+ const amountString = this.safeString(trade, 'qty');
60540
+ const marketId = this.safeString2(trade, 'symbol', 'contractName');
59787
60541
  const symbol = this.safeSymbol(marketId, market);
59788
60542
  const orderId = this.safeString(trade, 'orderId');
59789
- let id = this.safeString2(trade, 't', 'a');
59790
- id = this.safeString2(trade, 'id', 'tradeId', id);
60543
+ const id = this.safeString2(trade, 'id', 'tradeId');
59791
60544
  let side = undefined;
59792
60545
  const buyerMaker = this.safeValue(trade, 'isBuyerMaker'); // ignore "m" until Bitrue fixes api
59793
60546
  const isBuyer = this.safeValue(trade, 'isBuyer');
@@ -59800,12 +60553,12 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59800
60553
  let fee = undefined;
59801
60554
  if ('commission' in trade) {
59802
60555
  fee = {
59803
- 'cost': this.safeString(trade, 'commission'),
60556
+ 'cost': this.safeString2(trade, 'commission', 'fee'),
59804
60557
  'currency': this.safeCurrencyCode(this.safeString(trade, 'commissionAssert')),
59805
60558
  };
59806
60559
  }
59807
60560
  let takerOrMaker = undefined;
59808
- const isMaker = this.safeValue2(trade, 'isMaker', 'maker');
60561
+ const isMaker = this.safeValue(trade, 'isMaker');
59809
60562
  if (isMaker !== undefined) {
59810
60563
  takerOrMaker = isMaker ? 'maker' : 'taker';
59811
60564
  }
@@ -59830,6 +60583,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59830
60583
  * @method
59831
60584
  * @name bitrue#fetchTrades
59832
60585
  * @description get the list of most recent trades for a particular symbol
60586
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#recent-trades-list
59833
60587
  * @param {string} symbol unified symbol of the market to fetch trades for
59834
60588
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
59835
60589
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -59838,41 +60592,22 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59838
60592
  */
59839
60593
  await this.loadMarkets();
59840
60594
  const market = this.market(symbol);
59841
- const request = {
59842
- 'symbol': market['id'],
59843
- // 'limit': 100, // default 100, max = 1000
59844
- };
59845
- const method = this.safeString(this.options, 'fetchTradesMethod', 'v1PublicGetAggTrades');
59846
- if (limit !== undefined) {
59847
- request['limit'] = limit; // default 100, max 1000
60595
+ let response = undefined;
60596
+ if (market['spot']) {
60597
+ const request = {
60598
+ 'symbol': market['id'],
60599
+ // 'limit': 100, // default 100, max = 1000
60600
+ };
60601
+ if (limit !== undefined) {
60602
+ request['limit'] = limit; // default 100, max 1000
60603
+ }
60604
+ response = await this.spotV1PublicGetTrades(this.extend(request, params));
60605
+ }
60606
+ else {
60607
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchTrades only support spot markets');
59848
60608
  }
59849
60609
  //
59850
- // Caveats:
59851
- // - default limit (500) applies only if no other parameters set, trades up
59852
- // to the maximum limit may be returned to satisfy other parameters
59853
- // - if both limit and time window is set and time window contains more
59854
- // trades than the limit then the last trades from the window are returned
59855
- // - 'tradeId' accepted and returned by this method is "aggregate" trade id
59856
- // which is different from actual trade id
59857
- // - setting both fromId and time window results in error
59858
- const response = await this[method](this.extend(request, params));
59859
- //
59860
- // aggregate trades
59861
- //
59862
- // [
59863
- // {
59864
- // "a": 26129, // Aggregate tradeId
59865
- // "p": "0.01633102", // Price
59866
- // "q": "4.70443515", // Quantity
59867
- // "f": 27781, // First tradeId
59868
- // "l": 27781, // Last tradeId
59869
- // "T": 1498793709153, // Timestamp
59870
- // "m": true, // Was the buyer the maker?
59871
- // "M": true // Was the trade the best price match?
59872
- // }
59873
- // ]
59874
- //
59875
- // recent public trades and historical public trades
60610
+ // spot
59876
60611
  //
59877
60612
  // [
59878
60613
  // {
@@ -59889,6 +60624,8 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59889
60624
  }
59890
60625
  parseOrderStatus(status) {
59891
60626
  const statuses = {
60627
+ 'INIT': 'open',
60628
+ 'PENDING_CREATE': 'open',
59892
60629
  'NEW': 'open',
59893
60630
  'PARTIALLY_FILLED': 'open',
59894
60631
  'FILLED': 'closed',
@@ -59901,7 +60638,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59901
60638
  }
59902
60639
  parseOrder(order, market = undefined) {
59903
60640
  //
59904
- // createOrder
60641
+ // createOrder - spot
59905
60642
  //
59906
60643
  // {
59907
60644
  // "symbol":"USDCUSDT",
@@ -59910,7 +60647,13 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59910
60647
  // "transactTime":1635551031276
59911
60648
  // }
59912
60649
  //
59913
- // fetchOpenOrders
60650
+ // createOrder - future
60651
+ //
60652
+ // {
60653
+ // "orderId":1690615676032452985,
60654
+ // }
60655
+ //
60656
+ // fetchOrders - spot
59914
60657
  //
59915
60658
  // {
59916
60659
  // "symbol":"USDCUSDT",
@@ -59931,7 +60674,24 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59931
60674
  // "isWorking":false
59932
60675
  // }
59933
60676
  //
59934
- const status = this.parseOrderStatus(this.safeString(order, 'status'));
60677
+ // fetchOrders - future
60678
+ //
60679
+ // {
60680
+ // "orderId":1917641,
60681
+ // "price":100,
60682
+ // "origQty":10,
60683
+ // "origAmount":10,
60684
+ // "executedQty":1,
60685
+ // "avgPrice":10000,
60686
+ // "status":"INIT",
60687
+ // "type":"LIMIT",
60688
+ // "side":"BUY",
60689
+ // "action":"OPEN",
60690
+ // "transactTime":1686716571425
60691
+ // "clientOrderId":4949299210
60692
+ // }
60693
+ //
60694
+ const status = this.parseOrderStatus(this.safeString2(order, 'status', 'orderStatus'));
59935
60695
  const marketId = this.safeString(order, 'symbol');
59936
60696
  const symbol = this.safeSymbol(marketId, market);
59937
60697
  const filled = this.safeString(order, 'executedQty');
@@ -59966,7 +60726,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
59966
60726
  const fills = this.safeValue(order, 'fills', []);
59967
60727
  const clientOrderId = this.safeString(order, 'clientOrderId');
59968
60728
  const timeInForce = this.safeString(order, 'timeInForce');
59969
- const postOnly = (type === 'limit_maker') || (timeInForce === 'GTX');
60729
+ const postOnly = (type === 'limit_maker') || (timeInForce === 'GTX') || (type === 'post_only');
59970
60730
  if (type === 'limit_maker') {
59971
60731
  type = 'limit';
59972
60732
  }
@@ -60002,16 +60762,21 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60002
60762
  * @method
60003
60763
  * @name bitrue#createOrder
60004
60764
  * @description create a trade order
60005
- * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#signed-endpoint-examples-for-post-apiv1order
60765
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#recent-trades-list
60766
+ * @see https://www.bitrue.com/api-docs#new-order-trade-hmac-sha256
60767
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#new-order-trade-hmac-sha256
60006
60768
  * @param {string} symbol unified symbol of the market to create an order in
60007
60769
  * @param {string} type 'market' or 'limit'
60008
60770
  * @param {string} side 'buy' or 'sell'
60009
60771
  * @param {float} amount how much of currency you want to trade in units of base currency
60010
60772
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
60011
60773
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
60012
- * @param {float} [params.triggerPrice] the price at which a trigger order is triggered at
60774
+ * @param {float} [params.triggerPrice] *spot only* the price at which a trigger order is triggered at
60013
60775
  * @param {string} [params.clientOrderId] a unique id for the order, automatically generated if not sent
60014
- *
60776
+ * @param {decimal} [params.leverage] in future order, the leverage value of the order should consistent with the user contract configuration, default is 1
60777
+ * @param {string} [params.timeInForce] 'fok', 'ioc' or 'po'
60778
+ * @param {bool} [params.postOnly] default false
60779
+ * @param {bool} [params.reduceOnly] default false
60015
60780
  * EXCHANGE SPECIFIC PARAMETERS
60016
60781
  * @param {decimal} [params.icebergQty]
60017
60782
  * @param {long} [params.recvWindow]
@@ -60019,54 +60784,125 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60019
60784
  */
60020
60785
  await this.loadMarkets();
60021
60786
  const market = this.market(symbol);
60787
+ let response = undefined;
60788
+ let data = undefined;
60022
60789
  const uppercaseType = type.toUpperCase();
60023
- const validOrderTypes = this.safeValue(market['info'], 'orderTypes');
60024
- if (!this.inArray(uppercaseType, validOrderTypes)) {
60025
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' ' + type + ' is not a valid order type in market ' + symbol);
60026
- }
60027
60790
  const request = {
60028
- 'symbol': market['id'],
60029
60791
  'side': side.toUpperCase(),
60030
60792
  'type': uppercaseType,
60031
60793
  // 'timeInForce': '',
60032
- 'quantity': this.amountToPrecision(symbol, amount),
60033
60794
  // 'price': this.priceToPrecision (symbol, price),
60034
60795
  // 'newClientOrderId': clientOrderId, // automatically generated if not sent
60035
60796
  // 'stopPrice': this.priceToPrecision (symbol, 'stopPrice'),
60036
60797
  // 'icebergQty': this.amountToPrecision (symbol, icebergQty),
60037
60798
  };
60038
- const clientOrderId = this.safeString2(params, 'newClientOrderId', 'clientOrderId');
60039
- if (clientOrderId !== undefined) {
60040
- params = this.omit(params, ['newClientOrderId', 'clientOrderId']);
60041
- request['newClientOrderId'] = clientOrderId;
60042
- }
60043
60799
  if (uppercaseType === 'LIMIT') {
60044
60800
  if (price === undefined) {
60045
60801
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' createOrder() requires a price argument');
60046
60802
  }
60047
60803
  request['price'] = this.priceToPrecision(symbol, price);
60048
60804
  }
60049
- const stopPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
60050
- if (stopPrice !== undefined) {
60051
- params = this.omit(params, ['triggerPrice', 'stopPrice']);
60052
- request['stopPrice'] = this.priceToPrecision(symbol, stopPrice);
60805
+ if (market['swap']) {
60806
+ const isMarket = uppercaseType === 'MARKET';
60807
+ const timeInForce = this.safeStringLower(params, 'timeInForce');
60808
+ const postOnly = this.isPostOnly(isMarket, undefined, params);
60809
+ if (postOnly) {
60810
+ request['type'] = 'POST_ONLY';
60811
+ }
60812
+ else if (timeInForce === 'fok') {
60813
+ request['type'] = 'FOK';
60814
+ }
60815
+ else if (timeInForce === 'ioc') {
60816
+ request['type'] = 'IOC';
60817
+ }
60818
+ request['contractName'] = market['id'];
60819
+ if (isMarket && (side === 'buy') && (this.options['createMarketBuyOrderRequiresPrice'])) {
60820
+ const cost = this.safeString(params, 'cost');
60821
+ params = this.omit(params, 'cost');
60822
+ if (price === undefined && cost === undefined) {
60823
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' createOrder() requires the price argument with swap market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options["createMarketBuyOrderRequiresPrice"] = false to supply the cost in the amount argument (the exchange-specific behaviour)');
60824
+ }
60825
+ else {
60826
+ const amountString = this.numberToString(amount);
60827
+ const priceString = this.numberToString(price);
60828
+ const quoteAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
60829
+ amount = (cost !== undefined) ? cost : quoteAmount;
60830
+ request['amount'] = this.costToPrecision(symbol, amount);
60831
+ request['volume'] = this.costToPrecision(symbol, amount);
60832
+ }
60833
+ }
60834
+ else {
60835
+ request['amount'] = this.parseToNumeric(amount);
60836
+ request['volume'] = this.parseToNumeric(amount);
60837
+ }
60838
+ request['positionType'] = 1;
60839
+ const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
60840
+ request['open'] = reduceOnly ? 'CLOSE' : 'OPEN';
60841
+ const leverage = this.safeString(params, 'leverage', '1');
60842
+ request['leverage'] = this.parseToNumeric(leverage);
60843
+ params = this.omit(params, ['leverage', 'reduceOnly', 'reduce_only', 'timeInForce']);
60844
+ if (market['linear']) {
60845
+ response = await this.fapiV2PrivatePostOrder(this.extend(request, params));
60846
+ }
60847
+ else if (market['inverse']) {
60848
+ response = await this.dapiV2PrivatePostOrder(this.extend(request, params));
60849
+ }
60850
+ data = this.safeValue(response, 'data', {});
60053
60851
  }
60054
- const response = await this.v1PrivatePostOrder(this.extend(request, params));
60852
+ else if (market['spot']) {
60853
+ request['symbol'] = market['id'];
60854
+ request['quantity'] = this.amountToPrecision(symbol, amount);
60855
+ const validOrderTypes = this.safeValue(market['info'], 'orderTypes');
60856
+ if (!this.inArray(uppercaseType, validOrderTypes)) {
60857
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' ' + type + ' is not a valid order type in market ' + symbol);
60858
+ }
60859
+ const clientOrderId = this.safeString2(params, 'newClientOrderId', 'clientOrderId');
60860
+ if (clientOrderId !== undefined) {
60861
+ params = this.omit(params, ['newClientOrderId', 'clientOrderId']);
60862
+ request['newClientOrderId'] = clientOrderId;
60863
+ }
60864
+ const stopPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
60865
+ if (stopPrice !== undefined) {
60866
+ params = this.omit(params, ['triggerPrice', 'stopPrice']);
60867
+ request['stopPrice'] = this.priceToPrecision(symbol, stopPrice);
60868
+ }
60869
+ response = await this.spotV1PrivatePostOrder(this.extend(request, params));
60870
+ data = response;
60871
+ }
60872
+ else {
60873
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' createOrder only support spot & swap markets');
60874
+ }
60875
+ //
60876
+ // spot
60055
60877
  //
60056
60878
  // {
60057
- // "symbol":"USDCUSDT",
60058
- // "orderId":2878854881,
60059
- // "clientOrderId":"",
60060
- // "transactTime":1635551031276
60879
+ // "symbol": "BTCUSDT",
60880
+ // "orderId": 307650651173648896,
60881
+ // "orderIdStr": "307650651173648896",
60882
+ // "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
60883
+ // "transactTime": 1507725176595
60061
60884
  // }
60062
60885
  //
60063
- return this.parseOrder(response, market);
60886
+ // swap
60887
+ //
60888
+ // {
60889
+ // "code": "0",
60890
+ // "msg": "Success",
60891
+ // "data": {
60892
+ // "orderId": 1690615676032452985
60893
+ // }
60894
+ // }
60895
+ //
60896
+ return this.parseOrder(data, market);
60064
60897
  }
60065
60898
  async fetchOrder(id, symbol = undefined, params = {}) {
60066
60899
  /**
60067
60900
  * @method
60068
60901
  * @name bitrue#fetchOrder
60069
60902
  * @description fetches information on an order made by the user
60903
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#query-order-user_data
60904
+ * @see https://www.bitrue.com/api-docs#query-order-user_data-hmac-sha256
60905
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#query-order-user_data-hmac-sha256
60070
60906
  * @param {string} symbol unified symbol of the market the order was made in
60071
60907
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
60072
60908
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -60076,25 +60912,92 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60076
60912
  }
60077
60913
  await this.loadMarkets();
60078
60914
  const market = this.market(symbol);
60079
- const request = {
60080
- 'symbol': market['id'],
60081
- };
60082
- const clientOrderId = this.safeValue2(params, 'origClientOrderId', 'clientOrderId');
60083
- if (clientOrderId !== undefined) {
60084
- request['origClientOrderId'] = clientOrderId;
60915
+ const origClientOrderId = this.safeValue2(params, 'origClientOrderId', 'clientOrderId');
60916
+ params = this.omit(params, ['origClientOrderId', 'clientOrderId']);
60917
+ let response = undefined;
60918
+ let data = undefined;
60919
+ const request = {};
60920
+ if (origClientOrderId === undefined) {
60921
+ request['orderId'] = id;
60085
60922
  }
60086
60923
  else {
60087
- request['orderId'] = id;
60924
+ if (market['swap']) {
60925
+ request['clientOrderId'] = origClientOrderId;
60926
+ }
60927
+ else {
60928
+ request['origClientOrderId'] = origClientOrderId;
60929
+ }
60088
60930
  }
60089
- const query = this.omit(params, ['type', 'clientOrderId', 'origClientOrderId']);
60090
- const response = await this.v1PrivateGetOrder(this.extend(request, query));
60091
- return this.parseOrder(response, market);
60931
+ if (market['swap']) {
60932
+ request['contractName'] = market['id'];
60933
+ if (market['linear']) {
60934
+ response = await this.fapiV2PrivateGetOrder(this.extend(request, params));
60935
+ }
60936
+ else if (market['inverse']) {
60937
+ response = await this.dapiV2PrivateGetOrder(this.extend(request, params));
60938
+ }
60939
+ data = this.safeValue(response, 'data', {});
60940
+ }
60941
+ else if (market['spot']) {
60942
+ request['orderId'] = id; // spot market id is mandatory
60943
+ request['symbol'] = market['id'];
60944
+ response = await this.spotV1PrivateGetOrder(this.extend(request, params));
60945
+ data = response;
60946
+ }
60947
+ else {
60948
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchOrder only support spot & swap markets');
60949
+ }
60950
+ //
60951
+ // spot
60952
+ //
60953
+ // {
60954
+ // "symbol": "LTCBTC",
60955
+ // "orderId": 1,
60956
+ // "clientOrderId": "myOrder1",
60957
+ // "price": "0.1",
60958
+ // "origQty": "1.0",
60959
+ // "executedQty": "0.0",
60960
+ // "cummulativeQuoteQty": "0.0",
60961
+ // "status": "NEW",
60962
+ // "timeInForce": "GTC",
60963
+ // "type": "LIMIT",
60964
+ // "side": "BUY",
60965
+ // "stopPrice": "0.0",
60966
+ // "icebergQty": "0.0",
60967
+ // "time": 1499827319559,
60968
+ // "updateTime": 1499827319559,
60969
+ // "isWorking": true
60970
+ // }
60971
+ //
60972
+ // swap
60973
+ //
60974
+ // {
60975
+ // "code":0,
60976
+ // "msg":"success",
60977
+ // "data":{
60978
+ // "orderId":1917641,
60979
+ // "price":100,
60980
+ // "origQty":10,
60981
+ // "origAmount":10,
60982
+ // "executedQty":1,
60983
+ // "avgPrice":10000,
60984
+ // "status":"INIT",
60985
+ // "type":"LIMIT",
60986
+ // "side":"BUY",
60987
+ // "action":"OPEN",
60988
+ // "transactTime":1686716571425
60989
+ // "clientOrderId":4949299210
60990
+ // }
60991
+ // }
60992
+ //
60993
+ return this.parseOrder(data, market);
60092
60994
  }
60093
60995
  async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
60094
60996
  /**
60095
60997
  * @method
60096
60998
  * @name bitrue#fetchClosedOrders
60097
60999
  * @description fetches information on multiple closed orders made by the user
61000
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#all-orders-user_data
60098
61001
  * @param {string} symbol unified market symbol of the market orders were made in
60099
61002
  * @param {int} [since] the earliest time in ms to fetch orders for
60100
61003
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -60106,6 +61009,9 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60106
61009
  }
60107
61010
  await this.loadMarkets();
60108
61011
  const market = this.market(symbol);
61012
+ if (!market['spot']) {
61013
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchClosedOrders only support spot markets');
61014
+ }
60109
61015
  const request = {
60110
61016
  'symbol': market['id'],
60111
61017
  // 'orderId': 123445, // long
@@ -60119,7 +61025,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60119
61025
  if (limit !== undefined) {
60120
61026
  request['limit'] = limit; // default 100, max 1000
60121
61027
  }
60122
- const response = await this.v1PrivateGetAllOrders(this.extend(request, params));
61028
+ const response = await this.spotV1PrivateGetAllOrders(this.extend(request, params));
60123
61029
  //
60124
61030
  // [
60125
61031
  // {
@@ -60149,6 +61055,9 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60149
61055
  * @method
60150
61056
  * @name bitrue#fetchOpenOrders
60151
61057
  * @description fetch all unfilled currently open orders
61058
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#current-open-orders-user_data
61059
+ * @see https://www.bitrue.com/api-docs#current-all-open-orders-user_data-hmac-sha256
61060
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#current-all-open-orders-user_data-hmac-sha256
60152
61061
  * @param {string} symbol unified market symbol
60153
61062
  * @param {int} [since] the earliest time in ms to fetch open orders for
60154
61063
  * @param {int} [limit] the maximum number of open order structures to retrieve
@@ -60160,10 +61069,29 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60160
61069
  }
60161
61070
  await this.loadMarkets();
60162
61071
  const market = this.market(symbol);
60163
- const request = {
60164
- 'symbol': market['id'],
60165
- };
60166
- const response = await this.v1PrivateGetOpenOrders(this.extend(request, params));
61072
+ let response = undefined;
61073
+ let data = undefined;
61074
+ const request = {};
61075
+ if (market['swap']) {
61076
+ request['contractName'] = market['id'];
61077
+ if (market['linear']) {
61078
+ response = await this.fapiV2PrivateGetOpenOrders(this.extend(request, params));
61079
+ }
61080
+ else if (market['inverse']) {
61081
+ response = await this.dapiV2PrivateGetOpenOrders(this.extend(request, params));
61082
+ }
61083
+ data = this.safeValue(response, 'data', []);
61084
+ }
61085
+ else if (market['spot']) {
61086
+ request['symbol'] = market['id'];
61087
+ response = await this.spotV1PrivateGetOpenOrders(this.extend(request, params));
61088
+ data = response;
61089
+ }
61090
+ else {
61091
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchOpenOrders only support spot & swap markets');
61092
+ }
61093
+ //
61094
+ // spot
60167
61095
  //
60168
61096
  // [
60169
61097
  // {
@@ -60186,13 +61114,38 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60186
61114
  // }
60187
61115
  // ]
60188
61116
  //
60189
- return this.parseOrders(response, market, since, limit);
61117
+ // swap
61118
+ //
61119
+ // {
61120
+ // "code": "0",
61121
+ // "msg": "Success",
61122
+ // "data": [{
61123
+ // "orderId": 1917641,
61124
+ // "clientOrderId": "2488514315",
61125
+ // "price": 100,
61126
+ // "origQty": 10,
61127
+ // "origAmount": 10,
61128
+ // "executedQty": 1,
61129
+ // "avgPrice": 12451,
61130
+ // "status": "INIT",
61131
+ // "type": "LIMIT",
61132
+ // "side": "BUY",
61133
+ // "action": "OPEN",
61134
+ // "transactTime": 1686717303975
61135
+ // }
61136
+ // ]
61137
+ // }
61138
+ //
61139
+ return this.parseOrders(data, market, since, limit);
60190
61140
  }
60191
61141
  async cancelOrder(id, symbol = undefined, params = {}) {
60192
61142
  /**
60193
61143
  * @method
60194
61144
  * @name bitrue#cancelOrder
60195
61145
  * @description cancels an open order
61146
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#cancel-order-trade
61147
+ * @see https://www.bitrue.com/api-docs#cancel-order-trade-hmac-sha256
61148
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#cancel-order-trade-hmac-sha256
60196
61149
  * @param {string} id order id
60197
61150
  * @param {string} symbol unified symbol of the market the order was made in
60198
61151
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
@@ -60204,20 +61157,41 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60204
61157
  await this.loadMarkets();
60205
61158
  const market = this.market(symbol);
60206
61159
  const origClientOrderId = this.safeValue2(params, 'origClientOrderId', 'clientOrderId');
60207
- const request = {
60208
- 'symbol': market['id'],
60209
- // "orderId": id,
60210
- // "origClientOrderId": id,
60211
- // "newClientOrderId": id,
60212
- };
61160
+ params = this.omit(params, ['origClientOrderId', 'clientOrderId']);
61161
+ let response = undefined;
61162
+ let data = undefined;
61163
+ const request = {};
60213
61164
  if (origClientOrderId === undefined) {
60214
61165
  request['orderId'] = id;
60215
61166
  }
60216
61167
  else {
60217
- request['origClientOrderId'] = origClientOrderId;
61168
+ if (market['swap']) {
61169
+ request['clientOrderId'] = origClientOrderId;
61170
+ }
61171
+ else {
61172
+ request['origClientOrderId'] = origClientOrderId;
61173
+ }
61174
+ }
61175
+ if (market['swap']) {
61176
+ request['contractName'] = market['id'];
61177
+ if (market['linear']) {
61178
+ response = await this.fapiV2PrivatePostCancel(this.extend(request, params));
61179
+ }
61180
+ else if (market['inverse']) {
61181
+ response = await this.dapiV2PrivatePostCancel(this.extend(request, params));
61182
+ }
61183
+ data = this.safeValue(response, 'data', {});
61184
+ }
61185
+ else if (market['spot']) {
61186
+ request['symbol'] = market['id'];
61187
+ response = await this.spotV1PrivateDeleteOrder(this.extend(request, params));
61188
+ data = response;
61189
+ }
61190
+ else {
61191
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' cancelOrder only support spot & swap markets');
60218
61192
  }
60219
- const query = this.omit(params, ['type', 'origClientOrderId', 'clientOrderId']);
60220
- const response = await this.v1PrivateDeleteOrder(this.extend(request, query));
61193
+ //
61194
+ // spot
60221
61195
  //
60222
61196
  // {
60223
61197
  // "symbol": "LTCBTC",
@@ -60226,43 +61200,111 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60226
61200
  // "clientOrderId": "cancelMyOrder1"
60227
61201
  // }
60228
61202
  //
60229
- return this.parseOrder(response, market);
61203
+ // swap
61204
+ //
61205
+ // {
61206
+ // "code": "0",
61207
+ // "msg": "Success",
61208
+ // "data": {
61209
+ // "orderId": 1690615847831143159
61210
+ // }
61211
+ // }
61212
+ //
61213
+ return this.parseOrder(data, market);
61214
+ }
61215
+ async cancelAllOrders(symbol = undefined, params = {}) {
61216
+ /**
61217
+ * @method
61218
+ * @name bitrue#cancelAllOrders
61219
+ * @description cancel all open orders in a market
61220
+ * @see https://www.bitrue.com/api-docs#cancel-all-open-orders-trade-hmac-sha256
61221
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#cancel-all-open-orders-trade-hmac-sha256
61222
+ * @param {string} symbol unified market symbol of the market to cancel orders in
61223
+ * @param {object} [params] extra parameters specific to the bitrue api endpoint
61224
+ * @param {string} [params.marginMode] 'cross' or 'isolated', for spot margin trading
61225
+ * @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
61226
+ */
61227
+ await this.loadMarkets();
61228
+ const market = this.market(symbol);
61229
+ let response = undefined;
61230
+ let data = undefined;
61231
+ if (market['swap']) {
61232
+ const request = {
61233
+ 'contractName': market['id'],
61234
+ };
61235
+ if (market['linear']) {
61236
+ response = await this.fapiV2PrivatePostAllOpenOrders(this.extend(request, params));
61237
+ }
61238
+ else if (market['inverse']) {
61239
+ response = await this.dapiV2PrivatePostAllOpenOrders(this.extend(request, params));
61240
+ }
61241
+ data = this.safeValue(response, 'data', []);
61242
+ }
61243
+ else {
61244
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' cancelAllOrders only support future markets');
61245
+ }
61246
+ //
61247
+ // swap
61248
+ //
61249
+ // {
61250
+ // 'code': '0',
61251
+ // 'msg': 'Success',
61252
+ // 'data': null
61253
+ // }
61254
+ //
61255
+ return this.parseOrders(data, market);
60230
61256
  }
60231
61257
  async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
60232
61258
  /**
60233
61259
  * @method
60234
61260
  * @name bitrue#fetchMyTrades
60235
61261
  * @description fetch all trades made by the user
61262
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#account-trade-list-user_data
61263
+ * @see https://www.bitrue.com/api-docs#account-trade-list-user_data-hmac-sha256
61264
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#account-trade-list-user_data-hmac-sha256
60236
61265
  * @param {string} symbol unified market symbol
60237
61266
  * @param {int} [since] the earliest time in ms to fetch trades for
60238
61267
  * @param {int} [limit] the maximum number of trades structures to retrieve
60239
61268
  * @param {object} [params] extra parameters specific to the bitrue api endpoint
60240
61269
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
60241
61270
  */
60242
- const method = this.safeString(this.options, 'fetchMyTradesMethod', 'v2PrivateGetMyTrades');
60243
- if ((symbol === undefined) && (method === 'v2PrivateGetMyTrades')) {
60244
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ArgumentsRequired(this.id + ' v2PrivateGetMyTrades() requires a symbol argument');
60245
- }
60246
61271
  await this.loadMarkets();
60247
- const request = {
60248
- // 'symbol': market['id'],
60249
- // 'startTime': since,
60250
- // 'endTime': this.milliseconds (),
60251
- // 'fromId': 12345, // trade id to fetch from, most recent trades by default
60252
- // 'limit': limit, // default 100, max 1000
60253
- };
60254
- let market = undefined;
60255
- if (symbol !== undefined) {
60256
- market = this.market(symbol);
60257
- request['symbol'] = market['id'];
61272
+ if (symbol === undefined) {
61273
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
60258
61274
  }
61275
+ const market = this.market(symbol);
61276
+ let response = undefined;
61277
+ let data = undefined;
61278
+ const request = {};
60259
61279
  if (since !== undefined) {
60260
61280
  request['startTime'] = since;
60261
61281
  }
60262
61282
  if (limit !== undefined) {
61283
+ if (limit > 1000) {
61284
+ limit = 1000;
61285
+ }
60263
61286
  request['limit'] = limit;
60264
61287
  }
60265
- const response = await this[method](this.extend(request, params));
61288
+ if (market['swap']) {
61289
+ request['contractName'] = market['id'];
61290
+ if (market['linear']) {
61291
+ response = await this.fapiV2PrivateGetMyTrades(this.extend(request, params));
61292
+ }
61293
+ else if (market['inverse']) {
61294
+ response = await this.dapiV2PrivateGetMyTrades(this.extend(request, params));
61295
+ }
61296
+ data = this.safeValue(response, 'data', []);
61297
+ }
61298
+ else if (market['spot']) {
61299
+ request['symbol'] = market['id'];
61300
+ response = await this.spotV2PrivateGetMyTrades(this.extend(request, params));
61301
+ data = response;
61302
+ }
61303
+ else {
61304
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' fetchMyTrades only support spot & swap markets');
61305
+ }
61306
+ //
61307
+ // spot
60266
61308
  //
60267
61309
  // [
60268
61310
  // {
@@ -60281,13 +61323,39 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60281
61323
  // }
60282
61324
  // ]
60283
61325
  //
60284
- return this.parseTrades(response, market, since, limit);
61326
+ // swap
61327
+ //
61328
+ // {
61329
+ // "code":"0",
61330
+ // "msg":"Success",
61331
+ // "data":[
61332
+ // {
61333
+ // "tradeId":12,
61334
+ // "price":0.9,
61335
+ // "qty":1,
61336
+ // "amount":9,
61337
+ // "contractName":"E-SAND-USDT",
61338
+ // "side":"BUY",
61339
+ // "fee":"0.0018",
61340
+ // "bidId":1558124009467904992,
61341
+ // "askId":1558124043827644908,
61342
+ // "bidUserId":10294,
61343
+ // "askUserId":10467,
61344
+ // "isBuyer":true,
61345
+ // "isMaker":true,
61346
+ // "ctime":1678426306000
61347
+ // }
61348
+ // ]
61349
+ // }
61350
+ //
61351
+ return this.parseTrades(data, market, since, limit);
60285
61352
  }
60286
61353
  async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
60287
61354
  /**
60288
61355
  * @method
60289
61356
  * @name bitrue#fetchDeposits
60290
61357
  * @description fetch all deposits made to an account
61358
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#deposit-history--withdraw_data
60291
61359
  * @param {string} code unified currency code
60292
61360
  * @param {int} [since] the earliest time in ms to fetch deposits for
60293
61361
  * @param {int} [limit] the maximum number of deposits structures to retrieve
@@ -60314,7 +61382,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60314
61382
  if (limit !== undefined) {
60315
61383
  request['limit'] = limit;
60316
61384
  }
60317
- const response = await this.v1PrivateGetDepositHistory(this.extend(request, params));
61385
+ const response = await this.spotV1PrivateGetDepositHistory(this.extend(request, params));
60318
61386
  //
60319
61387
  // {
60320
61388
  // "code":200,
@@ -60359,6 +61427,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60359
61427
  * @method
60360
61428
  * @name bitrue#fetchWithdrawals
60361
61429
  * @description fetch all withdrawals made from an account
61430
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#withdraw-history--withdraw_data
60362
61431
  * @param {string} code unified currency code
60363
61432
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
60364
61433
  * @param {int} [limit] the maximum number of withdrawals structures to retrieve
@@ -60385,7 +61454,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60385
61454
  if (limit !== undefined) {
60386
61455
  request['limit'] = limit;
60387
61456
  }
60388
- const response = await this.v1PrivateGetWithdrawHistory(this.extend(request, params));
61457
+ const response = await this.spotV1PrivateGetWithdrawHistory(this.extend(request, params));
60389
61458
  //
60390
61459
  // {
60391
61460
  // "code": 200,
@@ -60549,6 +61618,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60549
61618
  * @method
60550
61619
  * @name bitrue#withdraw
60551
61620
  * @description make a withdrawal
61621
+ * @see https://github.com/Bitrue-exchange/Spot-official-api-docs#withdraw-commit--withdraw_data
60552
61622
  * @param {string} code unified currency code
60553
61623
  * @param {float} amount the amount to withdraw
60554
61624
  * @param {string} address the address to withdraw to
@@ -60585,7 +61655,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60585
61655
  if (tag !== undefined) {
60586
61656
  request['tag'] = tag;
60587
61657
  }
60588
- const response = await this.v1PrivatePostWithdrawCommit(this.extend(request, params));
61658
+ const response = await this.spotV1PrivatePostWithdrawCommit(this.extend(request, params));
60589
61659
  //
60590
61660
  // {
60591
61661
  // "code": 200,
@@ -60601,7 +61671,7 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60601
61671
  // }
60602
61672
  // }
60603
61673
  //
60604
- const data = this.safeValue(response, 'data');
61674
+ const data = this.safeValue(response, 'data', {});
60605
61675
  return this.parseTransaction(data, currency);
60606
61676
  }
60607
61677
  parseDepositWithdrawFee(fee, currency = undefined) {
@@ -60656,33 +61726,289 @@ class bitrue extends _abstract_bitrue_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
60656
61726
  * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
60657
61727
  */
60658
61728
  await this.loadMarkets();
60659
- const response = await this.v1PublicGetExchangeInfo(params);
61729
+ const response = await this.spotV1PublicGetExchangeInfo(params);
60660
61730
  const coins = this.safeValue(response, 'coins');
60661
61731
  return this.parseDepositWithdrawFees(coins, codes, 'coin');
60662
61732
  }
61733
+ parseTransfer(transfer, currency = undefined) {
61734
+ //
61735
+ // fetchTransfers
61736
+ //
61737
+ // {
61738
+ // 'transferType': 'wallet_to_contract',
61739
+ // 'symbol': 'USDT',
61740
+ // 'amount': 1.0,
61741
+ // 'status': 1,
61742
+ // 'ctime': 1685404575000
61743
+ // }
61744
+ //
61745
+ // transfer
61746
+ //
61747
+ // {}
61748
+ //
61749
+ const transferType = this.safeString(transfer, 'transferType');
61750
+ let fromAccount = undefined;
61751
+ let toAccount = undefined;
61752
+ if (transferType !== undefined) {
61753
+ const accountSplit = transferType.split('_to_');
61754
+ fromAccount = this.safeString(accountSplit, 0);
61755
+ toAccount = this.safeString(accountSplit, 1);
61756
+ }
61757
+ const timestamp = this.safeInteger(transfer, 'ctime');
61758
+ return {
61759
+ 'info': transfer,
61760
+ 'id': undefined,
61761
+ 'timestamp': timestamp,
61762
+ 'datetime': this.iso8601(timestamp),
61763
+ 'currency': this.safeString(currency, 'code'),
61764
+ 'amount': this.safeNumber(transfer, 'amount'),
61765
+ 'fromAccount': fromAccount,
61766
+ 'toAccount': toAccount,
61767
+ 'status': 'ok',
61768
+ };
61769
+ }
61770
+ async fetchTransfers(code = undefined, since = undefined, limit = undefined, params = {}) {
61771
+ /**
61772
+ * @method
61773
+ * @name bitrue#fetchTransfers
61774
+ * @description fetch a history of internal transfers made on an account
61775
+ * @see https://www.bitrue.com/api-docs#get-future-account-transfer-history-list-user_data-hmac-sha256
61776
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#get-future-account-transfer-history-list-user_data-hmac-sha256
61777
+ * @param {string} code unified currency code of the currency transferred
61778
+ * @param {int} [since] the earliest time in ms to fetch transfers for
61779
+ * @param {int} [limit] the maximum number of transfers structures to retrieve
61780
+ * @param {object} [params] extra parameters specific to the bitrue api endpoint
61781
+ * @param {int} [params.until] the latest time in ms to fetch transfers for
61782
+ * @param {string} [params.type] transfer type wallet_to_contract or contract_to_wallet
61783
+ * @returns {object[]} a list of [transfer structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure}
61784
+ */
61785
+ await this.loadMarkets();
61786
+ const type = this.safeString2(params, 'type', 'transferType');
61787
+ const request = {
61788
+ 'transferType': type,
61789
+ };
61790
+ let currency = undefined;
61791
+ if (code !== undefined) {
61792
+ currency = this.currency(code);
61793
+ request['coinSymbol'] = currency['id'];
61794
+ }
61795
+ if (since !== undefined) {
61796
+ request['beginTime'] = since;
61797
+ }
61798
+ if (limit !== undefined) {
61799
+ if (limit > 200) {
61800
+ limit = 200;
61801
+ }
61802
+ request['limit'] = limit;
61803
+ }
61804
+ const until = this.safeInteger(params, 'until');
61805
+ if (until !== undefined) {
61806
+ params = this.omit(params, 'until');
61807
+ request['endTime'] = until;
61808
+ }
61809
+ const response = await this.fapiV2PrivateGetFuturesTransferHistory(this.extend(request, params));
61810
+ //
61811
+ // {
61812
+ // 'code': '0',
61813
+ // 'msg': 'Success',
61814
+ // 'data': [{
61815
+ // 'transferType': 'wallet_to_contract',
61816
+ // 'symbol': 'USDT',
61817
+ // 'amount': 1.0,
61818
+ // 'status': 1,
61819
+ // 'ctime': 1685404575000
61820
+ // }]
61821
+ // }
61822
+ //
61823
+ const data = this.safeValue(response, 'data', {});
61824
+ return this.parseTransfers(data, currency, since, limit);
61825
+ }
61826
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
61827
+ /**
61828
+ * @method
61829
+ * @name bitrue#transfer
61830
+ * @description transfer currency internally between wallets on the same account
61831
+ * @see https://www.bitrue.com/api-docs#new-future-account-transfer-user_data-hmac-sha256
61832
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#user-commission-rate-user_data-hmac-sha256
61833
+ * @param {string} code unified currency code
61834
+ * @param {float} amount amount to transfer
61835
+ * @param {string} fromAccount account to transfer from
61836
+ * @param {string} toAccount account to transfer to
61837
+ * @param {object} [params] extra parameters specific to the bitrue api endpoint
61838
+ * @returns {object} a [transfer structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure}
61839
+ */
61840
+ await this.loadMarkets();
61841
+ const currency = this.currency(code);
61842
+ const accountTypes = this.safeValue(this.options, 'accountsByType', {});
61843
+ const fromId = this.safeString(accountTypes, fromAccount, fromAccount);
61844
+ const toId = this.safeString(accountTypes, toAccount, toAccount);
61845
+ const request = {
61846
+ 'coinSymbol': currency['id'],
61847
+ 'amount': this.currencyToPrecision(code, amount),
61848
+ 'transferType': fromId + '_to_' + toId,
61849
+ };
61850
+ const response = await this.fapiV2PrivatePostFuturesTransfer(this.extend(request, params));
61851
+ //
61852
+ // {
61853
+ // 'code': '0',
61854
+ // 'msg': 'Success',
61855
+ // 'data': null
61856
+ // }
61857
+ //
61858
+ const data = this.safeValue(response, 'data', {});
61859
+ return this.parseTransfer(data, currency);
61860
+ }
61861
+ async setLeverage(leverage, symbol = undefined, params = {}) {
61862
+ /**
61863
+ * @method
61864
+ * @name bitrue#setLeverage
61865
+ * @description set the level of leverage for a market
61866
+ * @see https://www.bitrue.com/api-docs#change-initial-leverage-trade-hmac-sha256
61867
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#change-initial-leverage-trade-hmac-sha256
61868
+ * @param {float} leverage the rate of leverage
61869
+ * @param {string} symbol unified market symbol
61870
+ * @param {object} [params] extra parameters specific to the bitrue api endpoint
61871
+ * @returns {object} response from the exchange
61872
+ */
61873
+ if (symbol === undefined) {
61874
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
61875
+ }
61876
+ if ((leverage < 1) || (leverage > 125)) {
61877
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadRequest(this.id + ' leverage should be between 1 and 125');
61878
+ }
61879
+ await this.loadMarkets();
61880
+ const market = this.market(symbol);
61881
+ let response = undefined;
61882
+ const request = {
61883
+ 'contractName': market['id'],
61884
+ 'leverage': leverage,
61885
+ };
61886
+ if (!market['swap']) {
61887
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' setLeverage only support swap markets');
61888
+ }
61889
+ if (market['linear']) {
61890
+ response = await this.fapiV2PrivatePostLevelEdit(this.extend(request, params));
61891
+ }
61892
+ else if (market['inverse']) {
61893
+ response = await this.dapiV2PrivatePostLevelEdit(this.extend(request, params));
61894
+ }
61895
+ return response;
61896
+ }
61897
+ parseMarginModification(data, market = undefined) {
61898
+ return {
61899
+ 'info': data,
61900
+ 'type': undefined,
61901
+ 'amount': undefined,
61902
+ 'code': undefined,
61903
+ 'symbol': market['symbol'],
61904
+ 'status': undefined,
61905
+ };
61906
+ }
61907
+ async setMargin(symbol, amount, params = {}) {
61908
+ /**
61909
+ * @method
61910
+ * @name bitrue#setMargin
61911
+ * @description Either adds or reduces margin in an isolated position in order to set the margin to a specific value
61912
+ * @see https://www.bitrue.com/api-docs#modify-isolated-position-margin-trade-hmac-sha256
61913
+ * @see https://www.bitrue.com/api_docs_includes_file/delivery.html#modify-isolated-position-margin-trade-hmac-sha256
61914
+ * @param {string} symbol unified market symbol of the market to set margin in
61915
+ * @param {float} amount the amount to set the margin to
61916
+ * @param {object} [params] parameters specific to the bitrue api endpoint
61917
+ * @returns {object} A [margin structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#add-margin-structure}
61918
+ */
61919
+ await this.loadMarkets();
61920
+ const market = this.market(symbol);
61921
+ if (!market['swap']) {
61922
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' setMargin only support swap markets');
61923
+ }
61924
+ let response = undefined;
61925
+ const request = {
61926
+ 'contractName': market['id'],
61927
+ 'amount': this.parseToNumeric(amount),
61928
+ };
61929
+ if (market['linear']) {
61930
+ response = await this.fapiV2PrivatePostPositionMargin(this.extend(request, params));
61931
+ }
61932
+ else if (market['inverse']) {
61933
+ response = await this.dapiV2PrivatePostPositionMargin(this.extend(request, params));
61934
+ }
61935
+ //
61936
+ // {
61937
+ // "code": 0,
61938
+ // "msg": "success"
61939
+ // "data": null
61940
+ // }
61941
+ //
61942
+ return this.parseMarginModification(response, market);
61943
+ }
60663
61944
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
60664
- const version = this.safeString(api, 0);
60665
- const access = this.safeString(api, 1);
60666
- let url = this.urls['api'][version] + '/' + this.implodeParams(path, params);
61945
+ const type = this.safeString(api, 0);
61946
+ const version = this.safeString(api, 1);
61947
+ const access = this.safeString(api, 2);
61948
+ let url = undefined;
61949
+ if (type === 'api' && version === 'kline') {
61950
+ url = this.urls['api'][type];
61951
+ }
61952
+ else {
61953
+ url = this.urls['api'][type] + '/' + version;
61954
+ }
61955
+ url = url + '/' + this.implodeParams(path, params);
60667
61956
  params = this.omit(params, this.extractParams(path));
60668
61957
  if (access === 'private') {
60669
61958
  this.checkRequiredCredentials();
60670
61959
  const recvWindow = this.safeInteger(this.options, 'recvWindow', 5000);
60671
- let query = this.urlencode(this.extend({
60672
- 'timestamp': this.nonce(),
60673
- 'recvWindow': recvWindow,
60674
- }, params));
60675
- const signature = this.hmac(this.encode(query), this.encode(this.secret), _static_dependencies_noble_hashes_sha256_js__WEBPACK_IMPORTED_MODULE_4__/* .sha256 */ .J);
60676
- query += '&' + 'signature=' + signature;
60677
- headers = {
60678
- 'X-MBX-APIKEY': this.apiKey,
60679
- };
60680
- if ((method === 'GET') || (method === 'DELETE')) {
60681
- url += '?' + query;
61960
+ if (type === 'spot') {
61961
+ let query = this.urlencode(this.extend({
61962
+ 'timestamp': this.nonce(),
61963
+ 'recvWindow': recvWindow,
61964
+ }, params));
61965
+ const signature = this.hmac(this.encode(query), this.encode(this.secret), _static_dependencies_noble_hashes_sha256_js__WEBPACK_IMPORTED_MODULE_4__/* .sha256 */ .J);
61966
+ query += '&' + 'signature=' + signature;
61967
+ headers = {
61968
+ 'X-MBX-APIKEY': this.apiKey,
61969
+ };
61970
+ if ((method === 'GET') || (method === 'DELETE')) {
61971
+ url += '?' + query;
61972
+ }
61973
+ else {
61974
+ body = query;
61975
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
61976
+ }
60682
61977
  }
60683
61978
  else {
60684
- body = query;
60685
- headers['Content-Type'] = 'application/x-www-form-urlencoded';
61979
+ const timestamp = this.nonce().toString();
61980
+ let signPath = undefined;
61981
+ if (type === 'fapi') {
61982
+ signPath = '/fapi';
61983
+ }
61984
+ else if (type === 'dapi') {
61985
+ signPath = '/dapi';
61986
+ }
61987
+ signPath = signPath + '/' + version + '/' + path;
61988
+ let signMessage = timestamp + method + signPath;
61989
+ if (method === 'GET') {
61990
+ const signature = this.hmac(this.encode(signMessage), this.encode(this.secret), _static_dependencies_noble_hashes_sha256_js__WEBPACK_IMPORTED_MODULE_4__/* .sha256 */ .J);
61991
+ headers = {
61992
+ 'X-CH-APIKEY': this.apiKey,
61993
+ 'X-CH-SIGN': signature,
61994
+ 'X-CH-TS': timestamp,
61995
+ };
61996
+ url += '?' + this.urlencode(params);
61997
+ }
61998
+ else {
61999
+ const query = this.extend({
62000
+ 'recvWindow': recvWindow,
62001
+ }, params);
62002
+ body = this.json(query);
62003
+ signMessage = signMessage + JSON.stringify(body);
62004
+ const signature = this.hmac(this.encode(signMessage), this.encode(this.secret), _static_dependencies_noble_hashes_sha256_js__WEBPACK_IMPORTED_MODULE_4__/* .sha256 */ .J);
62005
+ headers = {
62006
+ 'Content-Type': 'application/json',
62007
+ 'X-CH-APIKEY': this.apiKey,
62008
+ 'X-CH-SIGN': signature,
62009
+ 'X-CH-TS': timestamp,
62010
+ };
62011
+ }
60686
62012
  }
60687
62013
  }
60688
62014
  else {
@@ -119936,7 +121262,6 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
119936
121262
  'future': true,
119937
121263
  'option': true,
119938
121264
  'addMargin': true,
119939
- 'borrowMargin': true,
119940
121265
  'cancelAllOrders': true,
119941
121266
  'cancelOrder': true,
119942
121267
  'createMarketOrder': true,
@@ -120001,7 +121326,6 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
120001
121326
  'fetchVolatilityHistory': false,
120002
121327
  'fetchWithdrawals': true,
120003
121328
  'reduceMargin': true,
120004
- 'repayMargin': true,
120005
121329
  'setLeverage': true,
120006
121330
  'setMarginMode': false,
120007
121331
  'setPositionMode': true,
@@ -125426,220 +126750,6 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
125426
126750
  }
125427
126751
  return tiers;
125428
126752
  }
125429
- async repayMargin(code, amount, symbol = undefined, params = {}) {
125430
- /**
125431
- * @method
125432
- * @name gate#repayMargin
125433
- * @description repay borrowed margin and interest
125434
- * @see https://www.gate.io/docs/apiv4/en/#repay-cross-margin-loan
125435
- * @see https://www.gate.io/docs/apiv4/en/#repay-a-loan
125436
- * @param {string} code unified currency code of the currency to repay
125437
- * @param {float} amount the amount to repay
125438
- * @param {string} symbol unified market symbol, required for isolated margin
125439
- * @param {object} [params] extra parameters specific to the gate api endpoint
125440
- * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
125441
- * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
125442
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
125443
- */
125444
- const marginMode = this.safeString(params, 'marginMode'); // cross or isolated
125445
- params = this.omit(params, 'marginMode');
125446
- this.checkRequiredMarginArgument('repayMargin', symbol, marginMode);
125447
- await this.loadMarkets();
125448
- const currency = this.currency(code);
125449
- const request = {
125450
- 'currency': currency['id'],
125451
- 'amount': this.currencyToPrecision(code, amount),
125452
- };
125453
- let response = undefined;
125454
- params = this.omit(params, ['marginMode']);
125455
- if (symbol === undefined) {
125456
- response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
125457
- }
125458
- else {
125459
- const market = this.market(symbol);
125460
- request['currency_pair'] = market['id'];
125461
- request['mode'] = 'partial';
125462
- const loanId = this.safeString2(params, 'loan_id', 'id');
125463
- if (loanId === undefined) {
125464
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ArgumentsRequired(this.id + ' repayMargin() requires loan_id param for isolated margin');
125465
- }
125466
- request['loan_id'] = loanId;
125467
- params = this.omit(params, ['loan_id', 'id']);
125468
- response = await this.privateMarginPostLoansLoanIdRepayment(this.extend(request, params));
125469
- }
125470
- //
125471
- // Cross
125472
- //
125473
- // [
125474
- // {
125475
- // "id": "17",
125476
- // "create_time": 1620381696159,
125477
- // "update_time": 1620381696159,
125478
- // "currency": "EOS",
125479
- // "amount": "110.553635",
125480
- // "text": "web",
125481
- // "status": 2,
125482
- // "repaid": "110.506649705159",
125483
- // "repaid_interest": "0.046985294841",
125484
- // "unpaid_interest": "0.0000074393366667"
125485
- // }
125486
- // ]
125487
- //
125488
- // Isolated
125489
- //
125490
- // {
125491
- // "id": "34267567",
125492
- // "create_time": "1656394778",
125493
- // "expire_time": "1657258778",
125494
- // "status": "finished",
125495
- // "side": "borrow",
125496
- // "currency": "USDT",
125497
- // "rate": "0.0002",
125498
- // "amount": "100",
125499
- // "days": 10,
125500
- // "auto_renew": false,
125501
- // "currency_pair": "LTC_USDT",
125502
- // "left": "0",
125503
- // "repaid": "100",
125504
- // "paid_interest": "0.003333333333",
125505
- // "unpaid_interest": "0"
125506
- // }
125507
- //
125508
- if (marginMode === 'cross') {
125509
- response = response[0];
125510
- }
125511
- return this.parseMarginLoan(response, currency);
125512
- }
125513
- async borrowMargin(code, amount, symbol = undefined, params = {}) {
125514
- /**
125515
- * @method
125516
- * @name gate#borrowMargin
125517
- * @description create a loan to borrow margin
125518
- * @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
125519
- * @see https://www.gate.io/docs/apiv4/en/#lend-or-borrow
125520
- * @param {string} code unified currency code of the currency to borrow
125521
- * @param {float} amount the amount to borrow
125522
- * @param {string} symbol unified market symbol, required for isolated margin
125523
- * @param {object} [params] extra parameters specific to the gate api endpoint
125524
- * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
125525
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
125526
- */
125527
- const marginMode = this.safeString(params, 'marginMode'); // cross or isolated
125528
- params = this.omit(params, 'marginMode');
125529
- this.checkRequiredMarginArgument('borrowMargin', symbol, marginMode);
125530
- await this.loadMarkets();
125531
- const currency = this.currency(code);
125532
- const request = {
125533
- 'currency': currency['id'],
125534
- 'amount': this.currencyToPrecision(code, amount),
125535
- };
125536
- let response = undefined;
125537
- if (symbol === undefined) {
125538
- response = await this.privateMarginPostCrossLoans(this.extend(request, params));
125539
- }
125540
- else {
125541
- const market = this.market(symbol);
125542
- request['currency_pair'] = market['id'];
125543
- request['side'] = 'borrow';
125544
- // default it to 0.01% since this is a reasonable limit
125545
- // as it is the smallest tick size currently offered by gateio
125546
- request['rate'] = this.safeString(params, 'rate', '0.0001');
125547
- request['auto_renew'] = true;
125548
- params = this.omit(params, ['rate']);
125549
- response = await this.privateMarginPostLoans(this.extend(request, params));
125550
- }
125551
- //
125552
- // Cross
125553
- //
125554
- // {
125555
- // "id": "17",
125556
- // "create_time": 1620381696159,
125557
- // "update_time": 1620381696159,
125558
- // "currency": "EOS",
125559
- // "amount": "110.553635",
125560
- // "text": "web",
125561
- // "status": 2,
125562
- // "repaid": "110.506649705159",
125563
- // "repaid_interest": "0.046985294841",
125564
- // "unpaid_interest": "0.0000074393366667"
125565
- // }
125566
- //
125567
- // Isolated
125568
- //
125569
- // {
125570
- // "id": "34267567",
125571
- // "create_time": "1656394778",
125572
- // "expire_time": "1657258778",
125573
- // "status": "loaned",
125574
- // "side": "borrow",
125575
- // "currency": "USDT",
125576
- // "rate": "0.0002",
125577
- // "amount": "100",
125578
- // "days": 10,
125579
- // "auto_renew": false,
125580
- // "currency_pair": "LTC_USDT",
125581
- // "left": "0",
125582
- // "repaid": "0",
125583
- // "paid_interest": "0",
125584
- // "unpaid_interest": "0.003333333333"
125585
- // }
125586
- //
125587
- return this.parseMarginLoan(response, currency);
125588
- }
125589
- parseMarginLoan(info, currency = undefined) {
125590
- //
125591
- // Cross
125592
- //
125593
- // {
125594
- // "id": "17",
125595
- // "create_time": 1620381696159,
125596
- // "update_time": 1620381696159,
125597
- // "currency": "EOS",
125598
- // "amount": "110.553635",
125599
- // "text": "web",
125600
- // "status": 2,
125601
- // "repaid": "110.506649705159",
125602
- // "repaid_interest": "0.046985294841",
125603
- // "unpaid_interest": "0.0000074393366667"
125604
- // }
125605
- //
125606
- // Isolated
125607
- //
125608
- // {
125609
- // "id": "34267567",
125610
- // "create_time": "1656394778",
125611
- // "expire_time": "1657258778",
125612
- // "status": "loaned",
125613
- // "side": "borrow",
125614
- // "currency": "USDT",
125615
- // "rate": "0.0002",
125616
- // "amount": "100",
125617
- // "days": 10,
125618
- // "auto_renew": false,
125619
- // "currency_pair": "LTC_USDT",
125620
- // "left": "0",
125621
- // "repaid": "0",
125622
- // "paid_interest": "0",
125623
- // "unpaid_interest": "0.003333333333"
125624
- // }
125625
- //
125626
- const marginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
125627
- let timestamp = this.safeInteger(info, 'create_time');
125628
- if (marginMode === 'isolated') {
125629
- timestamp = this.safeTimestamp(info, 'create_time');
125630
- }
125631
- const currencyId = this.safeString(info, 'currency');
125632
- const marketId = this.safeString(info, 'currency_pair');
125633
- return {
125634
- 'id': this.safeInteger(info, 'id'),
125635
- 'currency': this.safeCurrencyCode(currencyId, currency),
125636
- 'amount': this.safeNumber(info, 'amount'),
125637
- 'symbol': this.safeSymbol(marketId, undefined, '_', 'margin'),
125638
- 'timestamp': timestamp,
125639
- 'datetime': this.iso8601(timestamp),
125640
- 'info': info,
125641
- };
125642
- }
125643
126753
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
125644
126754
  const authentication = api[0]; // public, private
125645
126755
  const type = api[1]; // spot, margin, future, delivery
@@ -157718,12 +158828,6 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
157718
158828
  'futuresPublic': 'https://api-futures.kucoin.com',
157719
158829
  'webExchange': 'https://futures.kucoin.com/_api/web-front',
157720
158830
  },
157721
- 'test': {
157722
- 'public': 'https://openapi-sandbox.kucoin.com',
157723
- 'private': 'https://openapi-sandbox.kucoin.com',
157724
- 'futuresPrivate': 'https://api-sandbox-futures.kucoin.com',
157725
- 'futuresPublic': 'https://api-sandbox-futures.kucoin.com',
157726
- },
157727
158831
  },
157728
158832
  'requiredCredentials': {
157729
158833
  'apiKey': true,
@@ -157948,6 +159052,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
157948
159052
  * @method
157949
159053
  * @name kucoinfutures#fetchStatus
157950
159054
  * @description the latest known information on the availability of the exchange API
159055
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-service-status
157951
159056
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
157952
159057
  * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
157953
159058
  */
@@ -157976,6 +159081,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
157976
159081
  * @method
157977
159082
  * @name kucoinfutures#fetchMarkets
157978
159083
  * @description retrieves data on all markets for kucoinfutures
159084
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list
157979
159085
  * @param {object} [params] extra parameters specific to the exchange api endpoint
157980
159086
  * @returns {object[]} an array of objects representing market data
157981
159087
  */
@@ -158140,6 +159246,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158140
159246
  * @method
158141
159247
  * @name kucoinfutures#fetchTime
158142
159248
  * @description fetches the current integer timestamp in milliseconds from the exchange server
159249
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-server-time
158143
159250
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
158144
159251
  * @returns {int} the current integer timestamp in milliseconds from the exchange server
158145
159252
  */
@@ -158157,6 +159264,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158157
159264
  * @method
158158
159265
  * @name kucoinfutures#fetchOHLCV
158159
159266
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
159267
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-klines
158160
159268
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
158161
159269
  * @param {string} timeframe the length of time each candle represents
158162
159270
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -158237,6 +159345,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158237
159345
  * @method
158238
159346
  * @name kucoinfutures#fetchDepositAddress
158239
159347
  * @description fetch the deposit address for a currency associated with this account
159348
+ * @see https://www.kucoin.com/docs/rest/funding/deposit/get-deposit-address
158240
159349
  * @param {string} code unified currency code
158241
159350
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
158242
159351
  * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
@@ -158276,6 +159385,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158276
159385
  * @method
158277
159386
  * @name kucoinfutures#fetchOrderBook
158278
159387
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
159388
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-part-order-book-level-2
158279
159389
  * @param {string} symbol unified symbol of the market to fetch the order book for
158280
159390
  * @param {int} [limit] the maximum amount of order book entries to return
158281
159391
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
@@ -158334,6 +159444,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158334
159444
  * @method
158335
159445
  * @name kucoinfutures#fetchTicker
158336
159446
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
159447
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-ticker
158337
159448
  * @param {string} symbol unified symbol of the market to fetch the ticker for
158338
159449
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
158339
159450
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -158415,6 +159526,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158415
159526
  * @method
158416
159527
  * @name kucoinfutures#fetchFundingHistory
158417
159528
  * @description fetch the history of funding payments paid and received on this account
159529
+ * @see https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-funding-history
158418
159530
  * @param {string} symbol unified market symbol
158419
159531
  * @param {int} [since] the earliest time in ms to fetch funding history for
158420
159532
  * @param {int} [limit] the maximum number of funding history structures to retrieve
@@ -158851,6 +159963,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158851
159963
  * @method
158852
159964
  * @name kucoinfutures#cancelOrder
158853
159965
  * @description cancels an open order
159966
+ * @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-futures-order-by-orderid
158854
159967
  * @param {string} id order id
158855
159968
  * @param {string} symbol unified symbol of the market the order was made in
158856
159969
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
@@ -158878,6 +159991,8 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158878
159991
  * @method
158879
159992
  * @name kucoinfutures#cancelAllOrders
158880
159993
  * @description cancel all open orders
159994
+ * @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-limit-orders
159995
+ * @see https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-stop-orders
158881
159996
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
158882
159997
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
158883
159998
  * @param {object} [params.stop] When true, all the trigger orders will be cancelled
@@ -158889,8 +160004,14 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158889
160004
  request['symbol'] = this.marketId(symbol);
158890
160005
  }
158891
160006
  const stop = this.safeValue(params, 'stop');
158892
- const method = stop ? 'futuresPrivateDeleteStopOrders' : 'futuresPrivateDeleteOrders';
158893
- const response = await this[method](this.extend(request, params));
160007
+ params = this.omit(params, 'stop');
160008
+ let response = undefined;
160009
+ if (stop) {
160010
+ response = await this.futuresPrivateDeleteStopOrders(this.extend(request, params));
160011
+ }
160012
+ else {
160013
+ response = await this.futuresPrivateDeleteOrders(this.extend(request, params));
160014
+ }
158894
160015
  //
158895
160016
  // {
158896
160017
  // "code": "200000",
@@ -158908,6 +160029,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
158908
160029
  * @method
158909
160030
  * @name kucoinfutures#addMargin
158910
160031
  * @description add margin
160032
+ * @see https://www.kucoin.com/docs/rest/futures-trading/positions/add-margin-manually
158911
160033
  * @param {string} symbol unified market symbol
158912
160034
  * @param {float} amount amount of margin to add
158913
160035
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
@@ -159091,8 +160213,13 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
159091
160213
  if (until !== undefined) {
159092
160214
  request['endAt'] = until;
159093
160215
  }
159094
- const method = stop ? 'futuresPrivateGetStopOrders' : 'futuresPrivateGetOrders';
159095
- const response = await this[method](this.extend(request, params));
160216
+ let response = undefined;
160217
+ if (stop) {
160218
+ response = await this.futuresPrivateGetStopOrders(this.extend(request, params));
160219
+ }
160220
+ else {
160221
+ response = await this.futuresPrivateGetOrders(this.extend(request, params));
160222
+ }
159096
160223
  //
159097
160224
  // {
159098
160225
  // "code": "200000",
@@ -159184,20 +160311,20 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
159184
160311
  */
159185
160312
  await this.loadMarkets();
159186
160313
  const request = {};
159187
- let method = 'futuresPrivateGetOrdersOrderId';
160314
+ let response = undefined;
159188
160315
  if (id === undefined) {
159189
160316
  const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
159190
160317
  if (clientOrderId === undefined) {
159191
160318
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' fetchOrder() requires parameter id or params.clientOid');
159192
160319
  }
159193
160320
  request['clientOid'] = clientOrderId;
159194
- method = 'futuresPrivateGetOrdersByClientOid';
159195
160321
  params = this.omit(params, ['clientOid', 'clientOrderId']);
160322
+ response = await this.futuresPrivateGetOrdersByClientOid(this.extend(request, params));
159196
160323
  }
159197
160324
  else {
159198
160325
  request['orderId'] = id;
160326
+ response = await this.futuresPrivateGetOrdersOrderId(this.extend(request, params));
159199
160327
  }
159200
- const response = await this[method](this.extend(request, params));
159201
160328
  //
159202
160329
  // {
159203
160330
  // "code": "200000",
@@ -159362,6 +160489,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
159362
160489
  * @method
159363
160490
  * @name kucoinfutures#fetchFundingRate
159364
160491
  * @description fetch the current funding rate
160492
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-current-funding-rate
159365
160493
  * @param {string} symbol unified market symbol
159366
160494
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
159367
160495
  * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
@@ -159427,6 +160555,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
159427
160555
  * @method
159428
160556
  * @name kucoinfutures#fetchBalance
159429
160557
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
160558
+ * @see https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-futures
159430
160559
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
159431
160560
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
159432
160561
  */
@@ -159604,6 +160733,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
159604
160733
  * @method
159605
160734
  * @name kucoinfutures#fetchTrades
159606
160735
  * @description get the list of most recent trades for a particular symbol
160736
+ * @see https://www.kucoin.com/docs/rest/futures-trading/market-data/get-transaction-history
159607
160737
  * @param {string} symbol unified symbol of the market to fetch trades for
159608
160738
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
159609
160739
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -159886,6 +161016,7 @@ class kucoinfutures extends _abstract_kucoinfutures_js__WEBPACK_IMPORTED_MODULE_
159886
161016
  * @method
159887
161017
  * @name kucoinfutures#fetchMarketLeverageTiers
159888
161018
  * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
161019
+ * @see https://www.kucoin.com/docs/rest/futures-trading/risk-limit/get-futures-risk-limit-level
159889
161020
  * @param {string} symbol unified market symbol
159890
161021
  * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
159891
161022
  * @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}
@@ -244893,8 +246024,8 @@ class phemex extends _phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .Z
244893
246024
  /* harmony export */ });
244894
246025
  /* harmony import */ var _poloniex_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8891);
244895
246026
  /* harmony import */ var _base_errors_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6689);
244896
- /* harmony import */ var _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3020);
244897
- /* harmony import */ var _base_Precise_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2194);
246027
+ /* harmony import */ var _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(3020);
246028
+ /* harmony import */ var _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2194);
244898
246029
  /* harmony import */ var _static_dependencies_noble_hashes_sha256_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1372);
244899
246030
  // ---------------------------------------------------------------------------
244900
246031
 
@@ -244917,6 +246048,15 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
244917
246048
  'watchStatus': false,
244918
246049
  'watchOrders': true,
244919
246050
  'watchMyTrades': true,
246051
+ 'createOrderWs': true,
246052
+ 'editOrderWs': false,
246053
+ 'fetchOpenOrdersWs': false,
246054
+ 'fetchOrderWs': false,
246055
+ 'cancelOrderWs': true,
246056
+ 'cancelOrdersWs': true,
246057
+ 'cancelAllOrdersWs': true,
246058
+ 'fetchTradesWs': false,
246059
+ 'fetchBalanceWs': false,
244920
246060
  },
244921
246061
  'urls': {
244922
246062
  'api': {
@@ -244927,6 +246067,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
244927
246067
  },
244928
246068
  },
244929
246069
  'options': {
246070
+ 'createMarketBuyOrderRequiresPrice': true,
244930
246071
  'tradesLimit': 1000,
244931
246072
  'ordersLimit': 1000,
244932
246073
  'OHLCVLimit': 1000,
@@ -245046,6 +246187,164 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245046
246187
  const request = this.extend(subscribe, params);
245047
246188
  return await this.watch(url, messageHash, request, messageHash);
245048
246189
  }
246190
+ async tradeRequest(name, params = {}) {
246191
+ /**
246192
+ * @ignore
246193
+ * @method
246194
+ * @description Connects to a websocket channel
246195
+ * @param {string} name name of the channel
246196
+ * @param {string[]|undefined} symbols CCXT market symbols
246197
+ * @param {object} [params] extra parameters specific to the poloniex api
246198
+ * @returns {object} data from the websocket stream
246199
+ */
246200
+ const url = this.urls['api']['ws']['private'];
246201
+ const messageHash = this.nonce();
246202
+ const subscribe = {
246203
+ 'id': messageHash,
246204
+ 'event': name,
246205
+ 'params': params,
246206
+ };
246207
+ return await this.watch(url, messageHash, subscribe, messageHash);
246208
+ }
246209
+ async createOrderWs(symbol, type, side, amount, price = undefined, params = {}) {
246210
+ /**
246211
+ * @method
246212
+ * @name poloniex#createOrderWs
246213
+ * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-create-order
246214
+ * @description create a trade order
246215
+ * @param {string} symbol unified symbol of the market to create an order in
246216
+ * @param {string} type 'market' or 'limit'
246217
+ * @param {string} side 'buy' or 'sell'
246218
+ * @param {float} amount how much of currency you want to trade in units of base currency
246219
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
246220
+ * @param {object} [params] extra parameters specific to the poloniex api endpoint
246221
+ * @param {string} [params.timeInForce] GTC (default), IOC, FOK
246222
+ * @param {string} [params.clientOrderId] Maximum 64-character length.*
246223
+ *
246224
+ * EXCHANGE SPECIFIC PARAMETERS
246225
+ * @param {string} [params.amount] quote units for the order
246226
+ * @param {boolean} [params.allowBorrow] allow order to be placed by borrowing funds (Default: false)
246227
+ * @param {string} [params.stpMode] self-trade prevention, defaults to expire_taker, none: enable self-trade; expire_taker: taker order will be canceled when self-trade happens
246228
+ * @param {string} [params.slippageTolerance] used to control the maximum slippage ratio, the value range is greater than 0 and less than 1
246229
+ * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
246230
+ */
246231
+ await this.loadMarkets();
246232
+ await this.authenticate();
246233
+ const market = this.market(symbol);
246234
+ let uppercaseType = type.toUpperCase();
246235
+ const uppercaseSide = side.toUpperCase();
246236
+ const isPostOnly = this.isPostOnly(uppercaseType === 'MARKET', uppercaseType === 'LIMIT_MAKER', params);
246237
+ if (isPostOnly) {
246238
+ uppercaseType = 'LIMIT_MAKER';
246239
+ }
246240
+ const request = {
246241
+ 'symbol': market['id'],
246242
+ 'side': side.toUpperCase(),
246243
+ 'type': type.toUpperCase(),
246244
+ };
246245
+ if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) {
246246
+ let quoteAmount = this.safeString(params, 'amount');
246247
+ if ((quoteAmount === undefined) && (this.options['createMarketBuyOrderRequiresPrice'])) {
246248
+ const cost = this.safeNumber(params, 'cost');
246249
+ params = this.omit(params, 'cost');
246250
+ if (price === undefined && cost === undefined) {
246251
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ArgumentsRequired(this.id + ' createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options["createMarketBuyOrderRequiresPrice"] = false to supply the cost in the amount argument (the exchange-specific behaviour)');
246252
+ }
246253
+ else {
246254
+ const amountString = this.numberToString(amount);
246255
+ const priceString = this.numberToString(price);
246256
+ const quote = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
246257
+ amount = (cost !== undefined) ? cost : this.parseNumber(quote);
246258
+ quoteAmount = this.costToPrecision(symbol, amount);
246259
+ }
246260
+ }
246261
+ else {
246262
+ quoteAmount = this.costToPrecision(symbol, amount);
246263
+ }
246264
+ request['amount'] = this.amountToPrecision(market['symbol'], quoteAmount);
246265
+ }
246266
+ else {
246267
+ request['quantity'] = this.amountToPrecision(market['symbol'], amount);
246268
+ if (price !== undefined) {
246269
+ request['price'] = this.priceToPrecision(symbol, price);
246270
+ }
246271
+ }
246272
+ return await this.tradeRequest('createOrder', this.extend(request, params));
246273
+ }
246274
+ async cancelOrderWs(id, symbol = undefined, params = {}) {
246275
+ /**
246276
+ * @method
246277
+ * @name poloniex#cancelOrderWs
246278
+ * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-multiple-orders
246279
+ * @description cancel multiple orders
246280
+ * @param {string} id order id
246281
+ * @param {string} [symbol] unified market symbol
246282
+ * @param {object} [params] extra parameters specific to the poloniex api endpoint
246283
+ * @param {string} [params.clientOrderId] client order id
246284
+ * @returns {object} an list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
246285
+ */
246286
+ const clientOrderId = this.safeString(params, 'clientOrderId');
246287
+ if (clientOrderId !== undefined) {
246288
+ const clientOrderIds = this.safeValue(params, 'clientOrderId', []);
246289
+ params['clientOrderIds'] = this.arrayConcat(clientOrderIds, [clientOrderId]);
246290
+ }
246291
+ return await this.cancelOrdersWs([id], symbol, params);
246292
+ }
246293
+ async cancelOrdersWs(ids, symbol = undefined, params = {}) {
246294
+ /**
246295
+ * @method
246296
+ * @name poloniex#cancelOrdersWs
246297
+ * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-multiple-orders
246298
+ * @description cancel multiple orders
246299
+ * @param {string[]} ids order ids
246300
+ * @param {string} symbol unified market symbol, default is undefined
246301
+ * @param {object} [params] extra parameters specific to the poloniex api endpoint
246302
+ * @param {string[]} [params.clientOrderIds] client order ids
246303
+ * @returns {object} an list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
246304
+ */
246305
+ await this.loadMarkets();
246306
+ await this.authenticate();
246307
+ const request = {
246308
+ 'orderIds': ids,
246309
+ };
246310
+ return await this.tradeRequest('cancelOrders', this.extend(request, params));
246311
+ }
246312
+ async cancelAllOrdersWs(symbol = undefined, params = {}) {
246313
+ /**
246314
+ * @method
246315
+ * @name poloniex#cancelAllOrdersWs
246316
+ * @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-all-orders
246317
+ * @description cancel all open orders of a type. Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.
246318
+ * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
246319
+ * @param {object} [params] extra parameters specific to the poloniex api endpoint
246320
+ * @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
246321
+ */
246322
+ await this.loadMarkets();
246323
+ await this.authenticate();
246324
+ return await this.tradeRequest('cancelAllOrders', params);
246325
+ }
246326
+ handleOrderRequest(client, message) {
246327
+ //
246328
+ // {
246329
+ // "id": "1234567",
246330
+ // "data": [{
246331
+ // "orderId": 205343650954092544,
246332
+ // "clientOrderId": "",
246333
+ // "message": "",
246334
+ // "code": 200
246335
+ // }]
246336
+ // }
246337
+ //
246338
+ const messageHash = this.safeInteger(message, 'id');
246339
+ const data = this.safeValue(message, 'data', []);
246340
+ const orders = [];
246341
+ for (let i = 0; i < data.length; i++) {
246342
+ const order = data[i];
246343
+ const parsedOrder = this.parseWsOrder(order);
246344
+ orders.push(parsedOrder);
246345
+ }
246346
+ client.resolve(orders, messageHash);
246347
+ }
245049
246348
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
245050
246349
  /**
245051
246350
  * @method
@@ -245269,7 +246568,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245269
246568
  if (symbol !== undefined) {
245270
246569
  if (stored === undefined) {
245271
246570
  const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
245272
- stored = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_3__/* .ArrayCacheByTimestamp */ .Py(limit);
246571
+ stored = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_4__/* .ArrayCacheByTimestamp */ .Py(limit);
245273
246572
  this.ohlcvs[symbol][timeframe] = stored;
245274
246573
  }
245275
246574
  stored.append(parsed);
@@ -245307,7 +246606,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245307
246606
  let tradesArray = this.safeValue(this.trades, symbol);
245308
246607
  if (tradesArray === undefined) {
245309
246608
  const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
245310
- tradesArray = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_3__/* .ArrayCache */ .ZL(tradesLimit);
246609
+ tradesArray = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_4__/* .ArrayCache */ .ZL(tradesLimit);
245311
246610
  this.trades[symbol] = tradesArray;
245312
246611
  }
245313
246612
  tradesArray.append(trade);
@@ -245486,7 +246785,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245486
246785
  let orders = this.orders;
245487
246786
  if (orders === undefined) {
245488
246787
  const limit = this.safeInteger(this.options, 'ordersLimit');
245489
- orders = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_3__/* .ArrayCacheBySymbolById */ .hl(limit);
246788
+ orders = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_4__/* .ArrayCacheBySymbolById */ .hl(limit);
245490
246789
  this.orders = orders;
245491
246790
  }
245492
246791
  const marketIds = [];
@@ -245519,21 +246818,21 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245519
246818
  const previousOrderTrade = previousOrderTrades[j];
245520
246819
  const cost = this.numberToString(previousOrderTrade['cost']);
245521
246820
  const amount = this.numberToString(previousOrderTrade['amount']);
245522
- totalCost = _base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringAdd(totalCost, cost);
245523
- totalAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringAdd(totalAmount, amount);
246821
+ totalCost = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAdd(totalCost, cost);
246822
+ totalAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAdd(totalAmount, amount);
245524
246823
  }
245525
- if (_base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringGt(totalAmount, '0')) {
245526
- previousOrder['average'] = this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringDiv(totalCost, totalAmount));
246824
+ if (_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringGt(totalAmount, '0')) {
246825
+ previousOrder['average'] = this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringDiv(totalCost, totalAmount));
245527
246826
  }
245528
246827
  previousOrder['cost'] = this.parseNumber(totalCost);
245529
246828
  if (previousOrder['filled'] !== undefined) {
245530
246829
  const tradeAmount = this.numberToString(trade['amount']);
245531
246830
  let previousOrderFilled = this.numberToString(previousOrder['filled']);
245532
- previousOrderFilled = _base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringAdd(previousOrderFilled, tradeAmount);
246831
+ previousOrderFilled = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAdd(previousOrderFilled, tradeAmount);
245533
246832
  previousOrder['filled'] = previousOrderFilled;
245534
246833
  if (previousOrder['amount'] !== undefined) {
245535
246834
  const previousOrderAmount = this.numberToString(previousOrder['amount']);
245536
- previousOrder['remaining'] = this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringSub(previousOrderAmount, previousOrderFilled));
246835
+ previousOrder['remaining'] = this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringSub(previousOrderAmount, previousOrderFilled));
245537
246836
  }
245538
246837
  }
245539
246838
  if (previousOrder['fee'] === undefined) {
@@ -245546,7 +246845,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245546
246845
  if ((previousOrder['fee']['cost'] !== undefined) && (trade['fee']['cost'] !== undefined)) {
245547
246846
  const stringOrderCost = this.numberToString(previousOrder['fee']['cost']);
245548
246847
  const stringTradeCost = this.numberToString(trade['fee']['cost']);
245549
- previousOrder['fee']['cost'] = _base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringAdd(stringOrderCost, stringTradeCost);
246848
+ previousOrder['fee']['cost'] = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAdd(stringOrderCost, stringTradeCost);
245550
246849
  }
245551
246850
  const rawState = this.safeString(order, 'state');
245552
246851
  const state = this.parseStatus(rawState);
@@ -245603,7 +246902,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245603
246902
  const filledAmount = this.safeString(order, 'filledAmount');
245604
246903
  const status = this.safeString(order, 'state');
245605
246904
  let trades = undefined;
245606
- if (!_base_Precise_js__WEBPACK_IMPORTED_MODULE_4__/* .Precise */ .O.stringEq(filledAmount, '0')) {
246905
+ if (!_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringEq(filledAmount, '0')) {
245607
246906
  trades = [];
245608
246907
  const trade = this.parseWsOrderTrade(order);
245609
246908
  trades.push(trade);
@@ -245844,7 +247143,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245844
247143
  const symbol = parsedTrade['symbol'];
245845
247144
  if (this.myTrades === undefined) {
245846
247145
  const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
245847
- this.myTrades = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_3__/* .ArrayCacheBySymbolById */ .hl(limit);
247146
+ this.myTrades = new _base_ws_Cache_js__WEBPACK_IMPORTED_MODULE_4__/* .ArrayCacheBySymbolById */ .hl(limit);
245848
247147
  }
245849
247148
  const trades = this.myTrades;
245850
247149
  trades.append(parsedTrade);
@@ -245852,6 +247151,9 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245852
247151
  const symbolMessageHash = messageHash + ':' + symbol;
245853
247152
  client.resolve(trades, symbolMessageHash);
245854
247153
  }
247154
+ handlePong(client) {
247155
+ client.lastPong = this.milliseconds();
247156
+ }
245855
247157
  handleMessage(client, message) {
245856
247158
  if (this.handleErrorMessage(client, message)) {
245857
247159
  return;
@@ -245882,11 +247184,26 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245882
247184
  'trades': this.handleTrade,
245883
247185
  'orders': this.handleOrder,
245884
247186
  'balances': this.handleBalance,
247187
+ 'createOrder': this.handleOrderRequest,
247188
+ 'cancelOrder': this.handleOrderRequest,
247189
+ 'cancelAllOrders': this.handleOrderRequest,
247190
+ 'auth': this.handleAuthenticate,
245885
247191
  };
245886
247192
  const method = this.safeValue(methods, type);
245887
247193
  if (type === 'auth') {
245888
247194
  this.handleAuthenticate(client, message);
245889
247195
  }
247196
+ else if (type === undefined) {
247197
+ const data = this.safeValue(message, 'data');
247198
+ const item = this.safeValue(data, 0);
247199
+ const orderId = this.safeString(item, 'orderId');
247200
+ if (orderId === '0') {
247201
+ this.handleErrorMessage(client, item);
247202
+ }
247203
+ else {
247204
+ return this.handleOrderRequest(client, message);
247205
+ }
247206
+ }
245890
247207
  else {
245891
247208
  const data = this.safeValue(message, 'data', []);
245892
247209
  const dataLength = data.length;
@@ -245897,9 +247214,26 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
245897
247214
  }
245898
247215
  handleErrorMessage(client, message) {
245899
247216
  //
245900
- // { message: 'Invalid channel value ["ordersss"]', event: 'error' }
247217
+ // {
247218
+ // message: 'Invalid channel value ["ordersss"]',
247219
+ // event: 'error'
247220
+ // }
247221
+ //
247222
+ // {
247223
+ // "orderId": 0,
247224
+ // "clientOrderId": null,
247225
+ // "message": "Currency trade disabled",
247226
+ // "code": 21352
247227
+ // }
247228
+ //
247229
+ // {
247230
+ // "event": "error",
247231
+ // "message": "Platform in maintenance mode"
247232
+ // }
247233
+ //
245901
247234
  const event = this.safeString(message, 'event');
245902
- if (event === 'error') {
247235
+ const orderId = this.safeString(message, 'orderId');
247236
+ if ((event === 'error') || (orderId === '0')) {
245903
247237
  const error = this.safeString(message, 'message');
245904
247238
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ExchangeError(this.id + ' error: ' + this.json(error));
245905
247239
  }
@@ -286133,7 +287467,7 @@ SOFTWARE.
286133
287467
 
286134
287468
  //-----------------------------------------------------------------------------
286135
287469
  // this is updated by vss.js when building
286136
- const version = '4.1.61';
287470
+ const version = '4.1.63';
286137
287471
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange */ .e.ccxtVersion = version;
286138
287472
  //-----------------------------------------------------------------------------
286139
287473