ccxt 4.1.60 → 4.1.62

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.60';
176
+ const version = '4.1.62';
177
177
  Exchange["default"].ccxtVersion = version;
178
178
  const exchanges = {
179
179
  'ace': ace,
@@ -26,16 +26,14 @@ class alpaca extends alpaca$1 {
26
26
  'logo': 'https://user-images.githubusercontent.com/1294454/187234005-b864db3d-f1e3-447a-aaf9-a9fc7b955d07.jpg',
27
27
  'www': 'https://alpaca.markets',
28
28
  'api': {
29
- 'public': 'https://api.{hostname}/{version}',
30
- 'private': 'https://api.{hostname}/{version}',
31
- 'cryptoPublic': 'https://data.{hostname}/{version}',
32
- 'markets': 'https://api.{hostname}/{version}',
29
+ 'broker': 'https://broker-api.{hostname}',
30
+ 'trader': 'https://api.{hostname}',
31
+ 'market': 'https://data.{hostname}',
33
32
  },
34
33
  'test': {
35
- 'public': 'https://paper-api.{hostname}/{version}',
36
- 'private': 'https://paper-api.{hostname}/{version}',
37
- 'cryptoPublic': 'https://data.{hostname}/{version}',
38
- 'markets': 'https://api.{hostname}/{version}',
34
+ 'broker': 'https://broker-api.sandbox.{hostname}',
35
+ 'trader': 'https://paper-api.{hostname}',
36
+ 'market': 'https://data.sandbox.{hostname}',
39
37
  },
40
38
  'doc': 'https://alpaca.markets/docs/',
41
39
  'fees': 'https://alpaca.markets/support/what-are-the-fees-associated-with-crypto-trading/',
@@ -89,37 +87,96 @@ class alpaca extends alpaca$1 {
89
87
  'withdraw': false,
90
88
  },
91
89
  'api': {
92
- 'markets': {
93
- 'get': [
94
- 'assets/public/beta',
95
- ],
96
- },
97
- 'private': {
98
- 'get': [
99
- 'account',
100
- 'orders',
101
- 'orders/{order_id}',
102
- 'positions',
103
- 'positions/{symbol}',
104
- 'account/activities/{activity_type}',
105
- ],
106
- 'post': [
107
- 'orders',
108
- ],
109
- 'delete': [
110
- 'orders',
111
- 'orders/{order_id}',
112
- ],
90
+ 'broker': {},
91
+ 'trader': {
92
+ 'private': {
93
+ 'get': [
94
+ 'v2/account',
95
+ 'v2/orders',
96
+ 'v2/orders/{order_id}',
97
+ 'v2/positions',
98
+ 'v2/positions/{symbol_or_asset_id}',
99
+ 'v2/account/portfolio/history',
100
+ 'v2/watchlists',
101
+ 'v2/watchlists/{watchlist_id}',
102
+ 'v2/watchlists:by_name',
103
+ 'v2/account/configurations',
104
+ 'v2/account/activities',
105
+ 'v2/account/activities/{activity_type}',
106
+ 'v2/calendar',
107
+ 'v2/clock',
108
+ 'v2/assets',
109
+ 'v2/assets/{symbol_or_asset_id}',
110
+ 'v2/corporate_actions/announcements/{id}',
111
+ 'v2/corporate_actions/announcements',
112
+ ],
113
+ 'post': [
114
+ 'v2/orders',
115
+ 'v2/watchlists',
116
+ 'v2/watchlists/{watchlist_id}',
117
+ 'v2/watchlists:by_name',
118
+ ],
119
+ 'put': [
120
+ 'v2/watchlists/{watchlist_id}',
121
+ 'v2/watchlists:by_name',
122
+ ],
123
+ 'patch': [
124
+ 'v2/orders/{order_id}',
125
+ 'v2/account/configurations',
126
+ ],
127
+ 'delete': [
128
+ 'v2/orders',
129
+ 'v2/orders/{order_id}',
130
+ 'v2/positions',
131
+ 'v2/positions/{symbol_or_asset_id}',
132
+ 'v2/watchlists/{watchlist_id}',
133
+ 'v2/watchlists:by_name',
134
+ 'v2/watchlists/{watchlist_id}/{symbol}',
135
+ ],
136
+ },
113
137
  },
114
- 'cryptoPublic': {
115
- 'get': [
116
- 'crypto/latest/orderbooks',
117
- 'crypto/trades',
118
- 'crypto/quotes',
119
- 'crypto/latest/quotes',
120
- 'crypto/bars',
121
- 'crypto/snapshots',
122
- ],
138
+ 'market': {
139
+ 'public': {
140
+ 'get': [
141
+ 'v1beta3/crypto/{loc}/bars',
142
+ 'v1beta3/crypto/{loc}/latest/bars',
143
+ 'v1beta3/crypto/{loc}/latest/orderbooks',
144
+ 'v1beta3/crypto/{loc}/latest/quotes',
145
+ 'v1beta3/crypto/{loc}/latest/trades',
146
+ 'v1beta3/crypto/{loc}/quotes',
147
+ 'v1beta3/crypto/{loc}/snapshots',
148
+ 'v1beta3/crypto/{loc}/trades',
149
+ ],
150
+ },
151
+ 'private': {
152
+ 'get': [
153
+ 'v1beta1/corporate-actions',
154
+ 'v1beta1/forex/latest/rates',
155
+ 'v1beta1/forex/rates',
156
+ 'v1beta1/logos/{symbol}',
157
+ 'v1beta1/news',
158
+ 'v1beta1/screener/stocks/most-actives',
159
+ 'v1beta1/screener/{market_type}/movers',
160
+ 'v2/stocks/auctions',
161
+ 'v2/stocks/bars',
162
+ 'v2/stocks/bars/latest',
163
+ 'v2/stocks/meta/conditions/{ticktype}',
164
+ 'v2/stocks/meta/exchanges',
165
+ 'v2/stocks/quotes',
166
+ 'v2/stocks/quotes/latest',
167
+ 'v2/stocks/snapshots',
168
+ 'v2/stocks/trades',
169
+ 'v2/stocks/trades/latest',
170
+ 'v2/stocks/{symbol}/auctions',
171
+ 'v2/stocks/{symbol}/bars',
172
+ 'v2/stocks/{symbol}/bars/latest',
173
+ 'v2/stocks/{symbol}/quotes',
174
+ 'v2/stocks/{symbol}/quotes/latest',
175
+ 'v2/stocks/{symbol}/snapshot',
176
+ 'v2/stocks/{symbol}/trades',
177
+ 'v2/stocks/{symbol}/trades/latest',
178
+ ],
179
+ },
123
180
  },
124
181
  },
125
182
  'timeframes': {
@@ -178,14 +235,6 @@ class alpaca extends alpaca$1 {
178
235
  'APCA-PARTNER-ID': 'ccxt',
179
236
  },
180
237
  'options': {
181
- 'fetchTradesMethod': 'cryptoPublicGetCryptoTrades',
182
- 'fetchOHLCVMethod': 'cryptoPublicGetCryptoBars',
183
- 'versions': {
184
- 'public': 'v2',
185
- 'private': 'v2',
186
- 'cryptoPublic': 'v1beta2',
187
- 'markets': 'v2', // crypto beta
188
- },
189
238
  'defaultExchange': 'CBSE',
190
239
  'exchanges': [
191
240
  'CBSE',
@@ -224,7 +273,7 @@ class alpaca extends alpaca$1 {
224
273
  'asset_class': 'crypto',
225
274
  'tradeable': true,
226
275
  };
227
- const assets = await this.marketsGetAssetsPublicBeta(this.extend(request, params));
276
+ const assets = await this.traderPrivateGetV2Assets(this.extend(request, params));
228
277
  //
229
278
  // [
230
279
  // {
@@ -315,26 +364,42 @@ class alpaca extends alpaca$1 {
315
364
  * @method
316
365
  * @name alpaca#fetchTrades
317
366
  * @description get the list of most recent trades for a particular symbol
367
+ * @see https://docs.alpaca.markets/reference/cryptotrades
368
+ * @see https://docs.alpaca.markets/reference/cryptolatesttrades
318
369
  * @param {string} symbol unified symbol of the market to fetch trades for
319
370
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
320
371
  * @param {int} [limit] the maximum amount of trades to fetch
321
372
  * @param {object} [params] extra parameters specific to the alpaca api endpoint
373
+ * @param {string} [params.loc] crypto location, default: us
374
+ * @param {string} [params.method] method, default: marketPublicGetV1beta3CryptoLocTrades
322
375
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
323
376
  */
324
377
  await this.loadMarkets();
325
378
  const market = this.market(symbol);
326
- const id = market['id'];
379
+ const marketId = market['id'];
380
+ const loc = this.safeString(params, 'loc', 'us');
381
+ const method = this.safeString(params, 'method', 'marketPublicGetV1beta3CryptoLocTrades');
327
382
  const request = {
328
- 'symbols': id,
383
+ 'symbols': marketId,
384
+ 'loc': loc,
329
385
  };
330
- if (since !== undefined) {
331
- request['start'] = this.iso8601(since);
386
+ params = this.omit(params, ['loc', 'method']);
387
+ let response = undefined;
388
+ if (method === 'marketPublicGetV1beta3CryptoLocTrades') {
389
+ if (since !== undefined) {
390
+ request['start'] = this.iso8601(since);
391
+ }
392
+ if (limit !== undefined) {
393
+ request['limit'] = limit;
394
+ }
395
+ response = await this.marketPublicGetV1beta3CryptoLocTrades(this.extend(request, params));
396
+ }
397
+ else if (method === 'marketPublicGetV1beta3CryptoLocLatestTrades') {
398
+ response = await this.marketPublicGetV1beta3CryptoLocLatestTrades(this.extend(request, params));
332
399
  }
333
- if (limit !== undefined) {
334
- request['limit'] = limit;
400
+ else {
401
+ throw new errors.NotSupported(this.id + ' fetchTrades() does not support ' + method + ', marketPublicGetV1beta3CryptoLocTrades and marketPublicGetV1beta3CryptoLocLatestTrades are supported');
335
402
  }
336
- const method = this.safeString(this.options, 'fetchTradesMethod', 'cryptoPublicGetCryptoTrades');
337
- const response = await this[method](this.extend(request, params));
338
403
  //
339
404
  // {
340
405
  // "next_page_token":null,
@@ -351,27 +416,50 @@ class alpaca extends alpaca$1 {
351
416
  // }
352
417
  // }
353
418
  //
419
+ // {
420
+ // "trades":{
421
+ // "BTC/USD":{
422
+ // "i":36440704,
423
+ // "p":22625,
424
+ // "s":0.0001,
425
+ // "t":"2022-07-21T11:47:31.073391Z",
426
+ // "tks":"B"
427
+ // }
428
+ // }
429
+ // }
430
+ //
354
431
  const trades = this.safeValue(response, 'trades', {});
355
- const symbolTrades = this.safeValue(trades, market['id'], {});
432
+ let symbolTrades = this.safeValue(trades, marketId, {});
433
+ if (!Array.isArray(symbolTrades)) {
434
+ symbolTrades = [symbolTrades];
435
+ }
356
436
  return this.parseTrades(symbolTrades, market, since, limit);
357
437
  }
358
438
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
359
- /**
360
- * @method
361
- * @name alpaca#fetchOrderBook
362
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
363
- * @param {string} symbol unified symbol of the market to fetch the order book for
364
- * @param {int} [limit] the maximum amount of order book entries to return
365
- * @param {object} [params] extra parameters specific to the alpaca api endpoint
366
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
367
- */
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
+ //
368
454
  await this.loadMarkets();
369
455
  const market = this.market(symbol);
370
456
  const id = market['id'];
457
+ const loc = this.safeString(params, 'loc', 'us');
371
458
  const request = {
372
459
  'symbols': id,
460
+ 'loc': loc,
373
461
  };
374
- const response = await this.cryptoPublicGetCryptoLatestOrderbooks(this.extend(request, params));
462
+ const response = await this.marketPublicGetV1beta3CryptoLocLatestOrderbooks(this.extend(request, params));
375
463
  //
376
464
  // {
377
465
  // "orderbooks":{
@@ -419,27 +507,44 @@ class alpaca extends alpaca$1 {
419
507
  * @method
420
508
  * @name alpaca#fetchOHLCV
421
509
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
510
+ * @see https://docs.alpaca.markets/reference/cryptobars
511
+ * @see https://docs.alpaca.markets/reference/cryptolatestbars
422
512
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
423
513
  * @param {string} timeframe the length of time each candle represents
424
514
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
425
515
  * @param {int} [limit] the maximum amount of candles to fetch
426
516
  * @param {object} [params] extra parameters specific to the alpha api endpoint
517
+ * @param {string} [params.loc] crypto location, default: us
518
+ * @param {string} [params.method] method, default: marketPublicGetV1beta3CryptoLocBars
427
519
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
428
520
  */
429
521
  await this.loadMarkets();
430
522
  const market = this.market(symbol);
523
+ const marketId = market['id'];
524
+ const loc = this.safeString(params, 'loc', 'us');
525
+ const method = this.safeString(params, 'method', 'marketPublicGetV1beta3CryptoLocBars');
431
526
  const request = {
432
- 'symbols': market['id'],
433
- 'timeframe': this.safeString(this.timeframes, timeframe, timeframe),
527
+ 'symbols': marketId,
528
+ 'loc': loc,
434
529
  };
435
- if (limit !== undefined) {
436
- request['limit'] = limit;
530
+ params = this.omit(params, ['loc', 'method']);
531
+ let response = undefined;
532
+ if (method === 'marketPublicGetV1beta3CryptoLocBars') {
533
+ if (limit !== undefined) {
534
+ request['limit'] = limit;
535
+ }
536
+ if (since !== undefined) {
537
+ request['start'] = this.yyyymmdd(since);
538
+ }
539
+ request['timeframe'] = this.safeString(this.timeframes, timeframe, timeframe);
540
+ response = await this.marketPublicGetV1beta3CryptoLocBars(this.extend(request, params));
541
+ }
542
+ else if (method === 'marketPublicGetV1beta3CryptoLocLatestBars') {
543
+ response = await this.marketPublicGetV1beta3CryptoLocLatestBars(this.extend(request, params));
437
544
  }
438
- if (since !== undefined) {
439
- request['start'] = this.yyyymmdd(since);
545
+ else {
546
+ throw new errors.NotSupported(this.id + ' fetchOHLCV() does not support ' + method + ', marketPublicGetV1beta3CryptoLocBars and marketPublicGetV1beta3CryptoLocLatestBars are supported');
440
547
  }
441
- const method = this.safeString(this.options, 'fetchOHLCVMethod', 'cryptoPublicGetCryptoBars');
442
- const response = await this[method](this.extend(request, params));
443
548
  //
444
549
  // {
445
550
  // "bars":{
@@ -469,8 +574,26 @@ class alpaca extends alpaca$1 {
469
574
  // "next_page_token":"QlRDL1VTRHxNfDIwMjItMDctMjFUMDU6MDE6MDAuMDAwMDAwMDAwWg=="
470
575
  // }
471
576
  //
577
+ // {
578
+ // "bars":{
579
+ // "BTC/USD":{
580
+ // "c":22887,
581
+ // "h":22888,
582
+ // "l":22873,
583
+ // "n":11,
584
+ // "o":22883,
585
+ // "t":"2022-07-21T05:00:00Z",
586
+ // "v":1.1138,
587
+ // "vw":22883.0155324116
588
+ // }
589
+ // }
590
+ // }
591
+ //
472
592
  const bars = this.safeValue(response, 'bars', {});
473
- const ohlcvs = this.safeValue(bars, market['id'], {});
593
+ let ohlcvs = this.safeValue(bars, marketId, {});
594
+ if (!Array.isArray(ohlcvs)) {
595
+ ohlcvs = [ohlcvs];
596
+ }
474
597
  return this.parseOHLCVs(ohlcvs, market, timeframe, since, limit);
475
598
  }
476
599
  parseOHLCV(ohlcv, market = undefined) {
@@ -546,7 +669,7 @@ class alpaca extends alpaca$1 {
546
669
  const clientOrderId = this.safeString(params, 'clientOrderId', defaultClientId);
547
670
  request['client_order_id'] = clientOrderId;
548
671
  params = this.omit(params, ['clientOrderId']);
549
- const order = await this.privatePostOrders(this.extend(request, params));
672
+ const order = await this.traderPrivatePostV2Orders(this.extend(request, params));
550
673
  //
551
674
  // {
552
675
  // "id": "61e69015-8549-4bfd-b9c3-01e75843f47d",
@@ -598,7 +721,7 @@ class alpaca extends alpaca$1 {
598
721
  const request = {
599
722
  'order_id': id,
600
723
  };
601
- const response = await this.privateDeleteOrdersOrderId(this.extend(request, params));
724
+ const response = await this.traderPrivateDeleteV2OrdersOrderId(this.extend(request, params));
602
725
  //
603
726
  // {
604
727
  // "code": 40410000,
@@ -620,7 +743,7 @@ class alpaca extends alpaca$1 {
620
743
  const request = {
621
744
  'order_id': id,
622
745
  };
623
- const order = await this.privateGetOrdersOrderId(this.extend(request, params));
746
+ const order = await this.traderPrivateGetV2OrdersOrderId(this.extend(request, params));
624
747
  const marketId = this.safeString(order, 'symbol');
625
748
  const market = this.safeMarket(marketId);
626
749
  return this.parseOrder(order, market);
@@ -641,7 +764,7 @@ class alpaca extends alpaca$1 {
641
764
  if (symbol !== undefined) {
642
765
  market = this.market(symbol);
643
766
  }
644
- const orders = await this.privateGetOrders(params);
767
+ const orders = await this.traderPrivateGetV2Orders(params);
645
768
  return this.parseOrders(orders, market, since, limit);
646
769
  }
647
770
  parseOrder(order, market = undefined) {
@@ -787,13 +910,10 @@ class alpaca extends alpaca$1 {
787
910
  }, market);
788
911
  }
789
912
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
790
- const versions = this.safeValue(this.options, 'versions');
791
- const version = this.safeString(versions, api);
792
913
  let endpoint = '/' + this.implodeParams(path, params);
793
- let url = this.implodeParams(this.urls['api'][api], { 'version': version });
794
- url = this.implodeHostname(url);
914
+ let url = this.implodeHostname(this.urls['api'][api[0]]);
795
915
  headers = (headers !== undefined) ? headers : {};
796
- if (api === 'private') {
916
+ if (api[1] === 'private') {
797
917
  headers['APCA-API-KEY-ID'] = this.apiKey;
798
918
  headers['APCA-API-SECRET-KEY'] = this.secret;
799
919
  }
@@ -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;
@@ -3026,7 +3030,7 @@ class Exchange {
3026
3030
  /**
3027
3031
  * @method
3028
3032
  * @name exchange#fetchPositionsForSymbol
3029
- * @description fetches all open positions for specific symbol, unlike fetchPositions (which is designed to work with multiple symbols) so this method might be preffered for ony-market purposes, because of less rate-limit consumption and speed
3033
+ * @description fetches all open positions for specific symbol, unlike fetchPositions (which is designed to work with multiple symbols) so this method might be preffered for one-market position, because of less rate-limit consumption and speed
3030
3034
  * @param {string} symbol unified market symbol
3031
3035
  * @param {object} params extra parameters specific to the endpoint
3032
3036
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure} with maximum 3 items - possible one position for "one-way" mode, and possible two positions (long & short) for "two-way" (a.k.a. hedge) mode
@@ -287,6 +287,7 @@ class binance extends binance$1 {
287
287
  // https://binance-docs.github.io/apidocs/spot/en/#withdraw-sapi
288
288
  'capital/config/getall': 1,
289
289
  'capital/deposit/address': 1,
290
+ 'capital/deposit/address/list': 1,
290
291
  'capital/deposit/hisrec': 0.1,
291
292
  'capital/deposit/subAddress': 0.1,
292
293
  'capital/deposit/subHisrec': 0.1,