feat(manager): display Total PnL (Unrealized + Fees) in logs
This commit is contained in:
@ -116,7 +116,7 @@ WETH_ADDRESS = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
|
||||
USDC_ADDRESS = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
|
||||
|
||||
STATUS_FILE = "hedge_status.json"
|
||||
MONITOR_INTERVAL_SECONDS = 60
|
||||
MONITOR_INTERVAL_SECONDS = 666
|
||||
CLOSE_POSITION_ENABLED = True
|
||||
OPEN_POSITION_ENABLED = True
|
||||
REBALANCE_ON_CLOSE_BELOW_RANGE = True
|
||||
@ -735,8 +735,31 @@ def main():
|
||||
except Exception as e:
|
||||
logger.debug(f"Fee simulation failed for {token_id}: {e}")
|
||||
|
||||
fee_text = f" | Fees: {unclaimed0:.4f}/{unclaimed1:.2f} (~${total_fees_usd:.2f})"
|
||||
logger.info(f"Position {token_id}: {status_msg} | Price: {current_price:.4f} [{lower_price:.4f} - {upper_price:.4f}]{fee_text}")
|
||||
# Calculate Total PnL (Fees + Price Appreciation/Depreciation)
|
||||
# We need the initial investment value (target_value)
|
||||
initial_value = Decimal(str(active_auto_pos.get('target_value', 0)))
|
||||
|
||||
# Estimate Current Position Liquidity Value (approximate)
|
||||
# For exact value, we'd need amounts for liquidity at current tick
|
||||
# But we can approximate using the target value logic reversed or just assume target ~ current if range is tight and price is close.
|
||||
# BETTER: Use get_amounts_for_liquidity with current price to get current holdings
|
||||
|
||||
curr_amt0_wei, curr_amt1_wei = get_amounts_for_liquidity(
|
||||
pool_data['sqrtPriceX96'],
|
||||
get_sqrt_ratio_at_tick(tick_lower),
|
||||
get_sqrt_ratio_at_tick(tick_upper),
|
||||
pos_details['liquidity']
|
||||
)
|
||||
curr_amt0 = Decimal(curr_amt0_wei) / Decimal(10**pos_details['token0_decimals'])
|
||||
curr_amt1 = Decimal(curr_amt1_wei) / Decimal(10**pos_details['token1_decimals'])
|
||||
|
||||
current_pos_value_usd = (curr_amt0 * current_price) + curr_amt1
|
||||
|
||||
pnl_unrealized = current_pos_value_usd - initial_value
|
||||
total_pnl_usd = pnl_unrealized + total_fees_usd
|
||||
|
||||
pnl_text = f" | TotPnL: ${total_pnl_usd:.2f} (Fees: ${total_fees_usd:.2f})"
|
||||
logger.info(f"Position {token_id}: {status_msg} | Price: {current_price:.4f} [{lower_price:.4f} - {upper_price:.4f}]{pnl_text}")
|
||||
|
||||
if not in_range and CLOSE_POSITION_ENABLED:
|
||||
logger.warning(f"🛑 Closing Position {token_id} (Out of Range)")
|
||||
|
||||
Reference in New Issue
Block a user