unicex 0.5.0__py3-none-any.whl → 0.8.0__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.
Files changed (100) hide show
  1. unicex/__init__.py +56 -124
  2. unicex/_abc/__init__.py +2 -0
  3. unicex/_abc/exchange_info.py +176 -0
  4. unicex/_abc/uni_client.py +2 -2
  5. unicex/_base/client.py +2 -2
  6. unicex/binance/__init__.py +12 -0
  7. unicex/binance/adapter.py +2 -2
  8. unicex/binance/exchange_info.py +12 -0
  9. unicex/bitget/__init__.py +14 -4
  10. unicex/bitget/adapter.py +1 -1
  11. unicex/bitget/exchange_info.py +12 -0
  12. unicex/bitget/uni_websocket_manager.py +1 -1
  13. unicex/bybit/__init__.py +12 -0
  14. unicex/bybit/adapter.py +2 -2
  15. unicex/bybit/exchange_info.py +12 -0
  16. unicex/bybit/uni_client.py +2 -2
  17. unicex/enums.py +16 -5
  18. unicex/extra.py +84 -6
  19. unicex/gateio/__init__.py +12 -0
  20. unicex/gateio/adapter.py +4 -4
  21. unicex/gateio/exchange_info.py +12 -0
  22. unicex/hyperliquid/__init__.py +12 -0
  23. unicex/hyperliquid/adapter.py +151 -30
  24. unicex/hyperliquid/client.py +2208 -125
  25. unicex/hyperliquid/exchange_info.py +100 -0
  26. unicex/hyperliquid/uni_client.py +176 -22
  27. unicex/mapper.py +35 -33
  28. unicex/mexc/__init__.py +12 -0
  29. unicex/mexc/adapter.py +30 -13
  30. unicex/mexc/exchange_info.py +32 -0
  31. unicex/mexc/uni_client.py +6 -0
  32. unicex/okx/__init__.py +12 -0
  33. unicex/okx/adapter.py +25 -9
  34. unicex/okx/client.py +2599 -26
  35. unicex/okx/exchange_info.py +50 -0
  36. unicex/okx/uni_client.py +10 -10
  37. unicex/types.py +31 -0
  38. unicex-0.8.0.dist-info/METADATA +192 -0
  39. unicex-0.8.0.dist-info/RECORD +75 -0
  40. unicex/bitrue/__init__.py +0 -15
  41. unicex/bitrue/adapter.py +0 -8
  42. unicex/bitrue/client.py +0 -128
  43. unicex/bitrue/uni_client.py +0 -151
  44. unicex/bitrue/uni_websocket_manager.py +0 -269
  45. unicex/bitrue/user_websocket.py +0 -7
  46. unicex/bitrue/websocket_manager.py +0 -11
  47. unicex/bitunix/__init__.py +0 -15
  48. unicex/bitunix/adapter.py +0 -8
  49. unicex/bitunix/client.py +0 -8
  50. unicex/bitunix/uni_client.py +0 -151
  51. unicex/bitunix/uni_websocket_manager.py +0 -269
  52. unicex/bitunix/user_websocket.py +0 -7
  53. unicex/bitunix/websocket_manager.py +0 -11
  54. unicex/btse/__init__.py +0 -15
  55. unicex/btse/adapter.py +0 -8
  56. unicex/btse/client.py +0 -123
  57. unicex/btse/uni_client.py +0 -151
  58. unicex/btse/uni_websocket_manager.py +0 -269
  59. unicex/btse/user_websocket.py +0 -7
  60. unicex/btse/websocket_manager.py +0 -11
  61. unicex/kcex/__init__.py +0 -15
  62. unicex/kcex/adapter.py +0 -8
  63. unicex/kcex/client.py +0 -8
  64. unicex/kcex/uni_client.py +0 -151
  65. unicex/kcex/uni_websocket_manager.py +0 -269
  66. unicex/kcex/user_websocket.py +0 -7
  67. unicex/kcex/websocket_manager.py +0 -11
  68. unicex/kraken/__init__.py +0 -15
  69. unicex/kraken/adapter.py +0 -8
  70. unicex/kraken/client.py +0 -165
  71. unicex/kraken/uni_client.py +0 -151
  72. unicex/kraken/uni_websocket_manager.py +0 -269
  73. unicex/kraken/user_websocket.py +0 -7
  74. unicex/kraken/websocket_manager.py +0 -11
  75. unicex/kucoin/__init__.py +0 -15
  76. unicex/kucoin/adapter.py +0 -8
  77. unicex/kucoin/client.py +0 -120
  78. unicex/kucoin/uni_client.py +0 -151
  79. unicex/kucoin/uni_websocket_manager.py +0 -269
  80. unicex/kucoin/user_websocket.py +0 -7
  81. unicex/kucoin/websocket_manager.py +0 -11
  82. unicex/weex/__init__.py +0 -15
  83. unicex/weex/adapter.py +0 -8
  84. unicex/weex/client.py +0 -8
  85. unicex/weex/uni_client.py +0 -151
  86. unicex/weex/uni_websocket_manager.py +0 -269
  87. unicex/weex/user_websocket.py +0 -7
  88. unicex/weex/websocket_manager.py +0 -11
  89. unicex/xt/__init__.py +0 -15
  90. unicex/xt/adapter.py +0 -8
  91. unicex/xt/client.py +0 -8
  92. unicex/xt/uni_client.py +0 -151
  93. unicex/xt/uni_websocket_manager.py +0 -269
  94. unicex/xt/user_websocket.py +0 -7
  95. unicex/xt/websocket_manager.py +0 -11
  96. unicex-0.5.0.dist-info/METADATA +0 -170
  97. unicex-0.5.0.dist-info/RECORD +0 -123
  98. {unicex-0.5.0.dist-info → unicex-0.8.0.dist-info}/WHEEL +0 -0
  99. {unicex-0.5.0.dist-info → unicex-0.8.0.dist-info}/licenses/LICENSE +0 -0
  100. {unicex-0.5.0.dist-info → unicex-0.8.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,32 @@
1
+ __all__ = ["ExchangeInfo"]
2
+
3
+ import aiohttp
4
+
5
+ from unicex._abc import IExchangeInfo
6
+ from unicex.types import TickerInfoItem
7
+
8
+
9
+ class ExchangeInfo(IExchangeInfo):
10
+ """Предзагружает информацию о тикерах для биржи Mexc."""
11
+
12
+ @classmethod
13
+ async def _load_exchange_info(cls) -> None:
14
+ """Загружает информацию о бирже."""
15
+ futures_tickers_info = {}
16
+ async with aiohttp.ClientSession() as session:
17
+ url = "https://contract.mexc.com/api/v1/contract/detail"
18
+ async with session.get(url) as response:
19
+ data = await response.json()
20
+ for el in data["data"]:
21
+ futures_tickers_info[el["symbol"]] = TickerInfoItem(
22
+ tick_precision=cls._step_size_to_precision(el["priceUnit"]),
23
+ size_precision=el["amountScale"],
24
+ contract_size=el["contractSize"],
25
+ min_market_size=el["minVol"],
26
+ max_market_size=el["maxVol"],
27
+ min_limit_size=el["minVol"],
28
+ max_limit_size=el["maxVol"],
29
+ )
30
+
31
+ cls._futures_tickers_info = futures_tickers_info
32
+ cls._logger.debug("Mexc futures exchange info loaded")
unicex/mexc/uni_client.py CHANGED
@@ -138,9 +138,15 @@ class UniClient(IUniClient[Client]):
138
138
  Возвращает:
139
139
  list[KlineDict]: Список свечей для тикера.
140
140
  """
141
+ if not limit and not all([start_time, end_time]):
142
+ raise ValueError("limit and (start_time and end_time) must be provided")
143
+
141
144
  if limit: # Перезаписываем start_time и end_time если указан limit, т.к. по умолчанию Mexc Futures не принимают этот параметр
145
+ if not isinstance(interval, Timeframe):
146
+ raise ValueError("interval must be a Timeframe if limit param provided")
142
147
  end_time = int(time.time())
143
148
  start_time = end_time - (limit * interval.to_seconds) # type: ignore[reportOptionalOperand]
149
+
144
150
  interval = (
145
151
  interval.to_exchange_format(Exchange.MEXC, MarketType.FUTURES)
146
152
  if isinstance(interval, Timeframe)
unicex/okx/__init__.py CHANGED
@@ -6,10 +6,22 @@ __all__ = [
6
6
  "UserWebsocket",
7
7
  "WebsocketManager",
8
8
  "UniWebsocketManager",
9
+ "ExchangeInfo",
9
10
  ]
10
11
 
11
12
  from .client import Client
13
+ from .exchange_info import ExchangeInfo
12
14
  from .uni_client import UniClient
13
15
  from .uni_websocket_manager import UniWebsocketManager
14
16
  from .user_websocket import UserWebsocket
15
17
  from .websocket_manager import WebsocketManager
18
+
19
+
20
+ async def load_exchange_info() -> None:
21
+ """Загружает информацию о бирже Okx."""
22
+ await ExchangeInfo.load_exchange_info()
23
+
24
+
25
+ async def start_exchange_info(parse_interval_seconds: int = 60 * 60) -> None:
26
+ """Запускает процесс обновления информации о бирже Okx."""
27
+ await ExchangeInfo.start(parse_interval_seconds)
unicex/okx/adapter.py CHANGED
@@ -10,13 +10,15 @@ from unicex.types import (
10
10
  )
11
11
  from unicex.utils import catch_adapter_errors, decorate_all_methods
12
12
 
13
+ from .exchange_info import ExchangeInfo
14
+
13
15
 
14
16
  @decorate_all_methods(catch_adapter_errors)
15
17
  class Adapter:
16
18
  """Адаптер для унификации данных с Okx API."""
17
19
 
18
20
  @staticmethod
19
- def tickers(raw_data: dict, only_usdt: bool = True) -> list[str]:
21
+ def tickers(raw_data: dict, only_usdt: bool) -> list[str]:
20
22
  """Преобразует сырые данные о тикерах в список унифицированных символов.
21
23
 
22
24
  Параметры:
@@ -29,11 +31,11 @@ class Adapter:
29
31
  return [
30
32
  item["instId"]
31
33
  for item in raw_data["data"]
32
- if only_usdt or item["instId"].endswith("-USDT")
34
+ if item["instId"].endswith("-USDT") or not only_usdt
33
35
  ]
34
36
 
35
37
  @staticmethod
36
- def futures_tickers(raw_data: dict, only_usdt: bool = True) -> list[str]:
38
+ def futures_tickers(raw_data: dict, only_usdt: bool) -> list[str]:
37
39
  """Преобразует сырые данные о тикерах в список унифицированных символов.
38
40
 
39
41
  Параметры:
@@ -46,16 +48,19 @@ class Adapter:
46
48
  return [
47
49
  item["instId"]
48
50
  for item in raw_data["data"]
49
- if only_usdt or item["instId"].endswith("-USDT-SWAP")
51
+ if item["instId"].endswith("-USDT-SWAP") or not only_usdt
50
52
  ]
51
53
 
52
54
  @staticmethod
53
55
  def ticker_24hr(raw_data: dict) -> TickerDailyDict:
54
- """Преобразует статистику 24ч в унифицированный формат."""
56
+ """Преобразует статистику 24ч в унифицированный формат.
57
+
58
+ # NOTE: Обратите внимание, изменение цены в случае с OKX возвращается относительно открытия 1 day свечи.
59
+ """
55
60
  return {
56
61
  item["instId"]: TickerDailyItem(
57
62
  p=round(
58
- (float(item["last"]) - float(item["open24h"]) / float(item["open24h"])) * 100, 2
63
+ (float(item["last"]) - float(item["open24h"])) / float(item["open24h"]) * 100, 2
59
64
  ),
60
65
  v=float(item["vol24h"]),
61
66
  q=float(item["volCcy24h"]),
@@ -65,14 +70,17 @@ class Adapter:
65
70
 
66
71
  @staticmethod
67
72
  def futures_ticker_24hr(raw_data: dict) -> TickerDailyDict:
68
- """Преобразует статистику 24ч в унифицированный формат."""
73
+ """Преобразует статистику 24ч в унифицированный формат.
74
+
75
+ # NOTE: Обратите внимание, изменение цены в случае с OKX возвращается относительно открытия 1 day свечи.
76
+ """
69
77
  return {
70
78
  item["instId"]: TickerDailyItem(
71
79
  p=round(
72
- (float(item["last"]) - float(item["open24h"]) / float(item["open24h"])) * 100, 2
80
+ (float(item["last"]) - float(item["open24h"])) / float(item["open24h"]) * 100, 2
73
81
  ),
74
82
  v=float(item["volCcy24h"]),
75
- q=float(item["vol24h"]),
83
+ q=float(item["volCcy24h"]) * float(item["last"]),
76
84
  )
77
85
  for item in raw_data["data"]
78
86
  }
@@ -120,3 +128,11 @@ class Adapter:
120
128
  )
121
129
  for item in raw_data["data"]
122
130
  }
131
+
132
+ @staticmethod
133
+ def _get_contract_size(symbol: str) -> float:
134
+ """Возвращает размер контракта для указанного символа тикера."""
135
+ try:
136
+ return ExchangeInfo.get_futures_ticker_info(symbol)["contract_size"] or 1
137
+ except: # noqa
138
+ return 1