trd-utils 0.0.30__tar.gz → 0.0.32__tar.gz

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.

Files changed (37) hide show
  1. {trd_utils-0.0.30 → trd_utils-0.0.32}/PKG-INFO +1 -1
  2. {trd_utils-0.0.30 → trd_utils-0.0.32}/pyproject.toml +1 -1
  3. trd_utils-0.0.32/trd_utils/__init__.py +3 -0
  4. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/blofin/blofin_client.py +2 -0
  5. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/bx_ultra/bx_types.py +11 -0
  6. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/bx_ultra/bx_ultra_client.py +23 -9
  7. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/exchange_base.py +8 -1
  8. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/hyperliquid/hyperliquid_client.py +2 -0
  9. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/okx/okx_client.py +2 -0
  10. trd_utils-0.0.30/trd_utils/__init__.py +0 -3
  11. {trd_utils-0.0.30 → trd_utils-0.0.32}/LICENSE +0 -0
  12. {trd_utils-0.0.30 → trd_utils-0.0.32}/README.md +0 -0
  13. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/cipher/__init__.py +0 -0
  14. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/common_utils/float_utils.py +0 -0
  15. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/common_utils/wallet_utils.py +0 -0
  16. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/date_utils/__init__.py +0 -0
  17. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/date_utils/datetime_helpers.py +0 -0
  18. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/README.md +0 -0
  19. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/__init__.py +0 -0
  20. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/base_types.py +0 -0
  21. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/blofin/__init__.py +0 -0
  22. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/blofin/blofin_types.py +0 -0
  23. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/bx_ultra/__init__.py +0 -0
  24. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/bx_ultra/bx_utils.py +0 -0
  25. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/errors.py +0 -0
  26. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/hyperliquid/README.md +0 -0
  27. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/hyperliquid/__init__.py +0 -0
  28. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/hyperliquid/hyperliquid_types.py +0 -0
  29. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/okx/__init__.py +0 -0
  30. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/exchanges/okx/okx_types.py +0 -0
  31. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/html_utils/__init__.py +0 -0
  32. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/html_utils/html_formats.py +0 -0
  33. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/tradingview/__init__.py +0 -0
  34. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/tradingview/tradingview_client.py +0 -0
  35. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/tradingview/tradingview_types.py +0 -0
  36. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/types_helper/__init__.py +0 -0
  37. {trd_utils-0.0.30 → trd_utils-0.0.32}/trd_utils/types_helper/base_model.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: trd_utils
3
- Version: 0.0.30
3
+ Version: 0.0.32
4
4
  Summary: Common Basic Utils for Python3. By ALiwoto.
5
5
  Keywords: utils,trd_utils,basic-utils,common-utils
6
6
  Author: ALiwoto
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "trd_utils"
3
- version = "0.0.30"
3
+ version = "0.0.32"
4
4
  description = "Common Basic Utils for Python3. By ALiwoto."
5
5
  authors = ["ALiwoto <aminnimaj@gmail.com>"]
6
6
  packages = [
@@ -0,0 +1,3 @@
1
+
2
+ __version__ = "0.0.32"
3
+
@@ -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
- if decompressed_message.lower() == "ping":
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(decompressed_message, parse_float=Decimal)
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
- api_identity = await self.get_trader_api_identity(
853
- uid=uid,
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:
@@ -47,6 +47,8 @@ class HyperLiquidClient(ExchangeBase):
47
47
  self._fav_letter = fav_letter
48
48
  self.sessions_dir = sessions_dir
49
49
 
50
+ super().__init__()
51
+
50
52
  if read_session_file:
51
53
  self.read_from_session_file(f"{sessions_dir}/{self.account_name}.hl")
52
54
 
@@ -55,6 +55,8 @@ class OkxClient(ExchangeBase):
55
55
  self._fav_letter = fav_letter
56
56
  self.sessions_dir = sessions_dir
57
57
 
58
+ super().__init__()
59
+
58
60
  if read_session_file:
59
61
  self.read_from_session_file(f"{sessions_dir}/{self.account_name}.okx")
60
62
 
@@ -1,3 +0,0 @@
1
-
2
- __version__ = "0.0.30"
3
-
File without changes
File without changes