refactor: Add error handling to get_all_trading_plans function
This commit is contained in:
parent
2a790a164a
commit
41de719250
@ -255,17 +255,22 @@ def get_trading_plan(plan_id: int) -> Optional[TradingPlan]:
|
|||||||
def get_all_trading_plans(status: Optional[PlanStatus] = None) -> List[TradingPlan]:
|
def get_all_trading_plans(status: Optional[PlanStatus] = None) -> List[TradingPlan]:
|
||||||
"""Get all trading plans, optionally filtered by status"""
|
"""Get all trading plans, optionally filtered by status"""
|
||||||
with create_client() as client:
|
with create_client() as client:
|
||||||
query = "SELECT * FROM trading_plans"
|
try:
|
||||||
params = {}
|
query = "SELECT * FROM trading_plans"
|
||||||
|
params = {}
|
||||||
if status:
|
|
||||||
query += " WHERE status = %(status)s"
|
|
||||||
params['status'] = status.value
|
|
||||||
|
|
||||||
query += " ORDER BY updated_at DESC"
|
if status:
|
||||||
|
query += " WHERE status = %(status)s"
|
||||||
|
params['status'] = status.value
|
||||||
|
|
||||||
|
query += " ORDER BY updated_at DESC"
|
||||||
|
|
||||||
|
results = client.execute(query, params)
|
||||||
|
return [get_trading_plan(result[0]) for result in results]
|
||||||
|
|
||||||
results = client.execute(query, params)
|
except Exception as e:
|
||||||
return [get_trading_plan(result[0]) for result in results]
|
print(f"Error retrieving trading plans: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
def update_trading_plan(plan: TradingPlan) -> bool:
|
def update_trading_plan(plan: TradingPlan) -> bool:
|
||||||
"""Update an existing trading plan"""
|
"""Update an existing trading plan"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user