fix: Modify trade linking query to correctly handle ClickHouse IN clause
This commit is contained in:
parent
062be5863f
commit
a2bbd31f27
@ -346,17 +346,14 @@ def link_trades_to_plan(plan_id: int, trade_ids: List[int]) -> bool:
|
|||||||
"""Link existing trades to a trading plan"""
|
"""Link existing trades to a trading plan"""
|
||||||
with create_client() as client:
|
with create_client() as client:
|
||||||
try:
|
try:
|
||||||
# Update trades to link them to the plan
|
# Format the trade_ids properly for the IN clause
|
||||||
trade_ids_str = ", ".join(map(str, trade_ids))
|
trade_ids_str = ", ".join(str(id) for id in trade_ids)
|
||||||
query = """
|
query = f"""
|
||||||
ALTER TABLE stock_db.trades
|
ALTER TABLE stock_db.trades
|
||||||
UPDATE plan_id = %(plan_id)s
|
UPDATE plan_id = {plan_id}
|
||||||
WHERE id IN (%(trade_ids)s)
|
WHERE id IN ({trade_ids_str})
|
||||||
"""
|
"""
|
||||||
client.command(query, {
|
client.command(query)
|
||||||
'plan_id': plan_id,
|
|
||||||
'trade_ids': trade_ids_str
|
|
||||||
})
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error linking trades to plan: {e}")
|
print(f"Error linking trades to plan: {e}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user