trd-utils 0.0.30__py3-none-any.whl → 0.0.32__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.
Potentially problematic release.
This version of trd-utils might be problematic. Click here for more details.
- trd_utils/__init__.py +1 -1
- trd_utils/exchanges/blofin/blofin_client.py +2 -0
- trd_utils/exchanges/bx_ultra/bx_types.py +11 -0
- trd_utils/exchanges/bx_ultra/bx_ultra_client.py +23 -9
- trd_utils/exchanges/exchange_base.py +8 -1
- trd_utils/exchanges/hyperliquid/hyperliquid_client.py +2 -0
- trd_utils/exchanges/okx/okx_client.py +2 -0
- {trd_utils-0.0.30.dist-info → trd_utils-0.0.32.dist-info}/METADATA +1 -1
- {trd_utils-0.0.30.dist-info → trd_utils-0.0.32.dist-info}/RECORD +11 -11
- {trd_utils-0.0.30.dist-info → trd_utils-0.0.32.dist-info}/LICENSE +0 -0
- {trd_utils-0.0.30.dist-info → trd_utils-0.0.32.dist-info}/WHEEL +0 -0
trd_utils/__init__.py
CHANGED
|
@@ -59,6 +59,8 @@ class BlofinClient(ExchangeBase):
|
|
|
59
59
|
self.account_name = account_name
|
|
60
60
|
self._fav_letter = fav_letter
|
|
61
61
|
self.sessions_dir = sessions_dir
|
|
62
|
+
|
|
63
|
+
super().__init__()
|
|
62
64
|
|
|
63
65
|
if read_session_file:
|
|
64
66
|
self.read_from_session_file(f"{sessions_dir}/{self.account_name}.bf")
|
|
@@ -636,6 +636,17 @@ class CopyTraderResumeResult(BaseModel):
|
|
|
636
636
|
swap_copy_trade_label_type: int = None
|
|
637
637
|
is_pro: int = None
|
|
638
638
|
|
|
639
|
+
def get_account_identity_by_filter(self, filter_text: str):
|
|
640
|
+
if not self.trader_sharing_accounts:
|
|
641
|
+
return 0
|
|
642
|
+
|
|
643
|
+
for current in self.trader_sharing_accounts:
|
|
644
|
+
if current.display_name.lower().find(filter_text) != -1 or \
|
|
645
|
+
current.copy_trade_account_enum.lower().find(filter_text) != -1:
|
|
646
|
+
if current.api_identity:
|
|
647
|
+
return current.api_identity
|
|
648
|
+
return 0
|
|
649
|
+
|
|
639
650
|
|
|
640
651
|
class CopyTraderResumeResponse(BxApiResponse):
|
|
641
652
|
data: CopyTraderResumeResult = None
|
|
@@ -124,14 +124,12 @@ class BXUltraClient(ExchangeBase):
|
|
|
124
124
|
self._fav_letter = fav_letter
|
|
125
125
|
self.sessions_dir = sessions_dir
|
|
126
126
|
|
|
127
|
+
super().__init__()
|
|
127
128
|
self.read_from_session_file(
|
|
128
129
|
file_path=f"{self.sessions_dir}/{self.account_name}.bx"
|
|
129
130
|
)
|
|
130
131
|
self.__last_candle_storage = {}
|
|
131
132
|
self.__last_candle_lock = asyncio.Lock()
|
|
132
|
-
self._internal_lock = asyncio.Lock()
|
|
133
|
-
self.extra_tasks = []
|
|
134
|
-
self.ws_connections = []
|
|
135
133
|
|
|
136
134
|
# endregion
|
|
137
135
|
###########################################################
|
|
@@ -310,11 +308,12 @@ class BXUltraClient(ExchangeBase):
|
|
|
310
308
|
async for msg in ws:
|
|
311
309
|
try:
|
|
312
310
|
decompressed_message = gzip.decompress(msg)
|
|
313
|
-
|
|
311
|
+
str_msg = decompressed_message.decode("utf-8")
|
|
312
|
+
if str_msg.lower() == "ping":
|
|
314
313
|
await ws.send("Pong")
|
|
315
314
|
continue
|
|
316
315
|
|
|
317
|
-
data: dict = json.loads(
|
|
316
|
+
data: dict = json.loads(str_msg, parse_float=Decimal)
|
|
318
317
|
if not isinstance(data, dict):
|
|
319
318
|
logger.warning(f"invalid data instance: {type(data)}")
|
|
320
319
|
continue
|
|
@@ -702,6 +701,7 @@ class BXUltraClient(ExchangeBase):
|
|
|
702
701
|
async def get_trader_api_identity(
|
|
703
702
|
self,
|
|
704
703
|
uid: int | str,
|
|
704
|
+
sub_account_filter: str = "futures",
|
|
705
705
|
) -> int | str:
|
|
706
706
|
global user_api_identity_cache
|
|
707
707
|
api_identity = user_api_identity_cache.get(uid, None)
|
|
@@ -710,6 +710,12 @@ class BXUltraClient(ExchangeBase):
|
|
|
710
710
|
uid=uid,
|
|
711
711
|
)
|
|
712
712
|
api_identity = resume.data.api_identity
|
|
713
|
+
if not api_identity:
|
|
714
|
+
# second try: try to use one of the sub-accounts' identity
|
|
715
|
+
api_identity = resume.data.get_account_identity_by_filter(sub_account_filter)
|
|
716
|
+
|
|
717
|
+
# maybe also try to fetch it in other ways later?
|
|
718
|
+
# ...
|
|
713
719
|
user_api_identity_cache[uid] = api_identity
|
|
714
720
|
return api_identity
|
|
715
721
|
|
|
@@ -838,7 +844,8 @@ class BXUltraClient(ExchangeBase):
|
|
|
838
844
|
aes = AESCipher(key=f"bx_{self.account_name}_bx", fav_letter=self._fav_letter)
|
|
839
845
|
target_path = Path(file_path)
|
|
840
846
|
if not target_path.exists():
|
|
841
|
-
target_path.mkdir(parents=True)
|
|
847
|
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
848
|
+
target_path.touch()
|
|
842
849
|
target_path.write_text(aes.encrypt(json.dumps(json_data)))
|
|
843
850
|
|
|
844
851
|
# endregion
|
|
@@ -848,10 +855,17 @@ class BXUltraClient(ExchangeBase):
|
|
|
848
855
|
async def get_unified_trader_positions(
|
|
849
856
|
self,
|
|
850
857
|
uid: int | str,
|
|
858
|
+
api_identity: int | str | None = None,
|
|
859
|
+
sub_account_filter: str = "futures",
|
|
851
860
|
) -> UnifiedTraderPositions:
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
861
|
+
if not api_identity:
|
|
862
|
+
api_identity = await self.get_trader_api_identity(
|
|
863
|
+
uid=uid,
|
|
864
|
+
sub_account_filter=sub_account_filter,
|
|
865
|
+
)
|
|
866
|
+
|
|
867
|
+
if not api_identity:
|
|
868
|
+
raise ValueError(f"Failed to fetch api_identity for user {uid}")
|
|
855
869
|
|
|
856
870
|
result = await self.get_copy_trader_positions(
|
|
857
871
|
uid=uid,
|
|
@@ -66,7 +66,15 @@ class ExchangeBase(ABC):
|
|
|
66
66
|
ws_connections: list[WSConnection] = None
|
|
67
67
|
# endregion
|
|
68
68
|
###########################################################
|
|
69
|
+
# region constructor method
|
|
69
70
|
|
|
71
|
+
def __init__(self):
|
|
72
|
+
self._internal_lock = asyncio.Lock()
|
|
73
|
+
self.extra_tasks = []
|
|
74
|
+
self.ws_connections = []
|
|
75
|
+
|
|
76
|
+
# endregion
|
|
77
|
+
###########################################################
|
|
70
78
|
# region abstract trading methods
|
|
71
79
|
|
|
72
80
|
async def get_unified_trader_positions(
|
|
@@ -96,7 +104,6 @@ class ExchangeBase(ABC):
|
|
|
96
104
|
)
|
|
97
105
|
|
|
98
106
|
# endregion
|
|
99
|
-
|
|
100
107
|
###########################################################
|
|
101
108
|
# region client helper methods
|
|
102
109
|
def get_headers(self, payload=None, needs_auth: bool = False) -> dict:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
trd_utils/__init__.py,sha256=
|
|
1
|
+
trd_utils/__init__.py,sha256=5mjXdrdRYpXTN4Y1ocvl6aDC56jkrCDAO1vGFM9PsPw,25
|
|
2
2
|
trd_utils/cipher/__init__.py,sha256=V05KNuzQwCic-ihMVHlC8sENaJGc3I8MCb4pg4849X8,1765
|
|
3
3
|
trd_utils/common_utils/float_utils.py,sha256=aYPwJ005LmrRhXAngojwvdDdtRgeb1FfR6hKeQ5ndMU,470
|
|
4
4
|
trd_utils/common_utils/wallet_utils.py,sha256=OX9q2fymP0VfIWTRIRBP8W33cfyjLXimxMgPOsZe-3g,727
|
|
@@ -8,20 +8,20 @@ trd_utils/exchanges/README.md,sha256=UwkpsfcoLCJaMvJe4yBsFkDpf8P6DOLYhtybb6xWMLc
|
|
|
8
8
|
trd_utils/exchanges/__init__.py,sha256=sZRyp24q0KyMYASshAfsP-AfvsCADTYqqefxiRulPKE,484
|
|
9
9
|
trd_utils/exchanges/base_types.py,sha256=NGykHGyY97mcc4gqxa0RLNElro0y3cQsdSCM1XAtIz8,3625
|
|
10
10
|
trd_utils/exchanges/blofin/__init__.py,sha256=X4r9o4Nyjla4UeOBG8lrgtnGYO2aErFMKaJ7yQrFasE,76
|
|
11
|
-
trd_utils/exchanges/blofin/blofin_client.py,sha256=
|
|
11
|
+
trd_utils/exchanges/blofin/blofin_client.py,sha256=RJcyET62cjxczEdHqQ-Cy6CT8veJYio_efublNBvEo8,12378
|
|
12
12
|
trd_utils/exchanges/blofin/blofin_types.py,sha256=ZlHX1ClYTd2pDRTQIlZYyBu5ReGpMgxXxKASsPeBQug,4090
|
|
13
13
|
trd_utils/exchanges/bx_ultra/__init__.py,sha256=8Ssy-eOemQR32Nv1-FoPHm87nRqRO4Fm2PU5GHEFKfQ,80
|
|
14
|
-
trd_utils/exchanges/bx_ultra/bx_types.py,sha256=
|
|
15
|
-
trd_utils/exchanges/bx_ultra/bx_ultra_client.py,sha256=
|
|
14
|
+
trd_utils/exchanges/bx_ultra/bx_types.py,sha256=qg_MoaZRpfRf29Eh-W0JXUklQWt5ckoP-Ktk4faX9io,34985
|
|
15
|
+
trd_utils/exchanges/bx_ultra/bx_ultra_client.py,sha256=w4VNjNjp5h-GLRMheWl8uU_KPWL7FrhV5TwbfQiyo3A,34432
|
|
16
16
|
trd_utils/exchanges/bx_ultra/bx_utils.py,sha256=PwapomwDW33arVmKIDj6cL-aP0ptu4BYy_lOCqSAPOo,1392
|
|
17
17
|
trd_utils/exchanges/errors.py,sha256=P_NTuc389XL7rFegomP59BydWmHv8ckiGyNU-_l5qNQ,167
|
|
18
|
-
trd_utils/exchanges/exchange_base.py,sha256=
|
|
18
|
+
trd_utils/exchanges/exchange_base.py,sha256=c9SV-XyZNonbPa8DDujHGSF4CR-iweGUojsPGvphjlU,7909
|
|
19
19
|
trd_utils/exchanges/hyperliquid/README.md,sha256=-qaxmDt_9NTus2xRuzyFGkKgYDWgWk7ufHVTSkyn3t4,105
|
|
20
20
|
trd_utils/exchanges/hyperliquid/__init__.py,sha256=QhwGRcneGFHREM-MMdYpbcx-aWdsWsu2WznHzx7LaUM,92
|
|
21
|
-
trd_utils/exchanges/hyperliquid/hyperliquid_client.py,sha256=
|
|
21
|
+
trd_utils/exchanges/hyperliquid/hyperliquid_client.py,sha256=FOOEDY1wOvyDlUcnSHf0Vp-8KNK2_AkI6Z7h3lls3Co,6832
|
|
22
22
|
trd_utils/exchanges/hyperliquid/hyperliquid_types.py,sha256=MiGG5fRU7wHqOMtCzQXD1fwwbeUK1HEcQwW5rl-9D4c,2678
|
|
23
23
|
trd_utils/exchanges/okx/__init__.py,sha256=OjVpvcwB9mrCTofLt14JRHV2-fMAzGz9-YkJAMwl6dM,67
|
|
24
|
-
trd_utils/exchanges/okx/okx_client.py,sha256=
|
|
24
|
+
trd_utils/exchanges/okx/okx_client.py,sha256=lUf507ovd4D3fI7Z3Iy1fGvxNJWdm4wTcdzTCkMw13U,7146
|
|
25
25
|
trd_utils/exchanges/okx/okx_types.py,sha256=IkFOfgivcvvIw950jyGHAVfFFGbGqfZcYGfZLWfNLvc,5013
|
|
26
26
|
trd_utils/html_utils/__init__.py,sha256=1WWs8C7JszRjTkmzIRLHpxWECHur_DrulTPGIeX88oM,426
|
|
27
27
|
trd_utils/html_utils/html_formats.py,sha256=unKsvOiiDmYTTaM0DYZEUNLEUzWQKKrqASJXvY54kvU,2299
|
|
@@ -30,7 +30,7 @@ trd_utils/tradingview/tradingview_client.py,sha256=g_eWYaCRQAL8Kvd-r6AnAdbH7Jha6
|
|
|
30
30
|
trd_utils/tradingview/tradingview_types.py,sha256=z21MXPVdWHAduEl3gSeMIRhxtBN9yK-jPYHfZSMIbSA,6144
|
|
31
31
|
trd_utils/types_helper/__init__.py,sha256=lLbUiW1jUV1gjzTMFLthwkvF0hwauH-F_J2JZq--1U0,67
|
|
32
32
|
trd_utils/types_helper/base_model.py,sha256=Q2KK0r4UXP9PlWeIl6nxdAeCGB5InU5IkTNGAfJasfM,11808
|
|
33
|
-
trd_utils-0.0.
|
|
34
|
-
trd_utils-0.0.
|
|
35
|
-
trd_utils-0.0.
|
|
36
|
-
trd_utils-0.0.
|
|
33
|
+
trd_utils-0.0.32.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
|
|
34
|
+
trd_utils-0.0.32.dist-info/METADATA,sha256=iqiiINJSXF-3P6x455gGj8HLQYJ-Qx6mKXl-HFBMe_A,1179
|
|
35
|
+
trd_utils-0.0.32.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
36
|
+
trd_utils-0.0.32.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|