feat: Add delete functionality for trading plans in edit mode

This commit is contained in:
Bobby (aider) 2025-02-11 18:44:33 -08:00
parent e7946667e4
commit b1e843e796
2 changed files with 21 additions and 0 deletions

View File

@ -9,6 +9,7 @@ from trading.journal import (
get_position_summary, get_latest_portfolio_value, update_portfolio_value
)
from trading.trading_plan import (
delete_trading_plan,
TradingPlan, PlanStatus, Timeframe, MarketFocus, TradeFrequency,
create_trading_plan_table, save_trading_plan, get_trading_plan,
get_all_trading_plans, update_trading_plan
@ -313,6 +314,15 @@ def trading_journal_page():
st.query_params(rerun=True)
except Exception as e:
st.error(f"Error updating trade: {str(e)}")
# Add delete button
if st.button("Delete Plan", key="delete_plan_button"):
try:
delete_trading_plan(plan.id)
st.success("Plan deleted successfully!")
st.experimental_set_query_params(rerun=True)
except Exception as e:
st.error(f"Error deleting plan: {str(e)}")
else:
st.info("No open trades to update")

View File

@ -312,6 +312,17 @@ def get_all_trading_plans(status: Optional[PlanStatus] = None) -> List[TradingPl
print(f"Error retrieving trading plans: {e}")
return []
def delete_trading_plan(plan_id: int) -> bool:
"""Delete a trading plan by ID"""
with create_client() as client:
try:
query = "ALTER TABLE trading_plans DELETE WHERE id = %(id)s"
client.command(query, {'id': plan_id})
return True
except Exception as e:
print(f"Error deleting trading plan: {e}")
return False
def update_trading_plan(plan: TradingPlan) -> bool:
"""Update an existing trading plan"""
if not plan.id: