From 77a067a22e596aff008382f06721e41a52b03a6c Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Tue, 11 Feb 2025 07:05:58 -0800 Subject: [PATCH] feat: Add direction field to TradeEntry and update trades table schema --- src/trading/journal.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/trading/journal.py b/src/trading/journal.py index 0ebd772..d8bf2be 100644 --- a/src/trading/journal.py +++ b/src/trading/journal.py @@ -262,10 +262,11 @@ def create_trades_table(): entry_date DateTime, shares UInt32, entry_price Float64, - target_price Float64, - stop_loss Float64, - strategy String, + target_price Nullable(Float64), + stop_loss Nullable(Float64), + strategy Nullable(String), order_type String, + direction String, followed_rules Nullable(UInt8), entry_reason Nullable(String), exit_price Nullable(Float64), @@ -335,7 +336,7 @@ def add_trade(trade: TradeEntry): query = f""" INSERT INTO stock_db.trades ( id, position_id, ticker, entry_date, shares, entry_price, target_price, stop_loss, - strategy, order_type, followed_rules, entry_reason, exit_price, exit_date, + strategy, order_type, direction, followed_rules, entry_reason, exit_price, exit_date, exit_reason, notes ) VALUES ( {generate_id()}, @@ -344,10 +345,11 @@ def add_trade(trade: TradeEntry): '{trade.entry_date.strftime('%Y-%m-%d %H:%M:%S')}', {trade.shares}, {trade.entry_price}, - {trade.target_price}, - {trade.stop_loss}, - '{trade.strategy}', + {trade.target_price if trade.target_price else 'NULL'}, + {trade.stop_loss if trade.stop_loss else 'NULL'}, + {f"'{trade.strategy}'" if trade.strategy else 'NULL'}, '{trade.order_type}', + '{trade.direction}', {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'},