refactor: Improve error handling in create_trading_plan_table function
This commit is contained in:
parent
a22f4a444a
commit
2a790a164a
@ -77,57 +77,59 @@ class TradingPlan:
|
|||||||
def create_trading_plan_table():
|
def create_trading_plan_table():
|
||||||
"""Create the trading plans table if it doesn't exist"""
|
"""Create the trading plans table if it doesn't exist"""
|
||||||
with create_client() as client:
|
with create_client() as client:
|
||||||
# First, try to drop the table if it exists
|
|
||||||
try:
|
try:
|
||||||
|
# Drop the table if it exists to ensure a clean creation
|
||||||
client.execute("DROP TABLE IF EXISTS trading_plans")
|
client.execute("DROP TABLE IF EXISTS trading_plans")
|
||||||
|
|
||||||
|
# Create new table with a simple structure
|
||||||
|
query = """
|
||||||
|
CREATE TABLE IF NOT EXISTS trading_plans
|
||||||
|
(
|
||||||
|
id UInt32,
|
||||||
|
plan_name String,
|
||||||
|
status String,
|
||||||
|
created_at DateTime,
|
||||||
|
updated_at DateTime,
|
||||||
|
timeframe String,
|
||||||
|
market_focus String,
|
||||||
|
entry_criteria String,
|
||||||
|
exit_criteria String,
|
||||||
|
stop_loss Float64,
|
||||||
|
profit_target Float64,
|
||||||
|
risk_reward_ratio Float64,
|
||||||
|
trade_frequency String,
|
||||||
|
market_conditions String,
|
||||||
|
indicators_used String,
|
||||||
|
entry_confirmation String,
|
||||||
|
position_sizing Float64,
|
||||||
|
maximum_drawdown Float64,
|
||||||
|
max_trades_per_day UInt32,
|
||||||
|
max_trades_per_week UInt32,
|
||||||
|
total_risk_per_trade Float64,
|
||||||
|
max_portfolio_risk Float64,
|
||||||
|
adjustments_for_drawdown String,
|
||||||
|
risk_controls String,
|
||||||
|
win_rate Float64,
|
||||||
|
average_return_per_trade Float64,
|
||||||
|
profit_factor Float64,
|
||||||
|
historical_backtest_results String,
|
||||||
|
real_trade_performance String,
|
||||||
|
improvements_needed String,
|
||||||
|
strategy_version UInt32,
|
||||||
|
plan_author String,
|
||||||
|
trade_review_notes String,
|
||||||
|
future_testing_ideas String,
|
||||||
|
sector_focus String,
|
||||||
|
fundamental_criteria String,
|
||||||
|
options_strategy_details String
|
||||||
|
)
|
||||||
|
ENGINE = TinyLog
|
||||||
|
"""
|
||||||
|
client.execute(query)
|
||||||
|
print("Table 'trading_plans' created successfully.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error dropping table: {e}")
|
print(f"Error creating table: {e}")
|
||||||
|
|
||||||
# Create new table with simpler structure
|
|
||||||
query = """
|
|
||||||
CREATE TABLE IF NOT EXISTS trading_plans
|
|
||||||
(
|
|
||||||
id UInt32,
|
|
||||||
plan_name String,
|
|
||||||
status String,
|
|
||||||
created_at DateTime,
|
|
||||||
updated_at DateTime,
|
|
||||||
timeframe String,
|
|
||||||
market_focus String,
|
|
||||||
entry_criteria String,
|
|
||||||
exit_criteria String,
|
|
||||||
stop_loss Float64,
|
|
||||||
profit_target Float64,
|
|
||||||
risk_reward_ratio Float64,
|
|
||||||
trade_frequency String,
|
|
||||||
market_conditions String,
|
|
||||||
indicators_used String,
|
|
||||||
entry_confirmation String,
|
|
||||||
position_sizing Float64,
|
|
||||||
maximum_drawdown Float64,
|
|
||||||
max_trades_per_day UInt32,
|
|
||||||
max_trades_per_week UInt32,
|
|
||||||
total_risk_per_trade Float64,
|
|
||||||
max_portfolio_risk Float64,
|
|
||||||
adjustments_for_drawdown String,
|
|
||||||
risk_controls String,
|
|
||||||
win_rate Float64,
|
|
||||||
average_return_per_trade Float64,
|
|
||||||
profit_factor Float64,
|
|
||||||
historical_backtest_results String,
|
|
||||||
real_trade_performance String,
|
|
||||||
improvements_needed String,
|
|
||||||
strategy_version UInt32,
|
|
||||||
plan_author String,
|
|
||||||
trade_review_notes String,
|
|
||||||
future_testing_ideas String,
|
|
||||||
sector_focus String,
|
|
||||||
fundamental_criteria String,
|
|
||||||
options_strategy_details String
|
|
||||||
)
|
|
||||||
ENGINE = TinyLog
|
|
||||||
"""
|
|
||||||
client.execute(query)
|
|
||||||
|
|
||||||
def save_trading_plan(plan: TradingPlan) -> int:
|
def save_trading_plan(plan: TradingPlan) -> int:
|
||||||
"""Save a trading plan to the database"""
|
"""Save a trading plan to the database"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user