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.
- unicex/__init__.py +56 -124
- unicex/_abc/__init__.py +2 -0
- unicex/_abc/exchange_info.py +176 -0
- unicex/_abc/uni_client.py +2 -2
- unicex/_base/client.py +2 -2
- unicex/binance/__init__.py +12 -0
- unicex/binance/adapter.py +2 -2
- unicex/binance/exchange_info.py +12 -0
- unicex/bitget/__init__.py +14 -4
- unicex/bitget/adapter.py +1 -1
- unicex/bitget/exchange_info.py +12 -0
- unicex/bitget/uni_websocket_manager.py +1 -1
- unicex/bybit/__init__.py +12 -0
- unicex/bybit/adapter.py +2 -2
- unicex/bybit/exchange_info.py +12 -0
- unicex/bybit/uni_client.py +2 -2
- unicex/enums.py +16 -5
- unicex/extra.py +84 -6
- unicex/gateio/__init__.py +12 -0
- unicex/gateio/adapter.py +4 -4
- unicex/gateio/exchange_info.py +12 -0
- unicex/hyperliquid/__init__.py +12 -0
- unicex/hyperliquid/adapter.py +151 -30
- unicex/hyperliquid/client.py +2208 -125
- unicex/hyperliquid/exchange_info.py +100 -0
- unicex/hyperliquid/uni_client.py +176 -22
- unicex/mapper.py +35 -33
- unicex/mexc/__init__.py +12 -0
- unicex/mexc/adapter.py +30 -13
- unicex/mexc/exchange_info.py +32 -0
- unicex/mexc/uni_client.py +6 -0
- unicex/okx/__init__.py +12 -0
- unicex/okx/adapter.py +25 -9
- unicex/okx/client.py +2599 -26
- unicex/okx/exchange_info.py +50 -0
- unicex/okx/uni_client.py +10 -10
- unicex/types.py +31 -0
- unicex-0.8.0.dist-info/METADATA +192 -0
- unicex-0.8.0.dist-info/RECORD +75 -0
- unicex/bitrue/__init__.py +0 -15
- unicex/bitrue/adapter.py +0 -8
- unicex/bitrue/client.py +0 -128
- unicex/bitrue/uni_client.py +0 -151
- unicex/bitrue/uni_websocket_manager.py +0 -269
- unicex/bitrue/user_websocket.py +0 -7
- unicex/bitrue/websocket_manager.py +0 -11
- unicex/bitunix/__init__.py +0 -15
- unicex/bitunix/adapter.py +0 -8
- unicex/bitunix/client.py +0 -8
- unicex/bitunix/uni_client.py +0 -151
- unicex/bitunix/uni_websocket_manager.py +0 -269
- unicex/bitunix/user_websocket.py +0 -7
- unicex/bitunix/websocket_manager.py +0 -11
- unicex/btse/__init__.py +0 -15
- unicex/btse/adapter.py +0 -8
- unicex/btse/client.py +0 -123
- unicex/btse/uni_client.py +0 -151
- unicex/btse/uni_websocket_manager.py +0 -269
- unicex/btse/user_websocket.py +0 -7
- unicex/btse/websocket_manager.py +0 -11
- unicex/kcex/__init__.py +0 -15
- unicex/kcex/adapter.py +0 -8
- unicex/kcex/client.py +0 -8
- unicex/kcex/uni_client.py +0 -151
- unicex/kcex/uni_websocket_manager.py +0 -269
- unicex/kcex/user_websocket.py +0 -7
- unicex/kcex/websocket_manager.py +0 -11
- unicex/kraken/__init__.py +0 -15
- unicex/kraken/adapter.py +0 -8
- unicex/kraken/client.py +0 -165
- unicex/kraken/uni_client.py +0 -151
- unicex/kraken/uni_websocket_manager.py +0 -269
- unicex/kraken/user_websocket.py +0 -7
- unicex/kraken/websocket_manager.py +0 -11
- unicex/kucoin/__init__.py +0 -15
- unicex/kucoin/adapter.py +0 -8
- unicex/kucoin/client.py +0 -120
- unicex/kucoin/uni_client.py +0 -151
- unicex/kucoin/uni_websocket_manager.py +0 -269
- unicex/kucoin/user_websocket.py +0 -7
- unicex/kucoin/websocket_manager.py +0 -11
- unicex/weex/__init__.py +0 -15
- unicex/weex/adapter.py +0 -8
- unicex/weex/client.py +0 -8
- unicex/weex/uni_client.py +0 -151
- unicex/weex/uni_websocket_manager.py +0 -269
- unicex/weex/user_websocket.py +0 -7
- unicex/weex/websocket_manager.py +0 -11
- unicex/xt/__init__.py +0 -15
- unicex/xt/adapter.py +0 -8
- unicex/xt/client.py +0 -8
- unicex/xt/uni_client.py +0 -151
- unicex/xt/uni_websocket_manager.py +0 -269
- unicex/xt/user_websocket.py +0 -7
- unicex/xt/websocket_manager.py +0 -11
- unicex-0.5.0.dist-info/METADATA +0 -170
- unicex-0.5.0.dist-info/RECORD +0 -123
- {unicex-0.5.0.dist-info → unicex-0.8.0.dist-info}/WHEEL +0 -0
- {unicex-0.5.0.dist-info → unicex-0.8.0.dist-info}/licenses/LICENSE +0 -0
- {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
|
|
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
|
|
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
|
|
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
|
|
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"])
|
|
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"])
|
|
80
|
+
(float(item["last"]) - float(item["open24h"])) / float(item["open24h"]) * 100, 2
|
|
73
81
|
),
|
|
74
82
|
v=float(item["volCcy24h"]),
|
|
75
|
-
q=float(item["
|
|
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
|