feat(kpi): integrate live Hyperliquid equity tracking for accurate NAV
This commit is contained in:
@ -487,14 +487,21 @@ class ScalperHedger:
|
||||
def get_current_position(self, coin: str) -> Dict[str, Decimal]:
|
||||
try:
|
||||
user_state = self.info.user_state(self.vault_address or self.account.address)
|
||||
|
||||
# Extract total account equity (marginSummary.accountValue)
|
||||
equity = Decimal("0")
|
||||
if "marginSummary" in user_state and "accountValue" in user_state["marginSummary"]:
|
||||
equity = to_decimal(user_state["marginSummary"]["accountValue"])
|
||||
|
||||
for pos in user_state["assetPositions"]:
|
||||
if pos["position"]["coin"] == coin:
|
||||
return {
|
||||
'size': to_decimal(pos["position"]["szi"]),
|
||||
'pnl': to_decimal(pos["position"]["unrealizedPnl"])
|
||||
'pnl': to_decimal(pos["position"]["unrealizedPnl"]),
|
||||
'equity': equity
|
||||
}
|
||||
return {'size': Decimal("0"), 'pnl': Decimal("0")}
|
||||
except: return {'size': Decimal("0"), 'pnl': Decimal("0")}
|
||||
return {'size': Decimal("0"), 'pnl': Decimal("0"), 'equity': equity}
|
||||
except: return {'size': Decimal("0"), 'pnl': Decimal("0"), 'equity': Decimal("0")}
|
||||
|
||||
def get_open_orders(self) -> List[Dict]:
|
||||
try:
|
||||
@ -757,6 +764,12 @@ class ScalperHedger:
|
||||
pos_data = self.get_current_position(COIN_SYMBOL)
|
||||
current_size = pos_data['size']
|
||||
current_pnl = pos_data['pnl']
|
||||
current_equity = pos_data['equity']
|
||||
|
||||
# Update JSON with latest equity stats
|
||||
update_position_stats(self.active_position_id, {
|
||||
"hedge_equity_usd": float(current_equity)
|
||||
})
|
||||
|
||||
# 3. Calculate Logic
|
||||
calc = self.strategy.calculate_rebalance(price, current_size)
|
||||
|
||||
Reference in New Issue
Block a user