From b917a0297cda6d5e0c3e325db1f8f6745d63c8c6 Mon Sep 17 00:00:00 2001 From: Jeffrey Ward Date: Wed, 11 Feb 2026 20:27:59 -0500 Subject: [PATCH] Added dashboard values --- traderex/lib/core/bots/dca_bot.ex | 24 +++++++++++++------ .../lib/traderex_web/live/dashboard_live.ex | 17 ++++++++++--- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/traderex/lib/core/bots/dca_bot.ex b/traderex/lib/core/bots/dca_bot.ex index 31d5869..84472b4 100644 --- a/traderex/lib/core/bots/dca_bot.ex +++ b/traderex/lib/core/bots/dca_bot.ex @@ -59,7 +59,7 @@ defmodule Core.Bots.DCABot do require Logger @tick_interval 60_000 # 1 minute - @drop_threshold 0.04 # 4% price drop triggers auto-buy + @drop_threshold 0.03 # 3% price drop triggers auto-buy @profit_threshold 0.20 # 20% total return triggers auto-sell # Public API @@ -175,6 +175,7 @@ defmodule Core.Bots.DCABot do bot_shares: shares, bot_cost_basis: cost_basis, current_return_pct: return_pct, + current_pl_dollars: 0.0, sell_and_stop_pending: false } else @@ -190,6 +191,7 @@ defmodule Core.Bots.DCABot do bot_shares: 0, bot_cost_basis: 0.0, current_return_pct: 0.0, + current_pl_dollars: 0.0, sell_and_stop_pending: false } end @@ -265,13 +267,18 @@ defmodule Core.Bots.DCABot do end @impl true - def handle_call(:position, _from, %{symbol: symbol, bot_shares: bot_shares, bot_cost_basis: bot_cost_basis, current_return_pct: current_return_pct, last_purchase_price: last_purchase_price, sell_and_stop_pending: sell_and_stop_pending} = state) do + def handle_call(:position, _from, %{symbol: symbol, bot_shares: bot_shares, bot_cost_basis: bot_cost_basis, current_return_pct: current_return_pct, current_pl_dollars: current_pl_dollars, last_price: last_price, last_purchase_price: last_purchase_price, sell_and_stop_pending: sell_and_stop_pending} = state) do + next_buy_price = if last_purchase_price, do: last_purchase_price * (1 - @drop_threshold), else: nil + position_info = %{ symbol: symbol, shares: bot_shares, cost_basis: bot_cost_basis, avg_price: if(bot_shares > 0, do: bot_cost_basis / bot_shares, else: 0.0), + current_price: last_price, + next_buy_price: next_buy_price, return_pct: current_return_pct, + pl_dollars: current_pl_dollars, last_purchase_price: last_purchase_price, sell_and_stop_pending: sell_and_stop_pending } @@ -319,12 +326,14 @@ defmodule Core.Bots.DCABot do price = quote.last # Calculate current return - return_pct = + {return_pct, pl_dollars} = if bot_shares > 0 && bot_cost_basis > 0 do current_value = bot_shares * price - Float.round((current_value - bot_cost_basis) / bot_cost_basis * 100, 2) + pct = Float.round((current_value - bot_cost_basis) / bot_cost_basis * 100, 2) + dollars = Float.round(current_value - bot_cost_basis, 2) + {pct, dollars} else - 0.0 + {0.0, 0.0} end # Log price and bot position status @@ -335,7 +344,7 @@ defmodule Core.Bots.DCABot do Logger.info("#{symbol} current price: $#{price} | Bot: no position") end - state = %{state | last_price: price, current_return_pct: return_pct} + state = %{state | last_price: price, current_return_pct: return_pct, current_pl_dollars: pl_dollars} # Check if we should auto-sell (position up 20%) state = maybe_auto_sell(state, price) @@ -452,7 +461,8 @@ defmodule Core.Bots.DCABot do bot_shares: 0, bot_cost_basis: 0.0, last_purchase_price: nil, - current_return_pct: 0.0 + current_return_pct: 0.0, + current_pl_dollars: 0.0 } # Save state after reset diff --git a/traderex/lib/traderex_web/live/dashboard_live.ex b/traderex/lib/traderex_web/live/dashboard_live.ex index 83790fd..6c5e313 100644 --- a/traderex/lib/traderex_web/live/dashboard_live.ex +++ b/traderex/lib/traderex_web/live/dashboard_live.ex @@ -306,13 +306,24 @@ defmodule TraderexWeb.DashboardLive do <:col :let={bot} label="Cost Basis"> {format_currency(bot.cost_basis)} + <:col :let={bot} label="Current Price"> + {format_currency(Map.get(bot, :current_price))} + <:col :let={bot} label="Avg Price"> {format_currency(bot.avg_price)} + <:col :let={bot} label="Next Buy Price"> + {format_currency(Map.get(bot, :next_buy_price))} + <:col :let={bot} label="Return"> - - {format_percent_simple(bot.return_pct)} - +
+ + {format_percent_simple(bot.return_pct)} + + + {format_currency(Map.get(bot, :pl_dollars, 0))} + +
<:col :let={bot} label="Actions">