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.
package/dist/cjs/ccxt.js CHANGED
@@ -173,7 +173,7 @@ var woo$1 = require('./src/pro/woo.js');
173
173
 
174
174
  //-----------------------------------------------------------------------------
175
175
  // this is updated by vss.js when building
176
- const version = '4.1.61';
176
+ const version = '4.1.63';
177
177
  Exchange["default"].ccxtVersion = version;
178
178
  const exchanges = {
179
179
  'ace': ace,
@@ -50,7 +50,7 @@ class alpaca extends alpaca$1 {
50
50
  'createOrder': true,
51
51
  'fetchBalance': true,
52
52
  'fetchBidsAsks': false,
53
- 'fetchClosedOrders': false,
53
+ 'fetchClosedOrders': true,
54
54
  'fetchCurrencies': false,
55
55
  'fetchDepositAddress': false,
56
56
  'fetchDepositAddressesByNetwork': false,
@@ -68,12 +68,12 @@ class alpaca extends alpaca$1 {
68
68
  'fetchOpenOrders': true,
69
69
  'fetchOrder': true,
70
70
  'fetchOrderBook': true,
71
- 'fetchOrders': false,
71
+ 'fetchOrders': true,
72
72
  'fetchPositions': false,
73
73
  'fetchStatus': false,
74
74
  'fetchTicker': false,
75
75
  'fetchTickers': false,
76
- 'fetchTime': false,
76
+ 'fetchTime': true,
77
77
  'fetchTrades': true,
78
78
  'fetchTradingFee': false,
79
79
  'fetchTradingFees': false,
@@ -261,42 +261,90 @@ class alpaca extends alpaca$1 {
261
261
  },
262
262
  });
263
263
  }
264
+ async fetchTime(params = {}) {
265
+ /**
266
+ * @method
267
+ * @name alpaca#fetchTime
268
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
269
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
270
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
271
+ */
272
+ const response = await this.traderPrivateGetV2Clock(params);
273
+ //
274
+ // {
275
+ // timestamp: '2023-11-22T08:07:57.654738097-05:00',
276
+ // is_open: false,
277
+ // next_open: '2023-11-22T09:30:00-05:00',
278
+ // next_close: '2023-11-22T16:00:00-05:00'
279
+ // }
280
+ //
281
+ const timestamp = this.safeString(response, 'timestamp');
282
+ const localTime = timestamp.slice(0, 23);
283
+ const jetlagStrStart = timestamp.length - 6;
284
+ const jetlagStrEnd = timestamp.length - 3;
285
+ const jetlag = timestamp.slice(jetlagStrStart, jetlagStrEnd);
286
+ const iso = this.parse8601(localTime) - this.parseToNumeric(jetlag) * 3600 * 1000;
287
+ return iso;
288
+ }
264
289
  async fetchMarkets(params = {}) {
265
290
  /**
266
291
  * @method
267
292
  * @name alpaca#fetchMarkets
268
293
  * @description retrieves data on all markets for alpaca
294
+ * @see https://docs.alpaca.markets/reference/get-v2-assets
269
295
  * @param {object} [params] extra parameters specific to the exchange api endpoint
270
296
  * @returns {object[]} an array of objects representing market data
271
297
  */
272
298
  const request = {
273
299
  'asset_class': 'crypto',
274
- 'tradeable': true,
300
+ 'status': 'active',
275
301
  };
276
302
  const assets = await this.traderPrivateGetV2Assets(this.extend(request, params));
277
303
  //
278
- // [
279
- // {
280
- // "id":"a3ba8ac0-166d-460b-b17a-1f035622dd47",
281
- // "class":"crypto",
282
- // "exchange":"FTXU",
283
- // "symbol":"DOGEUSD",
284
- // "name":"Dogecoin",
285
- // "status":"active",
286
- // "tradable":true,
287
- // "marginable":false,
288
- // "shortable":false,
289
- // "easy_to_borrow":false,
290
- // "fractionable":true,
291
- // "min_order_size":"1",
292
- // "min_trade_increment":"1",
293
- // "price_increment":"0.0000005"
294
- // }
295
- // ]
304
+ // [
305
+ // {
306
+ // "id": "c150e086-1e75-44e6-9c2c-093bb1e93139",
307
+ // "class": "crypto",
308
+ // "exchange": "CRYPTO",
309
+ // "symbol": "BTC/USDT",
310
+ // "name": "Bitcoin / USD Tether",
311
+ // "status": "active",
312
+ // "tradable": true,
313
+ // "marginable": false,
314
+ // "maintenance_margin_requirement": 100,
315
+ // "shortable": false,
316
+ // "easy_to_borrow": false,
317
+ // "fractionable": true,
318
+ // "attributes": [],
319
+ // "min_order_size": "0.000026873",
320
+ // "min_trade_increment": "0.000000001",
321
+ // "price_increment": "1"
322
+ // }
323
+ // ]
296
324
  //
297
325
  return this.parseMarkets(assets);
298
326
  }
299
327
  parseMarket(asset) {
328
+ //
329
+ // {
330
+ // "id": "c150e086-1e75-44e6-9c2c-093bb1e93139",
331
+ // "class": "crypto",
332
+ // "exchange": "CRYPTO",
333
+ // "symbol": "BTC/USDT",
334
+ // "name": "Bitcoin / USD Tether",
335
+ // "status": "active",
336
+ // "tradable": true,
337
+ // "marginable": false,
338
+ // "maintenance_margin_requirement": 100,
339
+ // "shortable": false,
340
+ // "easy_to_borrow": false,
341
+ // "fractionable": true,
342
+ // "attributes": [],
343
+ // "min_order_size": "0.000026873",
344
+ // "min_trade_increment": "0.000000001",
345
+ // "price_increment": "1"
346
+ // }
347
+ //
300
348
  const marketId = this.safeString(asset, 'symbol');
301
349
  const parts = marketId.split('/');
302
350
  const baseId = this.safeString(parts, 0);
@@ -436,21 +484,17 @@ class alpaca extends alpaca$1 {
436
484
  return this.parseTrades(symbolTrades, market, since, limit);
437
485
  }
438
486
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
439
- //
440
- // @method
441
- // @name alpaca#fetchOrderBook
442
- // @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
443
- // @see https://docs.alpaca.markets/reference/cryptolatestorderbooks
444
- // @param {string} symbol unified symbol of the market to fetch the order book for
445
- // @param {int} [limit] the maximum amount of order book entries to return
446
- // @param {object} [params] extra parameters specific to the alpaca api endpoint
447
- // <<<<<<< HEAD
448
- // @param {string} [params.loc] crypto location, default: us
449
- // @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
450
- // =======
451
- // @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
452
- // >>>>>>> f68b1b599ee41469fefa424f0efc9b6891549278
453
- //
487
+ /**
488
+ * @method
489
+ * @name alpaca#fetchOrderBook
490
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
491
+ * @see https://docs.alpaca.markets/reference/cryptolatestorderbooks
492
+ * @param {string} symbol unified symbol of the market to fetch the order book for
493
+ * @param {int} [limit] the maximum amount of order book entries to return
494
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
495
+ * @param {string} [params.loc] crypto location, default: us
496
+ * @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
497
+ */
454
498
  await this.loadMarkets();
455
499
  const market = this.market(symbol);
456
500
  const id = market['id'];
@@ -625,6 +669,7 @@ class alpaca extends alpaca$1 {
625
669
  * @method
626
670
  * @name alpaca#createOrder
627
671
  * @description create a trade order
672
+ * @see https://docs.alpaca.markets/reference/postorder
628
673
  * @param {string} symbol unified symbol of the market to create an order in
629
674
  * @param {string} type 'market', 'limit' or 'stop_limit'
630
675
  * @param {string} side 'buy' or 'sell'
@@ -713,6 +758,7 @@ class alpaca extends alpaca$1 {
713
758
  * @method
714
759
  * @name alpaca#cancelOrder
715
760
  * @description cancels an open order
761
+ * @see https://docs.alpaca.markets/reference/deleteorderbyorderid
716
762
  * @param {string} id order id
717
763
  * @param {string} symbol unified symbol of the market the order was made in
718
764
  * @param {object} [params] extra parameters specific to the alpaca api endpoint
@@ -730,11 +776,31 @@ class alpaca extends alpaca$1 {
730
776
  //
731
777
  return this.safeValue(response, 'message', {});
732
778
  }
779
+ async cancelAllOrders(symbol = undefined, params = {}) {
780
+ /**
781
+ * @method
782
+ * @name alpaca#cancelAllOrders
783
+ * @description cancel all open orders in a market
784
+ * @see https://docs.alpaca.markets/reference/deleteallorders
785
+ * @param {string} symbol alpaca cancelAllOrders cannot setting symbol, it will cancel all open orders
786
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
787
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
788
+ */
789
+ await this.loadMarkets();
790
+ const response = await this.traderPrivateDeleteV2Orders(params);
791
+ if (Array.isArray(response)) {
792
+ return this.parseOrders(response, undefined);
793
+ }
794
+ else {
795
+ return response;
796
+ }
797
+ }
733
798
  async fetchOrder(id, symbol = undefined, params = {}) {
734
799
  /**
735
800
  * @method
736
801
  * @name alpaca#fetchOrder
737
802
  * @description fetches information on an order made by the user
803
+ * @see https://docs.alpaca.markets/reference/getorderbyorderid
738
804
  * @param {string} symbol unified symbol of the market the order was made in
739
805
  * @param {object} [params] extra parameters specific to the alpaca api endpoint
740
806
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -748,24 +814,117 @@ class alpaca extends alpaca$1 {
748
814
  const market = this.safeMarket(marketId);
749
815
  return this.parseOrder(order, market);
750
816
  }
751
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
817
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
752
818
  /**
753
819
  * @method
754
- * @name alpaca#fetchOpenOrders
755
- * @description fetch all unfilled currently open orders
756
- * @param {string} symbol unified market symbol
757
- * @param {int} [since] the earliest time in ms to fetch open orders for
758
- * @param {int} [limit] the maximum number of open orders structures to retrieve
820
+ * @name alpaca#fetchOrders
821
+ * @description fetches information on multiple orders made by the user
822
+ * @see https://docs.alpaca.markets/reference/getallorders
823
+ * @param {string} symbol unified market symbol of the market orders were made in
824
+ * @param {int} [since] the earliest time in ms to fetch orders for
825
+ * @param {int} [limit] the maximum number of order structures to retrieve
759
826
  * @param {object} [params] extra parameters specific to the alpaca api endpoint
827
+ * @param {int} [params.until] the latest time in ms to fetch orders for
760
828
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
761
829
  */
762
830
  await this.loadMarkets();
831
+ const request = {
832
+ 'status': 'all',
833
+ };
763
834
  let market = undefined;
764
835
  if (symbol !== undefined) {
765
836
  market = this.market(symbol);
837
+ request['symbols'] = market['id'];
766
838
  }
767
- const orders = await this.traderPrivateGetV2Orders(params);
768
- return this.parseOrders(orders, market, since, limit);
839
+ const until = this.safeInteger(params, 'until');
840
+ if (until !== undefined) {
841
+ params = this.omit(params, 'until');
842
+ request['endTime'] = until;
843
+ }
844
+ if (since !== undefined) {
845
+ request['after'] = since;
846
+ }
847
+ if (limit !== undefined) {
848
+ request['limit'] = limit;
849
+ }
850
+ const response = await this.traderPrivateGetV2Orders(this.extend(request, params));
851
+ //
852
+ // [
853
+ // {
854
+ // "id": "cbaf12d7-69b8-49c0-a31b-b46af35c755c",
855
+ // "client_order_id": "ccxt_b36156ae6fd44d098ac9c179bab33efd",
856
+ // "created_at": "2023-11-17T04:21:42.234579Z",
857
+ // "updated_at": "2023-11-17T04:22:34.442765Z",
858
+ // "submitted_at": "2023-11-17T04:21:42.233357Z",
859
+ // "filled_at": null,
860
+ // "expired_at": null,
861
+ // "canceled_at": "2023-11-17T04:22:34.399019Z",
862
+ // "failed_at": null,
863
+ // "replaced_at": null,
864
+ // "replaced_by": null,
865
+ // "replaces": null,
866
+ // "asset_id": "77c6f47f-0939-4b23-b41e-47b4469c4bc8",
867
+ // "symbol": "LTC/USDT",
868
+ // "asset_class": "crypto",
869
+ // "notional": null,
870
+ // "qty": "0.001",
871
+ // "filled_qty": "0",
872
+ // "filled_avg_price": null,
873
+ // "order_class": "",
874
+ // "order_type": "limit",
875
+ // "type": "limit",
876
+ // "side": "sell",
877
+ // "time_in_force": "gtc",
878
+ // "limit_price": "1000",
879
+ // "stop_price": null,
880
+ // "status": "canceled",
881
+ // "extended_hours": false,
882
+ // "legs": null,
883
+ // "trail_percent": null,
884
+ // "trail_price": null,
885
+ // "hwm": null,
886
+ // "subtag": null,
887
+ // "source": "access_key"
888
+ // }
889
+ // ]
890
+ //
891
+ return this.parseOrders(response, market, since, limit);
892
+ }
893
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
894
+ /**
895
+ * @method
896
+ * @name alpaca#fetchOpenOrders
897
+ * @description fetch all unfilled currently open orders
898
+ * @see https://docs.alpaca.markets/reference/getallorders
899
+ * @param {string} symbol unified market symbol of the market orders were made in
900
+ * @param {int} [since] the earliest time in ms to fetch orders for
901
+ * @param {int} [limit] the maximum number of order structures to retrieve
902
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
903
+ * @param {int} [params.until] the latest time in ms to fetch orders for
904
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
905
+ */
906
+ const request = {
907
+ 'status': 'open',
908
+ };
909
+ return await this.fetchOrders(symbol, since, limit, this.extend(request, params));
910
+ }
911
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
912
+ /**
913
+ * @method
914
+ * @name alpaca#fetchClosedOrders
915
+ * @description fetches information on multiple closed orders made by the user
916
+ * @see https://docs.alpaca.markets/reference/getallorders
917
+ * @param {string} symbol unified market symbol of the market orders were made in
918
+ * @param {int} [since] the earliest time in ms to fetch orders for
919
+ * @param {int} [limit] the maximum number of order structures to retrieve
920
+ * @param {object} [params] extra parameters specific to the alpaca api endpoint
921
+ * @param {int} [params.until] the latest time in ms to fetch orders for
922
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
923
+ */
924
+ const request = {
925
+ 'status': 'closed',
926
+ };
927
+ return await this.fetchOrders(symbol, since, limit, this.extend(request, params));
769
928
  }
770
929
  parseOrder(order, market = undefined) {
771
930
  //
@@ -820,9 +979,11 @@ class alpaca extends alpaca$1 {
820
979
  };
821
980
  }
822
981
  let orderType = this.safeString(order, 'order_type');
823
- if (orderType.indexOf('limit') >= 0) {
824
- // might be limit or stop-limit
825
- orderType = 'limit';
982
+ if (orderType !== undefined) {
983
+ if (orderType.indexOf('limit') >= 0) {
984
+ // might be limit or stop-limit
985
+ orderType = 'limit';
986
+ }
826
987
  }
827
988
  const datetime = this.safeString(order, 'submitted_at');
828
989
  const timestamp = this.parse8601(datetime);
@@ -1898,11 +1898,13 @@ class Exchange {
1898
1898
  }
1899
1899
  }
1900
1900
  if (!parseFee && (reducedLength === 0)) {
1901
- fee['cost'] = this.safeNumber(fee, 'cost');
1902
- if ('rate' in fee) {
1903
- fee['rate'] = this.safeNumber(fee, 'rate');
1901
+ // copy fee to avoid modification by reference
1902
+ const feeCopy = this.deepExtend(fee);
1903
+ feeCopy['cost'] = this.safeNumber(feeCopy, 'cost');
1904
+ if ('rate' in feeCopy) {
1905
+ feeCopy['rate'] = this.safeNumber(feeCopy, 'rate');
1904
1906
  }
1905
- reducedFees.push(fee);
1907
+ reducedFees.push(feeCopy);
1906
1908
  }
1907
1909
  order['fees'] = reducedFees;
1908
1910
  if (parseFee && (reducedLength === 1)) {
@@ -2187,11 +2189,13 @@ class Exchange {
2187
2189
  }
2188
2190
  }
2189
2191
  if (!parseFee && (reducedLength === 0)) {
2190
- fee['cost'] = this.safeNumber(fee, 'cost');
2191
- if ('rate' in fee) {
2192
- fee['rate'] = this.safeNumber(fee, 'rate');
2192
+ // copy fee to avoid modification by reference
2193
+ const feeCopy = this.deepExtend(fee);
2194
+ feeCopy['cost'] = this.safeNumber(feeCopy, 'cost');
2195
+ if ('rate' in feeCopy) {
2196
+ feeCopy['rate'] = this.safeNumber(feeCopy, 'rate');
2193
2197
  }
2194
- reducedFees.push(fee);
2198
+ reducedFees.push(feeCopy);
2195
2199
  }
2196
2200
  if (parseFees) {
2197
2201
  trade['fees'] = reducedFees;
@@ -967,7 +967,7 @@ class binance extends binance$1 {
967
967
  'cm/income': 30,
968
968
  'um/account': 5,
969
969
  'cm/account': 5,
970
- 'portfolio/repay-futures-switch': 3,
970
+ 'repay-futures-switch': 3,
971
971
  'um/adlQuantile': 5,
972
972
  'cm/adlQuantile': 5,
973
973
  },
@@ -986,8 +986,8 @@ class binance extends binance$1 {
986
986
  'cm/positionSide/dual': 1,
987
987
  'auto-collection': 0.6667,
988
988
  'bnb-transfer': 0.6667,
989
- 'portfolio/repay-futures-switch': 150,
990
- 'portfolio/repay-futures-negative-balance': 150,
989
+ 'repay-futures-switch': 150,
990
+ 'repay-futures-negative-balance': 150,
991
991
  'listenKey': 1,
992
992
  'asset-collection': 3,
993
993
  },