diff --git a/src/trading/journal.py b/src/trading/journal.py index d863bc0..67451ad 100644 --- a/src/trading/journal.py +++ b/src/trading/journal.py @@ -346,12 +346,13 @@ def get_order_type() -> Optional[str]: print("Invalid choice. Please try again.") def add_trade(trade: TradeEntry): + """Add a new trade to the database""" with create_client() as client: query = f""" INSERT INTO stock_db.trades ( - id, position_id, ticker, entry_date, shares, entry_price, target_price, stop_loss, - strategy, order_type, direction, followed_rules, entry_reason, exit_price, exit_date, - exit_reason, notes + id, position_id, ticker, entry_date, shares, entry_price, target_price, + stop_loss, strategy, order_type, direction, followed_rules, entry_reason, + exit_price, exit_date, exit_reason, notes ) VALUES ( {generate_id()}, '{trade.position_id}', @@ -363,11 +364,11 @@ def add_trade(trade: TradeEntry): {trade.stop_loss if trade.stop_loss else 'NULL'}, {f"'{trade.strategy}'" if trade.strategy else 'NULL'}, '{trade.order_type}', - '{trade.direction}', + '{trade.direction.lower()}', # Ensure direction is stored in lowercase {1 if trade.followed_rules else 0}, {f"'{trade.entry_reason}'" if trade.entry_reason else 'NULL'}, - {trade.exit_price if trade.exit_price else 'NULL'}, - {f"'{trade.exit_date.strftime('%Y-%m-%d %H:%M:%S')}'" if trade.exit_date else 'NULL'}, + NULL, + NULL, {f"'{trade.exit_reason}'" if trade.exit_reason else 'NULL'}, {f"'{trade.notes}'" if trade.notes else 'NULL'} )