ccxt 4.3.89__py2.py3-none-any.whl → 4.3.90__py2.py3-none-any.whl

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.
ccxt/okx.py CHANGED
@@ -1062,6 +1062,7 @@ class okx(Exchange, ImplicitAPI):
1062
1062
  'ZEC': 'Zcash',
1063
1063
  'ZIL': 'Zilliqa',
1064
1064
  'ZKSYNC': 'ZKSYNC',
1065
+ 'OMNI': 'Omni',
1065
1066
  # 'NEON3': 'N3', # tbd
1066
1067
  # undetermined : "CELO-TOKEN", "Digital Cash", Khala
1067
1068
  # todo: uncomment below after consensus
@@ -1588,14 +1589,6 @@ class okx(Exchange, ImplicitAPI):
1588
1589
  dataResponse = self.safe_list(response, 'data', [])
1589
1590
  return self.parse_markets(dataResponse)
1590
1591
 
1591
- def safe_network(self, networkId):
1592
- networksById: dict = {
1593
- 'Bitcoin': 'BTC',
1594
- 'Omni': 'OMNI',
1595
- 'TRON': 'TRC20',
1596
- }
1597
- return self.safe_string(networksById, networkId, networkId)
1598
-
1599
1592
  def fetch_currencies(self, params={}) -> Currencies:
1600
1593
  """
1601
1594
  fetches all available currencies on an exchange
ccxt/pro/__init__.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # ----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.3.89'
7
+ __version__ = '4.3.90'
8
8
 
9
9
  # ----------------------------------------------------------------------------
10
10
 
ccxt/pro/binance.py CHANGED
@@ -9,10 +9,12 @@ import hashlib
9
9
  from ccxt.base.types import Balances, Int, Liquidation, Num, Order, OrderBook, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade
10
10
  from ccxt.async_support.base.ws.client import Client
11
11
  from typing import List
12
+ from typing import Any
12
13
  from ccxt.base.errors import ArgumentsRequired
13
14
  from ccxt.base.errors import BadRequest
14
15
  from ccxt.base.errors import NotSupported
15
16
  from ccxt.base.errors import ChecksumError
17
+ from ccxt.base.errors import UnsubscribeError
16
18
  from ccxt.base.precise import Precise
17
19
 
18
20
 
@@ -621,6 +623,74 @@ class binance(ccxt.async_support.binance):
621
623
  orderbook = await self.watch_multiple(url, messageHashes, self.extend(request, params), messageHashes, subscription)
622
624
  return orderbook.limit()
623
625
 
626
+ async def un_watch_order_book_for_symbols(self, symbols: List[str], params={}) -> Any:
627
+ """
628
+ :see: https://binance-docs.github.io/apidocs/spot/en/#partial-book-depth-streams
629
+ :see: https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream
630
+ :see: https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams
631
+ :see: https://binance-docs.github.io/apidocs/futures/en/#diff-book-depth-streams
632
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#partial-book-depth-streams
633
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#diff-book-depth-streams
634
+ unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
635
+ :param str[] symbols: unified array of symbols
636
+ :param dict [params]: extra parameters specific to the exchange API endpoint
637
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
638
+ """
639
+ await self.load_markets()
640
+ symbols = self.market_symbols(symbols, None, False, True, True)
641
+ firstMarket = self.market(symbols[0])
642
+ type = firstMarket['type']
643
+ if firstMarket['contract']:
644
+ type = 'future' if firstMarket['linear'] else 'delivery'
645
+ name = 'depth'
646
+ streamHash = 'multipleOrderbook'
647
+ if symbols is not None:
648
+ streamHash += '::' + ','.join(symbols)
649
+ watchOrderBookRate = self.safe_string(self.options, 'watchOrderBookRate', '100')
650
+ subParams = []
651
+ subMessageHashes = []
652
+ messageHashes = []
653
+ for i in range(0, len(symbols)):
654
+ symbol = symbols[i]
655
+ market = self.market(symbol)
656
+ subMessageHashes.append('orderbook::' + symbol)
657
+ messageHashes.append('unsubscribe:orderbook:' + symbol)
658
+ subscriptionHash = market['lowercaseId'] + '@' + name
659
+ symbolHash = subscriptionHash + '@' + watchOrderBookRate + 'ms'
660
+ subParams.append(symbolHash)
661
+ messageHashesLength = len(subMessageHashes)
662
+ url = self.urls['api']['ws'][type] + '/' + self.stream(type, streamHash, messageHashesLength)
663
+ requestId = self.request_id(url)
664
+ request: dict = {
665
+ 'method': 'UNSUBSCRIBE',
666
+ 'params': subParams,
667
+ 'id': requestId,
668
+ }
669
+ subscription: dict = {
670
+ 'unsubscribe': True,
671
+ 'id': str(requestId),
672
+ 'symbols': symbols,
673
+ 'subMessageHashes': subMessageHashes,
674
+ 'messageHashes': messageHashes,
675
+ 'topic': 'orderbook',
676
+ }
677
+ return await self.watch_multiple(url, messageHashes, self.extend(request, params), messageHashes, subscription)
678
+
679
+ async def un_watch_order_book(self, symbol: str, params={}) -> Any:
680
+ """
681
+ :see: https://binance-docs.github.io/apidocs/spot/en/#partial-book-depth-streams
682
+ :see: https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream
683
+ :see: https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams
684
+ :see: https://binance-docs.github.io/apidocs/futures/en/#diff-book-depth-streams
685
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#partial-book-depth-streams
686
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#diff-book-depth-streams
687
+ unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
688
+ :param str symbol: unified array of symbols
689
+ :param dict [params]: extra parameters specific to the exchange API endpoint
690
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
691
+ """
692
+ return await self.un_watch_order_book_for_symbols([symbol], params)
693
+
624
694
  async def fetch_order_book_ws(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
625
695
  """
626
696
  fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
@@ -871,8 +941,55 @@ class binance(ccxt.async_support.binance):
871
941
  method = self.safe_value(subscription, 'method')
872
942
  if method is not None:
873
943
  method(client, message, subscription)
944
+ isUnSubMessage = self.safe_bool(subscription, 'unsubscribe', False)
945
+ if isUnSubMessage:
946
+ self.handle_un_subscription(client, subscription)
874
947
  return message
875
948
 
949
+ def handle_un_subscription(self, client: Client, subscription: dict):
950
+ messageHashes = self.safe_list(subscription, 'messageHashes', [])
951
+ subMessageHashes = self.safe_list(subscription, 'subMessageHashes', [])
952
+ for j in range(0, len(messageHashes)):
953
+ unsubHash = messageHashes[j]
954
+ subHash = subMessageHashes[j]
955
+ if unsubHash in client.subscriptions:
956
+ del client.subscriptions[unsubHash]
957
+ if subHash in client.subscriptions:
958
+ del client.subscriptions[subHash]
959
+ error = UnsubscribeError(self.id + ' ' + subHash)
960
+ client.reject(error, subHash)
961
+ client.resolve(True, unsubHash)
962
+ self.clean_cache(subscription)
963
+
964
+ def clean_cache(self, subscription: dict):
965
+ topic = self.safe_string(subscription, 'topic')
966
+ symbols = self.safe_list(subscription, 'symbols', [])
967
+ symbolsLength = len(symbols)
968
+ if symbolsLength > 0:
969
+ for i in range(0, len(symbols)):
970
+ symbol = symbols[i]
971
+ if topic == 'trade':
972
+ del self.trades[symbol]
973
+ elif topic == 'orderbook':
974
+ del self.orderbooks[symbol]
975
+ elif topic == 'ticker':
976
+ del self.tickers[symbol]
977
+ else:
978
+ if topic == 'myTrades':
979
+ # don't reset self.myTrades directly here
980
+ # because in c# we need to use a different object
981
+ keys = list(self.myTrades.keys())
982
+ for i in range(0, len(keys)):
983
+ del self.myTrades[keys[i]]
984
+ elif topic == 'orders':
985
+ orderSymbols = list(self.orders.keys())
986
+ for i in range(0, len(orderSymbols)):
987
+ del self.orders[orderSymbols[i]]
988
+ elif topic == 'ticker':
989
+ tickerSymbols = list(self.tickers.keys())
990
+ for i in range(0, len(tickerSymbols)):
991
+ del self.tickers[tickerSymbols[i]]
992
+
876
993
  async def watch_trades_for_symbols(self, symbols: List[str], since: Int = None, limit: Int = None, params={}) -> List[Trade]:
877
994
  """
878
995
  get the list of most recent trades for a list of symbols
@@ -929,6 +1046,77 @@ class binance(ccxt.async_support.binance):
929
1046
  limit = trades.getLimit(tradeSymbol, limit)
930
1047
  return self.filter_by_since_limit(trades, since, limit, 'timestamp', True)
931
1048
 
1049
+ async def un_watch_trades_for_symbols(self, symbols: List[str], params={}) -> Any:
1050
+ """
1051
+ unsubscribes from the trades channel
1052
+ :see: https://binance-docs.github.io/apidocs/spot/en/#aggregate-trade-streams
1053
+ :see: https://binance-docs.github.io/apidocs/spot/en/#trade-streams
1054
+ :see: https://binance-docs.github.io/apidocs/futures/en/#aggregate-trade-streams
1055
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#aggregate-trade-streams
1056
+ :param str[] symbols: unified symbol of the market to fetch trades for
1057
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1058
+ :param str [params.name]: the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
1059
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
1060
+ """
1061
+ await self.load_markets()
1062
+ symbols = self.market_symbols(symbols, None, False, True, True)
1063
+ streamHash = 'multipleTrades'
1064
+ if symbols is not None:
1065
+ symbolsLength = len(symbols)
1066
+ if symbolsLength > 200:
1067
+ raise BadRequest(self.id + ' watchTradesForSymbols() accepts 200 symbols at most. To watch more symbols call watchTradesForSymbols() multiple times')
1068
+ streamHash += '::' + ','.join(symbols)
1069
+ name = None
1070
+ name, params = self.handle_option_and_params(params, 'watchTradesForSymbols', 'name', 'trade')
1071
+ params = self.omit(params, 'callerMethodName')
1072
+ firstMarket = self.market(symbols[0])
1073
+ type = firstMarket['type']
1074
+ if firstMarket['contract']:
1075
+ type = 'future' if firstMarket['linear'] else 'delivery'
1076
+ subMessageHashes = []
1077
+ subParams = []
1078
+ messageHashes = []
1079
+ for i in range(0, len(symbols)):
1080
+ symbol = symbols[i]
1081
+ market = self.market(symbol)
1082
+ subMessageHashes.append('trade::' + symbol)
1083
+ messageHashes.append('unsubscribe:trade:' + symbol)
1084
+ rawHash = market['lowercaseId'] + '@' + name
1085
+ subParams.append(rawHash)
1086
+ query = self.omit(params, 'type')
1087
+ subParamsLength = len(subParams)
1088
+ url = self.urls['api']['ws'][type] + '/' + self.stream(type, streamHash, subParamsLength)
1089
+ requestId = self.request_id(url)
1090
+ request: dict = {
1091
+ 'method': 'UNSUBSCRIBE',
1092
+ 'params': subParams,
1093
+ 'id': requestId,
1094
+ }
1095
+ subscription: dict = {
1096
+ 'unsubscribe': True,
1097
+ 'id': str(requestId),
1098
+ 'subMessageHashes': subMessageHashes,
1099
+ 'messageHashes': messageHashes,
1100
+ 'symbols': symbols,
1101
+ 'topic': 'trade',
1102
+ }
1103
+ return await self.watch_multiple(url, messageHashes, self.extend(request, query), messageHashes, subscription)
1104
+
1105
+ async def un_watch_trades(self, symbol: str, params={}) -> Any:
1106
+ """
1107
+ unsubscribes from the trades channel
1108
+ :see: https://binance-docs.github.io/apidocs/spot/en/#aggregate-trade-streams
1109
+ :see: https://binance-docs.github.io/apidocs/spot/en/#trade-streams
1110
+ :see: https://binance-docs.github.io/apidocs/futures/en/#aggregate-trade-streams
1111
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#aggregate-trade-streams
1112
+ :param str symbol: unified symbol of the market to fetch trades for
1113
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1114
+ :param str [params.name]: the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
1115
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
1116
+ """
1117
+ await self.load_markets()
1118
+ return await self.un_watch_trades_for_symbols([symbol], params)
1119
+
932
1120
  async def watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
933
1121
  """
934
1122
  get the list of most recent trades for a particular symbol
@@ -1427,6 +1615,98 @@ class binance(ccxt.async_support.binance):
1427
1615
  return newTickers
1428
1616
  return self.filter_by_array(self.tickers, 'symbol', symbols)
1429
1617
 
1618
+ async def un_watch_tickers(self, symbols: Strings = None, params={}) -> Any:
1619
+ """
1620
+ :see: https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream
1621
+ :see: https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-ticker-streams
1622
+ :see: https://binance-docs.github.io/apidocs/futures/en/#all-market-mini-tickers-stream
1623
+ :see: https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams
1624
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#all-market-mini-tickers-stream
1625
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#individual-symbol-ticker-streams
1626
+ unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
1627
+ :param str[] symbols: unified symbol of the market to fetch the ticker for
1628
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1629
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
1630
+ """
1631
+ channelName = None
1632
+ channelName, params = self.handle_option_and_params(params, 'watchTickers', 'name', 'ticker')
1633
+ if channelName == 'bookTicker':
1634
+ raise BadRequest(self.id + ' deprecation notice - to subscribe for bids-asks, use watch_bids_asks() method instead')
1635
+ await self.load_markets()
1636
+ methodName = 'watchTickers'
1637
+ symbols = self.market_symbols(symbols, None, True, False, True)
1638
+ firstMarket = None
1639
+ marketType = None
1640
+ symbolsDefined = (symbols is not None)
1641
+ if symbolsDefined:
1642
+ firstMarket = self.market(symbols[0])
1643
+ marketType, params = self.handle_market_type_and_params(methodName, firstMarket, params)
1644
+ subType = None
1645
+ subType, params = self.handle_sub_type_and_params(methodName, firstMarket, params)
1646
+ rawMarketType = None
1647
+ if self.isLinear(marketType, subType):
1648
+ rawMarketType = 'future'
1649
+ elif self.isInverse(marketType, subType):
1650
+ rawMarketType = 'delivery'
1651
+ elif marketType == 'spot':
1652
+ rawMarketType = marketType
1653
+ else:
1654
+ raise NotSupported(self.id + ' ' + methodName + '() does not support options markets')
1655
+ isBidAsk = (channelName == 'bookTicker')
1656
+ subscriptionArgs = []
1657
+ subMessageHashes = []
1658
+ messageHashes = []
1659
+ if symbolsDefined:
1660
+ for i in range(0, len(symbols)):
1661
+ symbol = symbols[i]
1662
+ market = self.market(symbol)
1663
+ subscriptionArgs.append(market['lowercaseId'] + '@' + channelName)
1664
+ subMessageHashes.append(self.get_message_hash(channelName, market['symbol'], isBidAsk))
1665
+ messageHashes.append('unsubscribe:ticker:' + symbol)
1666
+ else:
1667
+ if isBidAsk:
1668
+ if marketType == 'spot':
1669
+ raise ArgumentsRequired(self.id + ' ' + methodName + '() requires symbols for self channel for spot markets')
1670
+ subscriptionArgs.append('!' + channelName)
1671
+ else:
1672
+ subscriptionArgs.append('!' + channelName + '@arr')
1673
+ subMessageHashes.append(self.get_message_hash(channelName, None, isBidAsk))
1674
+ messageHashes.append('unsubscribe:ticker')
1675
+ streamHash = channelName
1676
+ if symbolsDefined:
1677
+ streamHash = channelName + '::' + ','.join(symbols)
1678
+ url = self.urls['api']['ws'][rawMarketType] + '/' + self.stream(rawMarketType, streamHash)
1679
+ requestId = self.request_id(url)
1680
+ request: dict = {
1681
+ 'method': 'UNSUBSCRIBE',
1682
+ 'params': subscriptionArgs,
1683
+ 'id': requestId,
1684
+ }
1685
+ subscription: dict = {
1686
+ 'unsubscribe': True,
1687
+ 'id': str(requestId),
1688
+ 'subMessageHashes': subMessageHashes,
1689
+ 'messageHashes': subMessageHashes,
1690
+ 'symbols': symbols,
1691
+ 'topic': 'ticker',
1692
+ }
1693
+ return await self.watch_multiple(url, subMessageHashes, self.extend(request, params), subMessageHashes, subscription)
1694
+
1695
+ async def un_watch_ticker(self, symbol: str, params={}) -> Any:
1696
+ """
1697
+ :see: https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream
1698
+ :see: https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-ticker-streams
1699
+ :see: https://binance-docs.github.io/apidocs/futures/en/#all-market-mini-tickers-stream
1700
+ :see: https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams
1701
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#all-market-mini-tickers-stream
1702
+ :see: https://binance-docs.github.io/apidocs/delivery/en/#individual-symbol-ticker-streams
1703
+ unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
1704
+ :param str symbol: unified symbol of the market to fetch the ticker for
1705
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1706
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
1707
+ """
1708
+ return await self.un_watch_tickers([symbol], params)
1709
+
1430
1710
  async def watch_bids_asks(self, symbols: Strings = None, params={}) -> Tickers:
1431
1711
  """
1432
1712
  watches best bid & ask for symbols