trd-utils 0.0.30__py3-none-any.whl → 0.0.31__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 +20 -7
- 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.31.dist-info}/METADATA +1 -1
- {trd_utils-0.0.30.dist-info → trd_utils-0.0.31.dist-info}/RECORD +11 -11
- {trd_utils-0.0.30.dist-info → trd_utils-0.0.31.dist-info}/LICENSE +0 -0
- {trd_utils-0.0.30.dist-info → trd_utils-0.0.31.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
|
###########################################################
|
|
@@ -702,6 +700,7 @@ class BXUltraClient(ExchangeBase):
|
|
|
702
700
|
async def get_trader_api_identity(
|
|
703
701
|
self,
|
|
704
702
|
uid: int | str,
|
|
703
|
+
sub_account_filter: str = "futures",
|
|
705
704
|
) -> int | str:
|
|
706
705
|
global user_api_identity_cache
|
|
707
706
|
api_identity = user_api_identity_cache.get(uid, None)
|
|
@@ -710,6 +709,12 @@ class BXUltraClient(ExchangeBase):
|
|
|
710
709
|
uid=uid,
|
|
711
710
|
)
|
|
712
711
|
api_identity = resume.data.api_identity
|
|
712
|
+
if not api_identity:
|
|
713
|
+
# second try: try to use one of the sub-accounts' identity
|
|
714
|
+
api_identity = resume.data.get_account_identity_by_filter(sub_account_filter)
|
|
715
|
+
|
|
716
|
+
# maybe also try to fetch it in other ways later?
|
|
717
|
+
# ...
|
|
713
718
|
user_api_identity_cache[uid] = api_identity
|
|
714
719
|
return api_identity
|
|
715
720
|
|
|
@@ -838,7 +843,8 @@ class BXUltraClient(ExchangeBase):
|
|
|
838
843
|
aes = AESCipher(key=f"bx_{self.account_name}_bx", fav_letter=self._fav_letter)
|
|
839
844
|
target_path = Path(file_path)
|
|
840
845
|
if not target_path.exists():
|
|
841
|
-
target_path.mkdir(parents=True)
|
|
846
|
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
847
|
+
target_path.touch()
|
|
842
848
|
target_path.write_text(aes.encrypt(json.dumps(json_data)))
|
|
843
849
|
|
|
844
850
|
# endregion
|
|
@@ -848,10 +854,17 @@ class BXUltraClient(ExchangeBase):
|
|
|
848
854
|
async def get_unified_trader_positions(
|
|
849
855
|
self,
|
|
850
856
|
uid: int | str,
|
|
857
|
+
api_identity: int | str | None = None,
|
|
858
|
+
sub_account_filter: str = "futures",
|
|
851
859
|
) -> UnifiedTraderPositions:
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
860
|
+
if not api_identity:
|
|
861
|
+
api_identity = await self.get_trader_api_identity(
|
|
862
|
+
uid=uid,
|
|
863
|
+
sub_account_filter=sub_account_filter,
|
|
864
|
+
)
|
|
865
|
+
|
|
866
|
+
if not api_identity:
|
|
867
|
+
raise ValueError(f"Failed to fetch api_identity for user {uid}")
|
|
855
868
|
|
|
856
869
|
result = await self.get_copy_trader_positions(
|
|
857
870
|
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=O97248lgCS5nee4fQ2cNH-783s7siiDuLQOhN5Lzeiw,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=jQ2eeyiB3Y8-furMuEf-76WrlGExKsnpWQtdI3RJ66M,34391
|
|
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.31.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
|
|
34
|
+
trd_utils-0.0.31.dist-info/METADATA,sha256=RFw0zRRFdg7zTNzVlNfH4W2g3J6I4NfYNea1jHohbsY,1179
|
|
35
|
+
trd_utils-0.0.31.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
36
|
+
trd_utils-0.0.31.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|