ccxt 4.2.35 → 4.2.37

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/js/src/bithumb.js CHANGED
@@ -191,6 +191,7 @@ export default class bithumb extends Exchange {
191
191
  * @method
192
192
  * @name bithumb#fetchMarkets
193
193
  * @description retrieves data on all markets for bithumb
194
+ * @see https://apidocs.bithumb.com/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C-all
194
195
  * @param {object} [params] extra parameters specific to the exchange API endpoint
195
196
  * @returns {object[]} an array of objects representing market data
196
197
  */
@@ -293,6 +294,7 @@ export default class bithumb extends Exchange {
293
294
  * @method
294
295
  * @name bithumb#fetchBalance
295
296
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
297
+ * @see https://apidocs.bithumb.com/reference/%EB%B3%B4%EC%9C%A0%EC%9E%90%EC%82%B0-%EC%A1%B0%ED%9A%8C
296
298
  * @param {object} [params] extra parameters specific to the exchange API endpoint
297
299
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
298
300
  */
@@ -308,6 +310,7 @@ export default class bithumb extends Exchange {
308
310
  * @method
309
311
  * @name bithumb#fetchOrderBook
310
312
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
313
+ * @see https://apidocs.bithumb.com/reference/%ED%98%B8%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C
311
314
  * @param {string} symbol unified symbol of the market to fetch the order book for
312
315
  * @param {int} [limit] the maximum amount of order book entries to return
313
316
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -400,6 +403,7 @@ export default class bithumb extends Exchange {
400
403
  * @method
401
404
  * @name bithumb#fetchTickers
402
405
  * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
406
+ * @see https://apidocs.bithumb.com/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C-all
403
407
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
404
408
  * @param {object} [params] extra parameters specific to the exchange API endpoint
405
409
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -457,6 +461,7 @@ export default class bithumb extends Exchange {
457
461
  * @method
458
462
  * @name bithumb#fetchTicker
459
463
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
464
+ * @see https://apidocs.bithumb.com/reference/%ED%98%84%EC%9E%AC%EA%B0%80-%EC%A0%95%EB%B3%B4-%EC%A1%B0%ED%9A%8C
460
465
  * @param {string} symbol unified symbol of the market to fetch the ticker for
461
466
  * @param {object} [params] extra parameters specific to the exchange API endpoint
462
467
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -515,6 +520,7 @@ export default class bithumb extends Exchange {
515
520
  * @method
516
521
  * @name bithumb#fetchOHLCV
517
522
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
523
+ * @see https://apidocs.bithumb.com/reference/candlestick-rest-api
518
524
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
519
525
  * @param {string} timeframe the length of time each candle represents
520
526
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -639,6 +645,7 @@ export default class bithumb extends Exchange {
639
645
  * @method
640
646
  * @name bithumb#fetchTrades
641
647
  * @description get the list of most recent trades for a particular symbol
648
+ * @see https://apidocs.bithumb.com/reference/%EC%B5%9C%EA%B7%BC-%EC%B2%B4%EA%B2%B0-%EB%82%B4%EC%97%AD
642
649
  * @param {string} symbol unified symbol of the market to fetch trades for
643
650
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
644
651
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -677,6 +684,9 @@ export default class bithumb extends Exchange {
677
684
  * @method
678
685
  * @name bithumb#createOrder
679
686
  * @description create a trade order
687
+ * @see https://apidocs.bithumb.com/reference/%EC%A7%80%EC%A0%95%EA%B0%80-%EC%A3%BC%EB%AC%B8%ED%95%98%EA%B8%B0
688
+ * @see https://apidocs.bithumb.com/reference/%EC%8B%9C%EC%9E%A5%EA%B0%80-%EB%A7%A4%EC%88%98%ED%95%98%EA%B8%B0
689
+ * @see https://apidocs.bithumb.com/reference/%EC%8B%9C%EC%9E%A5%EA%B0%80-%EB%A7%A4%EB%8F%84%ED%95%98%EA%B8%B0
680
690
  * @param {string} symbol unified symbol of the market to create an order in
681
691
  * @param {string} type 'market' or 'limit'
682
692
  * @param {string} side 'buy' or 'sell'
@@ -718,6 +728,7 @@ export default class bithumb extends Exchange {
718
728
  * @method
719
729
  * @name bithumb#fetchOrder
720
730
  * @description fetches information on an order made by the user
731
+ * @see https://apidocs.bithumb.com/reference/%EA%B1%B0%EB%9E%98-%EC%A3%BC%EB%AC%B8%EB%82%B4%EC%97%AD-%EC%83%81%EC%84%B8-%EC%A1%B0%ED%9A%8C
721
732
  * @param {string} symbol unified symbol of the market the order was made in
722
733
  * @param {object} [params] extra parameters specific to the exchange API endpoint
723
734
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -876,6 +887,7 @@ export default class bithumb extends Exchange {
876
887
  * @method
877
888
  * @name bithumb#fetchOpenOrders
878
889
  * @description fetch all unfilled currently open orders
890
+ * @see https://apidocs.bithumb.com/reference/%EA%B1%B0%EB%9E%98-%EC%A3%BC%EB%AC%B8%EB%82%B4%EC%97%AD-%EC%A1%B0%ED%9A%8C
879
891
  * @param {string} symbol unified market symbol
880
892
  * @param {int} [since] the earliest time in ms to fetch open orders for
881
893
  * @param {int} [limit] the maximum number of open order structures to retrieve
@@ -924,6 +936,7 @@ export default class bithumb extends Exchange {
924
936
  * @method
925
937
  * @name bithumb#cancelOrder
926
938
  * @description cancels an open order
939
+ * @see https://apidocs.bithumb.com/reference/%EC%A3%BC%EB%AC%B8-%EC%B7%A8%EC%86%8C%ED%95%98%EA%B8%B0
927
940
  * @param {string} id order id
928
941
  * @param {string} symbol unified symbol of the market the order was made in
929
942
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -959,6 +972,7 @@ export default class bithumb extends Exchange {
959
972
  * @method
960
973
  * @name bithumb#withdraw
961
974
  * @description make a withdrawal
975
+ * @see https://apidocs.bithumb.com/reference/%EC%BD%94%EC%9D%B8-%EC%B6%9C%EA%B8%88%ED%95%98%EA%B8%B0-%EA%B0%9C%EC%9D%B8
962
976
  * @param {string} code unified currency code
963
977
  * @param {float} amount the amount to withdraw
964
978
  * @param {string} address the address to withdraw to
package/js/src/bitmex.js CHANGED
@@ -285,6 +285,7 @@ export default class bitmex extends Exchange {
285
285
  * @method
286
286
  * @name bitmex#fetchCurrencies
287
287
  * @description fetches all available currencies on an exchange
288
+ * @see https://www.bitmex.com/api/explorer/#!/Wallet/Wallet_getAssetsConfig
288
289
  * @param {object} [params] extra parameters specific to the exchange API endpoint
289
290
  * @returns {object} an associative dictionary of currencies
290
291
  */
@@ -770,6 +771,7 @@ export default class bitmex extends Exchange {
770
771
  * @method
771
772
  * @name bitmex#fetchBalance
772
773
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
774
+ * @see https://www.bitmex.com/api/explorer/#!/User/User_getMargin
773
775
  * @param {object} [params] extra parameters specific to the exchange API endpoint
774
776
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
775
777
  */
@@ -832,6 +834,7 @@ export default class bitmex extends Exchange {
832
834
  * @method
833
835
  * @name bitmex#fetchOrderBook
834
836
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
837
+ * @see https://www.bitmex.com/api/explorer/#!/OrderBook/OrderBook_getL2
835
838
  * @param {string} symbol unified symbol of the market to fetch the order book for
836
839
  * @param {int} [limit] the maximum amount of order book entries to return
837
840
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -875,6 +878,7 @@ export default class bitmex extends Exchange {
875
878
  * @method
876
879
  * @name bitmex#fetchOrder
877
880
  * @description fetches information on an order made by the user
881
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_getOrders
878
882
  * @param {string} symbol unified symbol of the market the order was made in
879
883
  * @param {object} [params] extra parameters specific to the exchange API endpoint
880
884
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -943,6 +947,7 @@ export default class bitmex extends Exchange {
943
947
  * @method
944
948
  * @name bitmex#fetchOpenOrders
945
949
  * @description fetch all unfilled currently open orders
950
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_getOrders
946
951
  * @param {string} symbol unified market symbol
947
952
  * @param {int} [since] the earliest time in ms to fetch open orders for
948
953
  * @param {int} [limit] the maximum number of open orders structures to retrieve
@@ -961,6 +966,7 @@ export default class bitmex extends Exchange {
961
966
  * @method
962
967
  * @name bitmex#fetchClosedOrders
963
968
  * @description fetches information on multiple closed orders made by the user
969
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_getOrders
964
970
  * @param {string} symbol unified market symbol of the market orders were made in
965
971
  * @param {int} [since] the earliest time in ms to fetch orders for
966
972
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -975,8 +981,8 @@ export default class bitmex extends Exchange {
975
981
  /**
976
982
  * @method
977
983
  * @name bitmex#fetchMyTrades
978
- * @see https://www.bitmex.com/api/explorer/#!/Execution/Execution_getTradeHistory
979
984
  * @description fetch all trades made by the user
985
+ * @see https://www.bitmex.com/api/explorer/#!/Execution/Execution_getTradeHistory
980
986
  * @param {string} symbol unified market symbol
981
987
  * @param {int} [since] the earliest time in ms to fetch trades for
982
988
  * @param {int} [limit] the maximum number of trades structures to retrieve
@@ -1185,6 +1191,7 @@ export default class bitmex extends Exchange {
1185
1191
  * @method
1186
1192
  * @name bitmex#fetchLedger
1187
1193
  * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
1194
+ * @see https://www.bitmex.com/api/explorer/#!/User/User_getWalletHistory
1188
1195
  * @param {string} code unified currency code, default is undefined
1189
1196
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1190
1197
  * @param {int} [limit] max number of ledger entrys to return, default is undefined
@@ -1236,6 +1243,7 @@ export default class bitmex extends Exchange {
1236
1243
  * @method
1237
1244
  * @name bitmex#fetchDepositsWithdrawals
1238
1245
  * @description fetch history of deposits and withdrawals
1246
+ * @see https://www.bitmex.com/api/explorer/#!/User/User_getWalletHistory
1239
1247
  * @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
1240
1248
  * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
1241
1249
  * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
@@ -1354,6 +1362,7 @@ export default class bitmex extends Exchange {
1354
1362
  * @method
1355
1363
  * @name bitmex#fetchTicker
1356
1364
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1365
+ * @see https://www.bitmex.com/api/explorer/#!/Instrument/Instrument_get
1357
1366
  * @param {string} symbol unified symbol of the market to fetch the ticker for
1358
1367
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1359
1368
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -1375,6 +1384,7 @@ export default class bitmex extends Exchange {
1375
1384
  * @method
1376
1385
  * @name bitmex#fetchTickers
1377
1386
  * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1387
+ * @see https://www.bitmex.com/api/explorer/#!/Instrument/Instrument_getActiveAndIndices
1378
1388
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1379
1389
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1380
1390
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -1457,8 +1467,8 @@ export default class bitmex extends Exchange {
1457
1467
  /**
1458
1468
  * @method
1459
1469
  * @name bitmex#fetchOHLCV
1460
- * @see https://www.bitmex.com/api/explorer/#!/Trade/Trade_getBucketed
1461
1470
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1471
+ * @see https://www.bitmex.com/api/explorer/#!/Trade/Trade_getBucketed
1462
1472
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1463
1473
  * @param {string} timeframe the length of time each candle represents
1464
1474
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -1773,8 +1783,8 @@ export default class bitmex extends Exchange {
1773
1783
  /**
1774
1784
  * @method
1775
1785
  * @name bitmex#fetchTrades
1776
- * @see https://www.bitmex.com/api/explorer/#!/Trade/Trade_get
1777
1786
  * @description get the list of most recent trades for a particular symbol
1787
+ * @see https://www.bitmex.com/api/explorer/#!/Trade/Trade_get
1778
1788
  * @param {string} symbol unified symbol of the market to fetch trades for
1779
1789
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
1780
1790
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -1995,6 +2005,7 @@ export default class bitmex extends Exchange {
1995
2005
  * @method
1996
2006
  * @name bitmex#cancelOrder
1997
2007
  * @description cancels an open order
2008
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_cancel
1998
2009
  * @param {string} id order id
1999
2010
  * @param {string} symbol not used by bitmex cancelOrder ()
2000
2011
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2026,6 +2037,7 @@ export default class bitmex extends Exchange {
2026
2037
  * @method
2027
2038
  * @name bitmex#cancelOrders
2028
2039
  * @description cancel multiple orders
2040
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_cancel
2029
2041
  * @param {string[]} ids order ids
2030
2042
  * @param {string} symbol not used by bitmex cancelOrders ()
2031
2043
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2051,6 +2063,7 @@ export default class bitmex extends Exchange {
2051
2063
  * @method
2052
2064
  * @name bitmex#cancelAllOrders
2053
2065
  * @description cancel all open orders
2066
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_cancelAll
2054
2067
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
2055
2068
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2056
2069
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -2109,6 +2122,7 @@ export default class bitmex extends Exchange {
2109
2122
  * @method
2110
2123
  * @name bitmex#fetchPositions
2111
2124
  * @description fetch all open positions
2125
+ * @see https://www.bitmex.com/api/explorer/#!/Position/Position_get
2112
2126
  * @param {string[]|undefined} symbols list of unified market symbols
2113
2127
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2114
2128
  * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
@@ -2367,6 +2381,7 @@ export default class bitmex extends Exchange {
2367
2381
  * @method
2368
2382
  * @name bitmex#withdraw
2369
2383
  * @description make a withdrawal
2384
+ * @see https://www.bitmex.com/api/explorer/#!/User/User_requestWithdrawal
2370
2385
  * @param {string} code unified currency code
2371
2386
  * @param {float} amount the amount to withdraw
2372
2387
  * @param {string} address the address to withdraw to
@@ -2414,6 +2429,7 @@ export default class bitmex extends Exchange {
2414
2429
  * @method
2415
2430
  * @name bitmex#fetchFundingRates
2416
2431
  * @description fetch the funding rate for multiple markets
2432
+ * @see https://www.bitmex.com/api/explorer/#!/Instrument/Instrument_getActiveAndIndices
2417
2433
  * @param {string[]|undefined} symbols list of unified market symbols
2418
2434
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2419
2435
  * @returns {object} a dictionary of [funding rates structures]{@link https://docs.ccxt.com/#/?id=funding-rates-structure}, indexe by market symbols
@@ -2465,6 +2481,7 @@ export default class bitmex extends Exchange {
2465
2481
  * @method
2466
2482
  * @name bitmex#fetchFundingRateHistory
2467
2483
  * @description Fetches the history of funding rates
2484
+ * @see https://www.bitmex.com/api/explorer/#!/Funding/Funding_get
2468
2485
  * @param {string} symbol unified symbol of the market to fetch the funding rate history for
2469
2486
  * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
2470
2487
  * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
@@ -2548,6 +2565,7 @@ export default class bitmex extends Exchange {
2548
2565
  * @method
2549
2566
  * @name bitmex#setLeverage
2550
2567
  * @description set the level of leverage for a market
2568
+ * @see https://www.bitmex.com/api/explorer/#!/Position/Position_updateLeverage
2551
2569
  * @param {float} leverage the rate of leverage
2552
2570
  * @param {string} symbol unified market symbol
2553
2571
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2575,6 +2593,7 @@ export default class bitmex extends Exchange {
2575
2593
  * @method
2576
2594
  * @name bitmex#setMarginMode
2577
2595
  * @description set margin mode to 'cross' or 'isolated'
2596
+ * @see https://www.bitmex.com/api/explorer/#!/Position/Position_isolateMargin
2578
2597
  * @param {string} marginMode 'cross' or 'isolated'
2579
2598
  * @param {string} symbol unified market symbol
2580
2599
  * @param {object} [params] extra parameters specific to the exchange API endpoint
package/js/src/bybit.js CHANGED
@@ -3741,10 +3741,22 @@ export default class bybit extends Exchange {
3741
3741
  if (isStopLoss) {
3742
3742
  const slTriggerPrice = this.safeValue2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss);
3743
3743
  request['stopLoss'] = this.priceToPrecision(symbol, slTriggerPrice);
3744
+ const slLimitPrice = this.safeValue(stopLoss, 'price');
3745
+ if (slLimitPrice !== undefined) {
3746
+ request['tpslMode'] = 'Partial';
3747
+ request['slOrderType'] = 'Limit';
3748
+ request['slLimitPrice'] = this.priceToPrecision(symbol, slLimitPrice);
3749
+ }
3744
3750
  }
3745
3751
  if (isTakeProfit) {
3746
3752
  const tpTriggerPrice = this.safeValue2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit);
3747
3753
  request['takeProfit'] = this.priceToPrecision(symbol, tpTriggerPrice);
3754
+ const tpLimitPrice = this.safeValue(takeProfit, 'price');
3755
+ if (tpLimitPrice !== undefined) {
3756
+ request['tpslMode'] = 'Partial';
3757
+ request['tpOrderType'] = 'Limit';
3758
+ request['tpLimitPrice'] = this.priceToPrecision(symbol, tpLimitPrice);
3759
+ }
3748
3760
  }
3749
3761
  }
3750
3762
  if (market['spot']) {
@@ -6026,9 +6038,6 @@ export default class bybit extends Exchange {
6026
6038
  if (timestamp === undefined) {
6027
6039
  timestamp = this.safeIntegerN(position, ['updatedTime', 'updatedAt']);
6028
6040
  }
6029
- // default to cross of USDC margined positions
6030
- const tradeMode = this.safeInteger(position, 'tradeMode', 0);
6031
- const marginMode = tradeMode ? 'isolated' : 'cross';
6032
6041
  let collateralString = this.safeString(position, 'positionBalance');
6033
6042
  const entryPrice = this.omitZero(this.safeString2(position, 'entryPrice', 'avgPrice'));
6034
6043
  const liquidationPrice = this.omitZero(this.safeString(position, 'liqPrice'));
@@ -6092,7 +6101,7 @@ export default class bybit extends Exchange {
6092
6101
  'markPrice': this.safeNumber(position, 'markPrice'),
6093
6102
  'lastPrice': undefined,
6094
6103
  'collateral': this.parseNumber(collateralString),
6095
- 'marginMode': marginMode,
6104
+ 'marginMode': undefined,
6096
6105
  'side': side,
6097
6106
  'percentage': undefined,
6098
6107
  'stopLossPrice': this.safeNumber2(position, 'stop_loss', 'stopLoss'),
@@ -54,8 +54,8 @@ export default class binance extends binanceRest {
54
54
  },
55
55
  'api': {
56
56
  'ws': {
57
- 'spot': 'wss://stream.binance.com/ws',
58
- 'margin': 'wss://stream.binance.com/ws',
57
+ 'spot': 'wss://stream.binance.com:9443/ws',
58
+ 'margin': 'wss://stream.binance.com:9443/ws',
59
59
  'future': 'wss://fstream.binance.com/ws',
60
60
  'delivery': 'wss://dstream.binance.com/ws',
61
61
  'ws': 'wss://ws-api.binance.com:443/ws-api/v3',
@@ -4,13 +4,18 @@ import Client from '../base/ws/Client.js';
4
4
  export default class gemini extends geminiRest {
5
5
  describe(): any;
6
6
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
7
+ watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
7
8
  parseWsTrade(trade: any, market?: any): Trade;
8
9
  handleTrade(client: Client, message: any): void;
9
10
  handleTrades(client: Client, message: any): void;
11
+ handleTradesForMultidata(client: Client, trades: any, timestamp: Int): void;
10
12
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
11
13
  handleOHLCV(client: Client, message: any): any;
12
14
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
13
15
  handleOrderBook(client: Client, message: any): void;
16
+ watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
17
+ helperForWatchMultipleConstruct(itemHashName: string, symbols: string[], params?: {}): Promise<any>;
18
+ handleOrderBookForMultidata(client: Client, rawOrderBookChanges: any, timestamp: Int, nonce: Int): void;
14
19
  handleL2Updates(client: Client, message: any): void;
15
20
  watchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
16
21
  handleHeartbeat(client: Client, message: any): any;
@@ -7,7 +7,7 @@
7
7
  // ---------------------------------------------------------------------------
8
8
  import geminiRest from '../gemini.js';
9
9
  import { ArrayCache, ArrayCacheBySymbolById, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
10
- import { ExchangeError } from '../base/errors.js';
10
+ import { ExchangeError, NotSupported } from '../base/errors.js';
11
11
  import { sha384 } from '../static_dependencies/noble-hashes/sha512.js';
12
12
  // ---------------------------------------------------------------------------
13
13
  export default class gemini extends geminiRest {
@@ -19,9 +19,11 @@ export default class gemini extends geminiRest {
19
19
  'watchTicker': false,
20
20
  'watchTickers': false,
21
21
  'watchTrades': true,
22
+ 'watchTradesForSymbols': true,
22
23
  'watchMyTrades': false,
23
24
  'watchOrders': true,
24
25
  'watchOrderBook': true,
26
+ 'watchOrderBookForSymbols': true,
25
27
  'watchOHLCV': true,
26
28
  },
27
29
  'hostname': 'api.gemini.com',
@@ -70,7 +72,29 @@ export default class gemini extends geminiRest {
70
72
  }
71
73
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
72
74
  }
75
+ async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
76
+ /**
77
+ * @method
78
+ * @name gemini#watchTradesForSymbols
79
+ * @see https://docs.gemini.com/websocket-api/#multi-market-data
80
+ * @description get the list of most recent trades for a list of symbols
81
+ * @param {string[]} symbols unified symbol of the market to fetch trades for
82
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
83
+ * @param {int} [limit] the maximum amount of trades to fetch
84
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
85
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
86
+ */
87
+ const trades = await this.helperForWatchMultipleConstruct('trades', symbols, params);
88
+ if (this.newUpdates) {
89
+ const first = this.safeList(trades, 0);
90
+ const tradeSymbol = this.safeString(first, 'symbol');
91
+ limit = trades.getLimit(tradeSymbol, limit);
92
+ }
93
+ return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
94
+ }
73
95
  parseWsTrade(trade, market = undefined) {
96
+ //
97
+ // regular v2 trade
74
98
  //
75
99
  // {
76
100
  // "type": "trade",
@@ -82,11 +106,31 @@ export default class gemini extends geminiRest {
82
106
  // "side": "buy"
83
107
  // }
84
108
  //
109
+ // multi data trade
110
+ //
111
+ // {
112
+ // "type": "trade",
113
+ // "symbol": "ETHUSD",
114
+ // "tid": "1683002242170204", // this is not TS, but somewhat ID
115
+ // "price": "2299.24",
116
+ // "amount": "0.002662",
117
+ // "makerSide": "bid"
118
+ // }
119
+ //
85
120
  const timestamp = this.safeInteger(trade, 'timestamp');
86
- const id = this.safeString(trade, 'event_id');
121
+ const id = this.safeString2(trade, 'event_id', 'tid');
87
122
  const priceString = this.safeString(trade, 'price');
88
- const amountString = this.safeString(trade, 'quantity');
89
- const side = this.safeStringLower(trade, 'side');
123
+ const amountString = this.safeString2(trade, 'quantity', 'amount');
124
+ let side = this.safeStringLower(trade, 'side');
125
+ if (side === undefined) {
126
+ const marketSide = this.safeStringLower(trade, 'makerSide');
127
+ if (marketSide === 'bid') {
128
+ side = 'sell';
129
+ }
130
+ else if (marketSide === 'ask') {
131
+ side = 'buy';
132
+ }
133
+ }
90
134
  const marketId = this.safeStringLower(trade, 'symbol');
91
135
  const symbol = this.safeSymbol(marketId, market);
92
136
  return this.safeTrade({
@@ -186,6 +230,34 @@ export default class gemini extends geminiRest {
186
230
  client.resolve(stored, messageHash);
187
231
  }
188
232
  }
233
+ handleTradesForMultidata(client, trades, timestamp) {
234
+ if (trades !== undefined) {
235
+ const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
236
+ const storesForSymbols = {};
237
+ for (let i = 0; i < trades.length; i++) {
238
+ const marketId = trades[i]['symbol'];
239
+ const market = this.safeMarket(marketId.toLowerCase());
240
+ const symbol = market['symbol'];
241
+ const trade = this.parseWsTrade(trades[i], market);
242
+ trade['timestamp'] = timestamp;
243
+ trade['datetime'] = this.iso8601(timestamp);
244
+ let stored = this.safeValue(this.trades, symbol);
245
+ if (stored === undefined) {
246
+ stored = new ArrayCache(tradesLimit);
247
+ this.trades[symbol] = stored;
248
+ }
249
+ stored.append(trade);
250
+ storesForSymbols[symbol] = stored;
251
+ }
252
+ const symbols = Object.keys(storesForSymbols);
253
+ for (let i = 0; i < symbols.length; i++) {
254
+ const symbol = symbols[i];
255
+ const stored = storesForSymbols[symbol];
256
+ const messageHash = 'trades:' + symbol;
257
+ client.resolve(stored, messageHash);
258
+ }
259
+ }
260
+ }
189
261
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
190
262
  /**
191
263
  * @method
@@ -331,6 +403,93 @@ export default class gemini extends geminiRest {
331
403
  this.orderbooks[symbol] = orderbook;
332
404
  client.resolve(orderbook, messageHash);
333
405
  }
406
+ async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
407
+ /**
408
+ * @method
409
+ * @name gemini#watchOrderBookForSymbols
410
+ * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
411
+ * @see https://docs.gemini.com/websocket-api/#multi-market-data
412
+ * @param {string[]} symbols unified array of symbols
413
+ * @param {int} [limit] the maximum amount of order book entries to return
414
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
415
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
416
+ */
417
+ const orderbook = await this.helperForWatchMultipleConstruct('orderbook', symbols, params);
418
+ return orderbook.limit();
419
+ }
420
+ async helperForWatchMultipleConstruct(itemHashName, symbols, params = {}) {
421
+ await this.loadMarkets();
422
+ symbols = this.marketSymbols(symbols, undefined, false, true, true);
423
+ const firstMarket = this.market(symbols[0]);
424
+ if (!firstMarket['spot'] && !firstMarket['linear']) {
425
+ throw new NotSupported(this.id + ' watchMultiple supports only spot or linear-swap symbols');
426
+ }
427
+ const messageHashes = [];
428
+ const marketIds = [];
429
+ for (let i = 0; i < symbols.length; i++) {
430
+ const symbol = symbols[i];
431
+ const messageHash = itemHashName + ':' + symbol;
432
+ messageHashes.push(messageHash);
433
+ const market = this.market(symbol);
434
+ marketIds.push(market['id']);
435
+ }
436
+ const queryStr = marketIds.join(',');
437
+ let url = this.urls['api']['ws'] + '/v1/multimarketdata?symbols=' + queryStr + '&heartbeat=true&';
438
+ if (itemHashName === 'orderbook') {
439
+ url += 'trades=false&bids=true&offers=true';
440
+ }
441
+ else if (itemHashName === 'trades') {
442
+ url += 'trades=true&bids=false&offers=false';
443
+ }
444
+ return await this.watchMultiple(url, messageHashes, undefined);
445
+ }
446
+ handleOrderBookForMultidata(client, rawOrderBookChanges, timestamp, nonce) {
447
+ //
448
+ // rawOrderBookChanges
449
+ //
450
+ // [
451
+ // {
452
+ // delta: "4105123935484.817624",
453
+ // price: "0.000000001",
454
+ // reason: "initial", // initial|cancel|place
455
+ // remaining: "4105123935484.817624",
456
+ // side: "bid", // bid|ask
457
+ // symbol: "SHIBUSD",
458
+ // type: "change", // seems always change
459
+ // },
460
+ // ...
461
+ //
462
+ const marketId = rawOrderBookChanges[0]['symbol'];
463
+ const market = this.safeMarket(marketId.toLowerCase());
464
+ const symbol = market['symbol'];
465
+ const messageHash = 'orderbook:' + symbol;
466
+ let orderbook = this.safeDict(this.orderbooks, symbol);
467
+ if (orderbook === undefined) {
468
+ orderbook = this.orderBook();
469
+ }
470
+ const bids = orderbook['bids'];
471
+ const asks = orderbook['asks'];
472
+ for (let i = 0; i < rawOrderBookChanges.length; i++) {
473
+ const entry = rawOrderBookChanges[i];
474
+ const price = this.safeNumber(entry, 'price');
475
+ const size = this.safeNumber(entry, 'remaining');
476
+ const rawSide = this.safeString(entry, 'side');
477
+ if (rawSide === 'bid') {
478
+ bids.store(price, size);
479
+ }
480
+ else {
481
+ asks.store(price, size);
482
+ }
483
+ }
484
+ orderbook['bids'] = bids;
485
+ orderbook['asks'] = asks;
486
+ orderbook['symbol'] = symbol;
487
+ orderbook['nonce'] = nonce;
488
+ orderbook['timestamp'] = timestamp;
489
+ orderbook['datetime'] = this.iso8601(timestamp);
490
+ this.orderbooks[symbol] = orderbook;
491
+ client.resolve(orderbook, messageHash);
492
+ }
334
493
  handleL2Updates(client, message) {
335
494
  //
336
495
  // {
@@ -411,6 +570,7 @@ export default class gemini extends geminiRest {
411
570
  // "socket_sequence": 7
412
571
  // }
413
572
  //
573
+ client.lastPong = this.milliseconds();
414
574
  return message;
415
575
  }
416
576
  handleSubscription(client, message) {
@@ -613,6 +773,33 @@ export default class gemini extends geminiRest {
613
773
  if (method !== undefined) {
614
774
  method.call(this, client, message);
615
775
  }
776
+ // handle multimarketdata
777
+ if (type === 'update') {
778
+ const ts = this.safeInteger(message, 'timestampms', this.milliseconds());
779
+ const eventId = this.safeInteger(message, 'eventId');
780
+ const events = this.safeList(message, 'events');
781
+ const orderBookItems = [];
782
+ const collectedEventsOfTrades = [];
783
+ for (let i = 0; i < events.length; i++) {
784
+ const event = events[i];
785
+ const eventType = this.safeString(event, 'type');
786
+ const isOrderBook = (eventType === 'change') && ('side' in event) && this.inArray(event['side'], ['ask', 'bid']);
787
+ if (isOrderBook) {
788
+ orderBookItems.push(event);
789
+ }
790
+ else if (eventType === 'trade') {
791
+ collectedEventsOfTrades.push(events[i]);
792
+ }
793
+ }
794
+ const lengthOb = orderBookItems.length;
795
+ if (lengthOb > 0) {
796
+ this.handleOrderBookForMultidata(client, orderBookItems, ts, eventId);
797
+ }
798
+ const lengthTrades = collectedEventsOfTrades.length;
799
+ if (lengthTrades > 0) {
800
+ this.handleTradesForMultidata(client, collectedEventsOfTrades, ts);
801
+ }
802
+ }
616
803
  }
617
804
  async authenticate(params = {}) {
618
805
  const url = this.safeString(params, 'url');