refactor: Simplify main menu logic with function calls
This commit is contained in:
parent
3425539781
commit
0b40142bfb
104
src/main.py
104
src/main.py
@ -8,108 +8,30 @@ from screener.scanner_controller import run_technical_scanner
|
||||
from screener.canslim_controller import run_canslim_screener
|
||||
from trading.main import main as trading_main
|
||||
|
||||
def main():
|
||||
create_trades_table() # Ensure table exists
|
||||
|
||||
while True:
|
||||
print("\nTrading Journal")
|
||||
print("1. Add New Trade")
|
||||
print("2. Update Existing Trade")
|
||||
print("3. View Open Trades")
|
||||
print("4. View Trade History")
|
||||
print("5. Return to Main Menu")
|
||||
|
||||
print_main_menu()
|
||||
choice = input("\nSelect an option (1-5): ")
|
||||
|
||||
if choice == "1":
|
||||
ticker = input("Enter ticker symbol: ").upper()
|
||||
shares = int(input("Enter number of shares: "))
|
||||
entry_price = float(input("Enter entry price: "))
|
||||
target_price = float(input("Enter target price: "))
|
||||
stop_loss = float(input("Enter stop loss: "))
|
||||
strategy = input("Enter strategy name: ")
|
||||
followed_rules = input("Did you follow your rules? (y/n): ").lower() == 'y'
|
||||
entry_reason = input("Enter entry reason (optional): ") or None
|
||||
notes = input("Additional notes (optional): ") or None
|
||||
|
||||
trade = TradeEntry(
|
||||
ticker=ticker,
|
||||
entry_date=datetime.datetime.now(),
|
||||
shares=shares,
|
||||
entry_price=entry_price,
|
||||
target_price=target_price,
|
||||
stop_loss=stop_loss,
|
||||
strategy=strategy,
|
||||
followed_rules=followed_rules,
|
||||
entry_reason=entry_reason,
|
||||
notes=notes
|
||||
)
|
||||
|
||||
add_trade(trade)
|
||||
print(f"\nExpected Profit: ${trade.expected_profit_loss:.2f}")
|
||||
print(f"Maximum Loss: ${trade.max_loss:.2f}")
|
||||
print("Trade added successfully!")
|
||||
run_canslim_screener()
|
||||
|
||||
elif choice == "2":
|
||||
open_trades = get_open_trades()
|
||||
if not open_trades:
|
||||
print("No open trades to update.")
|
||||
continue
|
||||
|
||||
print("\nOpen Trades:")
|
||||
for trade in open_trades:
|
||||
print(f"{trade['id']}: {trade['ticker']} - Entered at ${trade['entry_price']}")
|
||||
|
||||
trade_id = int(input("\nEnter trade ID to update: "))
|
||||
exit_price = float(input("Enter exit price: "))
|
||||
followed_rules = input("Did you follow your rules? (y/n): ").lower() == 'y'
|
||||
exit_reason = input("Enter exit reason: ")
|
||||
notes = input("Additional notes (optional): ") or None
|
||||
|
||||
update_trade_exit(
|
||||
trade_id=trade_id,
|
||||
exit_price=exit_price,
|
||||
exit_date=datetime.datetime.now(),
|
||||
followed_rules=followed_rules,
|
||||
exit_reason=exit_reason,
|
||||
notes=notes
|
||||
)
|
||||
print("Trade updated successfully!")
|
||||
print_technical_scanner_menu()
|
||||
scanner_choice = input("\nEnter your choice (1-3): ")
|
||||
run_technical_scanner(scanner_choice)
|
||||
|
||||
elif choice == "3":
|
||||
open_trades = get_open_trades()
|
||||
if not open_trades:
|
||||
print("No open trades found.")
|
||||
else:
|
||||
print("\nOpen Trades:")
|
||||
for trade in open_trades:
|
||||
print(f"\nTicker: {trade['ticker']}")
|
||||
print(f"Entry Date: {trade['entry_date']}")
|
||||
print(f"Shares: {trade['shares']}")
|
||||
print(f"Entry Price: ${trade['entry_price']}")
|
||||
print(f"Target: ${trade['target_price']}")
|
||||
print(f"Stop Loss: ${trade['stop_loss']}")
|
||||
print(f"Strategy: {trade['strategy']}")
|
||||
|
||||
trading_main()
|
||||
|
||||
elif choice == "4":
|
||||
history = get_trade_history()
|
||||
if not history:
|
||||
print("No trade history found.")
|
||||
else:
|
||||
print("\nTrade History:")
|
||||
for trade in history:
|
||||
profit_loss = (trade['exit_price'] - trade['entry_price']) * trade['shares']
|
||||
print(f"\nTicker: {trade['ticker']}")
|
||||
print(f"Entry: ${trade['entry_price']} on {trade['entry_date']}")
|
||||
print(f"Exit: ${trade['exit_price']} on {trade['exit_date']}")
|
||||
print(f"P/L: ${profit_loss:.2f}")
|
||||
print(f"Strategy: {trade['strategy']}")
|
||||
if trade['notes']:
|
||||
print(f"Notes: {trade['notes']}")
|
||||
print("-" * 40)
|
||||
|
||||
journal_menu()
|
||||
|
||||
elif choice == "5":
|
||||
print("Exiting...")
|
||||
break
|
||||
|
||||
else:
|
||||
print("Invalid choice. Please try again.")
|
||||
|
||||
def main():
|
||||
print("\nStock Analysis System")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user