Add account data fetching and display balances in dashboard
This commit is contained in:
@ -77,14 +77,13 @@ class PositionMonitor:
|
||||
output_lines.append("\n--- Perpetuals Account Summary ---")
|
||||
output_lines.append(f" Account Value: ${account_value:,.2f} | Margin Used: ${margin_used:,.2f} | Utilization: {utilization:.2f}%")
|
||||
|
||||
# --- 2. Spot Balances Summary ---
|
||||
# --- 2. Spot Balances Table ---
|
||||
output_lines.append("\n--- Spot Balances ---")
|
||||
spot_balances = spot_state.get('balances', [])
|
||||
if not spot_balances:
|
||||
output_lines.append(" No spot balances found.")
|
||||
else:
|
||||
balances_str = ", ".join([f"{b.get('coin')}: {float(b.get('total', 0)):,.4f}" for b in spot_balances if float(b.get('total', 0)) > 0])
|
||||
output_lines.append(f" {balances_str}")
|
||||
self.build_spot_balances_table(spot_balances, output_lines)
|
||||
|
||||
# --- 3. Open Positions Table ---
|
||||
output_lines.append("\n--- Open Perpetual Positions ---")
|
||||
@ -106,6 +105,23 @@ class PositionMonitor:
|
||||
self._lines_printed = len(output_lines)
|
||||
sys.stdout.flush()
|
||||
|
||||
def build_spot_balances_table(self, spot_balances: list, output_lines: list):
|
||||
"""Builds the text for the spot balances table."""
|
||||
header = f"| {'Coin':<10} | {'Total':>18} |"
|
||||
output_lines.append(header)
|
||||
output_lines.append("-" * len(header))
|
||||
|
||||
for balance in spot_balances:
|
||||
coin = balance.get('coin', 'Unknown')
|
||||
total = float(balance.get('total', 0))
|
||||
|
||||
coin_str = f"{coin:<10}"
|
||||
total_str = f"{total:>18,.4f}"
|
||||
|
||||
output_lines.append(f"| {coin_str} | {total_str} |")
|
||||
|
||||
output_lines.append("-" * len(header))
|
||||
|
||||
def build_positions_table(self, positions: list, coin_to_strategy_map: dict, output_lines: list):
|
||||
"""Builds the text for the positions summary table."""
|
||||
header = f"| {'Strategy':<25} | {'Coin':<6} | {'Side':<5} | {'Size':>15} | {'Entry Price':>12} | {'Mark Price':>12} | {'PNL':>15} | {'Leverage':>10} |"
|
||||
|
||||
Reference in New Issue
Block a user