mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-06-16 21:06:15 +03:00
fix(cli): consolidate duplicate get_ticker and only announce non-stock asset type
This commit is contained in:
29
cli/main.py
29
cli/main.py
@@ -505,12 +505,15 @@ def get_user_selections():
|
|||||||
console.print(
|
console.print(
|
||||||
create_question_box(
|
create_question_box(
|
||||||
"Step 1: Ticker Symbol",
|
"Step 1: Ticker Symbol",
|
||||||
"Enter the exact ticker symbol to analyze, including exchange suffix when needed (examples: SPY, CNC.TO, 7203.T, 0700.HK)",
|
"Enter the ticker, with exchange suffix when needed (e.g. SPY, 0700.HK, BTC-USD)",
|
||||||
"SPY",
|
"SPY",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
selected_ticker = get_ticker()
|
selected_ticker = get_ticker()
|
||||||
asset_type = detect_asset_type(selected_ticker)
|
asset_type = detect_asset_type(selected_ticker)
|
||||||
|
# Only announce when it's not the default stock path, to avoid printing
|
||||||
|
# "stock" on every run.
|
||||||
|
if asset_type.value != "stock":
|
||||||
console.print(
|
console.print(
|
||||||
f"[green]Detected asset type:[/green] {asset_type.value}"
|
f"[green]Detected asset type:[/green] {asset_type.value}"
|
||||||
)
|
)
|
||||||
@@ -639,29 +642,6 @@ def get_user_selections():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_ticker():
|
|
||||||
"""Get ticker symbol from user input, preserving exchange suffixes."""
|
|
||||||
# typer.prompt strips trailing dot-suffixes on some shells (e.g. 000404.SH
|
|
||||||
# collapses to 000404). questionary.text reads the raw line.
|
|
||||||
ticker = questionary.text(
|
|
||||||
"",
|
|
||||||
validate=lambda value: (
|
|
||||||
not value.strip()
|
|
||||||
or (
|
|
||||||
all(ch.isalnum() or ch in "._-^" for ch in value.strip())
|
|
||||||
and len(value.strip()) <= 32
|
|
||||||
)
|
|
||||||
)
|
|
||||||
or "Please enter a valid ticker symbol, e.g. AAPL, 000404.SZ, 0700.HK.",
|
|
||||||
).ask()
|
|
||||||
|
|
||||||
if ticker is None:
|
|
||||||
console.print("\n[red]No ticker symbol provided. Exiting...[/red]")
|
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
return (ticker.strip() or "SPY").upper()
|
|
||||||
|
|
||||||
|
|
||||||
def get_analysis_date():
|
def get_analysis_date():
|
||||||
"""Get the analysis date from user input."""
|
"""Get the analysis date from user input."""
|
||||||
while True:
|
while True:
|
||||||
@@ -1076,6 +1056,7 @@ def run_analysis(checkpoint: bool = False):
|
|||||||
|
|
||||||
# Add initial messages
|
# Add initial messages
|
||||||
message_buffer.add_message("System", f"Selected ticker: {selections['ticker']}")
|
message_buffer.add_message("System", f"Selected ticker: {selections['ticker']}")
|
||||||
|
if selections["asset_type"] != "stock":
|
||||||
message_buffer.add_message("System", f"Detected asset type: {selections['asset_type']}")
|
message_buffer.add_message("System", f"Detected asset type: {selections['asset_type']}")
|
||||||
message_buffer.add_message(
|
message_buffer.add_message(
|
||||||
"System", f"Analysis date: {selections['analysis_date']}"
|
"System", f"Analysis date: {selections['analysis_date']}"
|
||||||
|
|||||||
21
cli/utils.py
21
cli/utils.py
@@ -12,7 +12,7 @@ from tradingagents.llm_clients.model_catalog import get_model_options
|
|||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
TICKER_INPUT_EXAMPLES = "Examples: SPY, CNC.TO, 7203.T, 0700.HK"
|
TICKER_INPUT_EXAMPLES = "SPY, 0700.HK, BTC-USD"
|
||||||
|
|
||||||
ANALYST_ORDER = [
|
ANALYST_ORDER = [
|
||||||
("Market Analyst", AnalystType.MARKET),
|
("Market Analyst", AnalystType.MARKET),
|
||||||
@@ -25,10 +25,19 @@ CRYPTO_SUFFIXES = ("-USD", "-USDT", "-USDC", "-BTC", "-ETH")
|
|||||||
|
|
||||||
|
|
||||||
def get_ticker() -> str:
|
def get_ticker() -> str:
|
||||||
"""Prompt the user to enter a ticker symbol."""
|
"""Prompt the user to enter a ticker symbol, preserving exchange suffixes.
|
||||||
|
|
||||||
|
Uses questionary.text (not typer.prompt, which strips trailing dot-suffixes
|
||||||
|
like ``000404.SH`` on some shells) and validates the symbol charset so an
|
||||||
|
obvious typo is caught before the run starts.
|
||||||
|
"""
|
||||||
ticker = questionary.text(
|
ticker = questionary.text(
|
||||||
f"Enter the exact ticker symbol to analyze ({TICKER_INPUT_EXAMPLES}):",
|
f"Enter ticker symbol (e.g. {TICKER_INPUT_EXAMPLES}):",
|
||||||
validate=lambda x: len(x.strip()) > 0 or "Please enter a valid ticker symbol.",
|
validate=lambda x: (
|
||||||
|
not x.strip()
|
||||||
|
or (all(ch.isalnum() or ch in "._-^" for ch in x.strip()) and len(x.strip()) <= 32)
|
||||||
|
or "Please enter a valid ticker symbol, e.g. AAPL, 000404.SZ, 0700.HK."
|
||||||
|
),
|
||||||
style=questionary.Style(
|
style=questionary.Style(
|
||||||
[
|
[
|
||||||
("text", "fg:green"),
|
("text", "fg:green"),
|
||||||
@@ -37,11 +46,11 @@ def get_ticker() -> str:
|
|||||||
),
|
),
|
||||||
).ask()
|
).ask()
|
||||||
|
|
||||||
if not ticker:
|
if ticker is None:
|
||||||
console.print("\n[red]No ticker symbol provided. Exiting...[/red]")
|
console.print("\n[red]No ticker symbol provided. Exiting...[/red]")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
return normalize_ticker_symbol(ticker)
|
return normalize_ticker_symbol(ticker) if ticker.strip() else "SPY"
|
||||||
|
|
||||||
|
|
||||||
def normalize_ticker_symbol(ticker: str) -> str:
|
def normalize_ticker_symbol(ticker: str) -> str:
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ class TickerSymbolHandlingTests(unittest.TestCase):
|
|||||||
self.assertIn("7203.T", context)
|
self.assertIn("7203.T", context)
|
||||||
self.assertIn("exchange suffix", context)
|
self.assertIn("exchange suffix", context)
|
||||||
|
|
||||||
|
def test_single_get_ticker_no_shadow(self):
|
||||||
|
# Regression: cli/main.py had a duplicate get_ticker with an empty
|
||||||
|
# questionary prompt (rendered as a bare "?") that shadowed the
|
||||||
|
# descriptive one in cli/utils. Keep a single canonical definition.
|
||||||
|
import cli.main
|
||||||
|
import cli.utils
|
||||||
|
self.assertIs(cli.main.get_ticker, cli.utils.get_ticker)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user