trd-utils 0.0.40__tar.gz → 0.0.41__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.
- {trd_utils-0.0.40 → trd_utils-0.0.41}/PKG-INFO +1 -1
- {trd_utils-0.0.40 → trd_utils-0.0.41}/pyproject.toml +1 -1
- trd_utils-0.0.41/trd_utils/__init__.py +3 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/base_types.py +28 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/bx_ultra/bx_ultra_client.py +3 -2
- trd_utils-0.0.40/trd_utils/__init__.py +0 -3
- {trd_utils-0.0.40 → trd_utils-0.0.41}/LICENSE +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/README.md +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/cipher/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/common_utils/float_utils.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/common_utils/wallet_utils.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/date_utils/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/date_utils/datetime_helpers.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/README.md +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/blofin/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/blofin/blofin_client.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/blofin/blofin_types.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/bx_ultra/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/bx_ultra/bx_types.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/bx_ultra/bx_utils.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/errors.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/exchange_base.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/hyperliquid/README.md +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/hyperliquid/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/hyperliquid/hyperliquid_client.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/hyperliquid/hyperliquid_types.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/okx/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/okx/okx_client.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/okx/okx_types.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/exchanges/price_fetcher.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/html_utils/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/html_utils/html_formats.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/tradingview/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/tradingview/tradingview_client.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/tradingview/tradingview_types.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/types_helper/__init__.py +0 -0
- {trd_utils-0.0.40 → trd_utils-0.0.41}/trd_utils/types_helper/base_model.py +0 -0
|
@@ -50,6 +50,34 @@ class UnifiedPositionInfo(BaseModel):
|
|
|
50
50
|
# not all exchanges support this yet, so use it with caution.
|
|
51
51
|
last_volume: Decimal | None = None
|
|
52
52
|
|
|
53
|
+
def recalculate_pnl(self) -> tuple[Decimal, Decimal]:
|
|
54
|
+
"""
|
|
55
|
+
Recalculates the PnL based on the available data.
|
|
56
|
+
This requires `last_price`, `open_price`, `initial_margin`,
|
|
57
|
+
and `position_leverage` to be set.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
The recalculated (PnL, percentage) as a Decimal, or None if calculation
|
|
61
|
+
is not possible with the current data.
|
|
62
|
+
"""
|
|
63
|
+
if not self.position_leverage:
|
|
64
|
+
self.position_leverage = 1
|
|
65
|
+
|
|
66
|
+
if not all([self.last_price, self.open_price, self.initial_margin]):
|
|
67
|
+
# Not enough data to calculate PnL.
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
price_change_percentage = (self.last_price - self.open_price) / self.open_price
|
|
71
|
+
if self.position_side == "SHORT":
|
|
72
|
+
# For a short position, profit is made when the price goes down.
|
|
73
|
+
price_change_percentage *= -1
|
|
74
|
+
|
|
75
|
+
pnl_percentage = self.position_leverage * price_change_percentage
|
|
76
|
+
# PnL = Initial Margin * Leverage * Price Change %
|
|
77
|
+
pnl = self.initial_margin * pnl_percentage
|
|
78
|
+
self.position_pnl = pnl
|
|
79
|
+
return (pnl, pnl_percentage)
|
|
80
|
+
|
|
53
81
|
def __str__(self):
|
|
54
82
|
parts = []
|
|
55
83
|
|
|
@@ -83,7 +83,8 @@ class BXUltraClient(ExchangeBase, IPriceFetcher):
|
|
|
83
83
|
# region client parameters
|
|
84
84
|
we_api_base_host: str = "\u0061pi-\u0061pp.w\u0065-\u0061pi.com"
|
|
85
85
|
we_api_base_url: str = "https://\u0061pi-\u0061pp.w\u0065-\u0061pi.com/\u0061pi"
|
|
86
|
-
ws_we_api_base_url: str = "wss://ws-market-
|
|
86
|
+
ws_we_api_base_url: str = "wss://ws-market-sw\u0061p.w\u0065-\u0061pi.com/ws"
|
|
87
|
+
f_ws_we_api_base_url: str = "wss://f-ws-\u0061pp.w\u0065-\u0061pi.com/market"
|
|
87
88
|
original_base_host: str = "https://\u0062ing\u0078.co\u006d"
|
|
88
89
|
qq_os_base_host: str = "https://\u0061pi-\u0061pp.\u0071\u0071-os.com"
|
|
89
90
|
qq_os_base_url: str = "https://\u0061pi-\u0061pp.\u0071\u0071-os.com/\u0061pi"
|
|
@@ -283,7 +284,7 @@ class BXUltraClient(ExchangeBase, IPriceFetcher):
|
|
|
283
284
|
|
|
284
285
|
# endregion
|
|
285
286
|
###########################################################
|
|
286
|
-
# region ws-
|
|
287
|
+
# region ws last-candle methods
|
|
287
288
|
async def do_price_subscribe(self) -> None:
|
|
288
289
|
"""
|
|
289
290
|
Subscribes to the price changes coming from the exchange.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|