jetpackjules Claude commited on
Commit
0ba43cc
Β·
1 Parent(s): 6ca2db5

Fix Investment Performance table to show all trading symbols

Browse files

- Modified refresh_investment_performance_table() to process ALL symbols from order history
- No longer limited to just IPOs marked as "INVESTED" in VM data
- Now shows comprehensive trading performance for EGG, SLDE, MENS, and all other traded symbols
- Maintains IPO price lookup when available for reference
- Sorts symbols alphabetically for better organization

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +30 -44
__pycache__/app.cpython-310.pyc ADDED
Binary file (34.3 kB). View file
 
app.py CHANGED
@@ -344,7 +344,7 @@ def get_order_history():
344
  return []
345
 
346
  def refresh_investment_performance_table():
347
- """Refresh investment performance table with P&L for invested IPOs"""
348
  # Get IPO data and orders
349
  ipos = fetch_from_vm('ipos?limit=100', [])
350
  orders = get_order_history()
@@ -353,39 +353,36 @@ def refresh_investment_performance_table():
353
  # Create proper empty DataFrame with correct column names
354
  columns = ['Symbol', 'Status', 'IPO Price', 'Buy Price', 'Current Price', 'Quantity', 'Investment', 'Current Value', 'P&L ($)', 'P&L (%)']
355
 
356
- if not ipos:
 
 
357
  return pd.DataFrame(columns=columns)
358
 
359
- # Debug: Let's see what we're getting
360
- logger.info(f"Found {len(ipos)} total IPOs")
361
- invested_symbols = [ipo for ipo in ipos if ipo.get('investment_status') == 'INVESTED']
362
- logger.info(f"Found {len(invested_symbols)} invested IPOs")
363
- logger.info(f"Found {len(orders)} total orders")
364
 
365
- invested_data = []
366
 
367
- if not invested_symbols:
368
- # No invested IPOs found, add a debug row to see what's happening
369
- invested_data.append({
370
- 'Symbol': "πŸ” DEBUG",
371
- 'Status': f"Found {len(ipos)} IPOs total",
372
- 'IPO Price': "Check logs",
373
- 'Buy Price': "N/A",
374
- 'Current Price': "N/A",
375
- 'Quantity': "0",
376
- 'Investment': "$0.00",
377
- 'Current Value': "N/A",
378
- 'P&L ($)': "$0.00",
379
- 'P&L (%)': "0.00%"
380
- })
381
- return pd.DataFrame(invested_data)
382
 
383
- # Simple version first - just show the IPOs that were invested in
384
- for ipo in invested_symbols:
385
- symbol = ipo.get('symbol', 'N/A')
386
- ipo_price = ipo.get('trading_price', 0)
387
-
388
- # Check if we have order data for this symbol
389
  symbol_orders = [o for o in orders if o.symbol == symbol]
390
 
391
  if symbol_orders:
@@ -401,6 +398,9 @@ def refresh_investment_performance_table():
401
  total_sold = sum(float(o.filled_qty or 0) for o in sell_orders)
402
  current_qty = total_bought - total_sold
403
 
 
 
 
404
  if current_qty > 0:
405
  # Still holding
406
  status = "🟦 HOLDING"
@@ -433,7 +433,7 @@ def refresh_investment_performance_table():
433
  invested_data.append({
434
  'Symbol': f"{pl_indicator} {symbol}",
435
  'Status': status,
436
- 'IPO Price': f"${ipo_price}" if ipo_price != 'N/A' else 'N/A',
437
  'Buy Price': f"${avg_buy_price:.2f}",
438
  'Current Price': f"${current_price:.2f}" if current_price > 0 else "N/A",
439
  'Quantity': f"{current_qty:.0f}",
@@ -442,20 +442,6 @@ def refresh_investment_performance_table():
442
  'P&L ($)': f"${pl_dollars:+.2f}",
443
  'P&L (%)': f"{pl_percent:+.2f}%"
444
  })
445
- else:
446
- # No order data found, show placeholder
447
- invested_data.append({
448
- 'Symbol': f"❓ {symbol}",
449
- 'Status': "πŸ” NO ORDERS",
450
- 'IPO Price': f"${ipo_price}" if ipo_price != 'N/A' else 'N/A',
451
- 'Buy Price': "N/A",
452
- 'Current Price': "N/A",
453
- 'Quantity': "0",
454
- 'Investment': "$0.00",
455
- 'Current Value': "N/A",
456
- 'P&L ($)': "$0.00",
457
- 'P&L (%)': "0.00%"
458
- })
459
 
460
  return pd.DataFrame(invested_data)
461
 
 
344
  return []
345
 
346
  def refresh_investment_performance_table():
347
+ """Refresh investment performance table with P&L for all trading symbols"""
348
  # Get IPO data and orders
349
  ipos = fetch_from_vm('ipos?limit=100', [])
350
  orders = get_order_history()
 
353
  # Create proper empty DataFrame with correct column names
354
  columns = ['Symbol', 'Status', 'IPO Price', 'Buy Price', 'Current Price', 'Quantity', 'Investment', 'Current Value', 'P&L ($)', 'P&L (%)']
355
 
356
+ logger.info(f"Found {len(orders)} total orders for performance analysis")
357
+
358
+ if not orders:
359
  return pd.DataFrame(columns=columns)
360
 
361
+ # Get all unique symbols from order history
362
+ symbols_traded = set()
363
+ for order in orders:
364
+ if hasattr(order, 'symbol') and order.symbol:
365
+ symbols_traded.add(order.symbol)
366
 
367
+ logger.info(f"Found {len(symbols_traded)} unique symbols traded: {list(symbols_traded)}")
368
 
369
+ # Create IPO price lookup from VM data
370
+ ipo_price_lookup = {}
371
+ for ipo in ipos:
372
+ symbol = ipo.get('symbol', '')
373
+ if symbol:
374
+ try:
375
+ price = float(ipo.get('trading_price', 0))
376
+ if price > 0:
377
+ ipo_price_lookup[symbol] = price
378
+ except (ValueError, TypeError):
379
+ pass
 
 
 
 
380
 
381
+ invested_data = []
382
+
383
+ # Process each symbol that was traded
384
+ for symbol in sorted(symbols_traded):
385
+ # Get all orders for this symbol
 
386
  symbol_orders = [o for o in orders if o.symbol == symbol]
387
 
388
  if symbol_orders:
 
398
  total_sold = sum(float(o.filled_qty or 0) for o in sell_orders)
399
  current_qty = total_bought - total_sold
400
 
401
+ # Get IPO price if available
402
+ ipo_price = ipo_price_lookup.get(symbol, 0)
403
+
404
  if current_qty > 0:
405
  # Still holding
406
  status = "🟦 HOLDING"
 
433
  invested_data.append({
434
  'Symbol': f"{pl_indicator} {symbol}",
435
  'Status': status,
436
+ 'IPO Price': f"${ipo_price:.2f}" if ipo_price > 0 else 'N/A',
437
  'Buy Price': f"${avg_buy_price:.2f}",
438
  'Current Price': f"${current_price:.2f}" if current_price > 0 else "N/A",
439
  'Quantity': f"{current_qty:.0f}",
 
442
  'P&L ($)': f"${pl_dollars:+.2f}",
443
  'P&L (%)': f"{pl_percent:+.2f}%"
444
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
 
446
  return pd.DataFrame(invested_data)
447