3VVM commited on
Commit
c373874
·
verified ·
1 Parent(s): 9548588

Add Forex and Crypto symbol picker

Browse files

Market selector (Crypto/Forex) with 25 crypto coins and 20 forex pairs; custom Yahoo tickers still allowed.

Files changed (3) hide show
  1. README.md +8 -1
  2. app.py +25 -1
  3. symbols.py +78 -0
README.md CHANGED
@@ -14,4 +14,11 @@ Live MAYTHOS market analysis using Yahoo Finance through the free `yfinance`
14
  library. The Space warms the signal engine from recent Yahoo candles and then
15
  refreshes the latest Yahoo candle every 60 seconds.
16
 
17
- Supported examples: `BTC-USD`, `ETH-USD`, `AAPL`, `EURUSD=X`.
 
 
 
 
 
 
 
 
14
  library. The Space warms the signal engine from recent Yahoo candles and then
15
  refreshes the latest Yahoo candle every 60 seconds.
16
 
17
+ The symbol picker has two markets:
18
+
19
+ - **Crypto**: 25 coins, for example `BTC-USD`, `ETH-USD`, `SOL-USD`, `XRP-USD`.
20
+ - **Forex**: 20 pairs (majors, crosses, exotics), for example `EURUSD=X`,
21
+ `GBPUSD=X`, `USDJPY=X`, `USDINR=X`.
22
+
23
+ Any other Yahoo Finance ticker (such as `AAPL`) can still be typed into the
24
+ Symbol box. The full list lives in `symbols.py`.
app.py CHANGED
@@ -15,6 +15,7 @@ from typing import Any, List, Optional, Tuple
15
  import gradio as gr
16
 
17
  from maythos_engine import MAYTHOS, YahooFinanceFeed
 
18
 
19
 
20
  _LOCK = threading.RLock()
@@ -111,6 +112,12 @@ def refresh(symbol: str, interval: str, period: str,
111
  )
112
 
113
 
 
 
 
 
 
 
114
  with gr.Blocks(title="MAYTHOSLIVE — Yahoo Finance") as demo:
115
  gr.Markdown(
116
  "# MAYTHOSLIVE\n"
@@ -119,7 +126,19 @@ with gr.Blocks(title="MAYTHOSLIVE — Yahoo Finance") as demo:
119
  )
120
 
121
  with gr.Row():
122
- symbol = gr.Textbox(value="BTC-USD", label="Yahoo Finance symbol")
 
 
 
 
 
 
 
 
 
 
 
 
123
  interval = gr.Dropdown(
124
  choices=["1m", "2m", "5m", "15m", "30m", "1h", "1d"],
125
  value="1m",
@@ -152,6 +171,11 @@ with gr.Blocks(title="MAYTHOSLIVE — Yahoo Finance") as demo:
152
  refresh_button.click(refresh, inputs=inputs, outputs=outputs)
153
  demo.load(refresh, inputs=inputs, outputs=outputs)
154
 
 
 
 
 
 
155
  timer = gr.Timer(value=60)
156
  timer.tick(refresh, inputs=inputs, outputs=outputs)
157
 
 
15
  import gradio as gr
16
 
17
  from maythos_engine import MAYTHOS, YahooFinanceFeed
18
+ from symbols import DEFAULT_MARKET, DEFAULT_SYMBOL, MARKETS, symbols_for
19
 
20
 
21
  _LOCK = threading.RLock()
 
112
  )
113
 
114
 
115
+ def change_market(market: str) -> Any:
116
+ """Swap the symbol list when the market changes and select its first symbol."""
117
+ choices = symbols_for(market)
118
+ return gr.update(choices=choices, value=choices[0][1])
119
+
120
+
121
  with gr.Blocks(title="MAYTHOSLIVE — Yahoo Finance") as demo:
122
  gr.Markdown(
123
  "# MAYTHOSLIVE\n"
 
126
  )
127
 
128
  with gr.Row():
129
+ market = gr.Radio(
130
+ choices=list(MARKETS.keys()),
131
+ value=DEFAULT_MARKET,
132
+ label="Market",
133
+ )
134
+ symbol = gr.Dropdown(
135
+ choices=symbols_for(DEFAULT_MARKET),
136
+ value=DEFAULT_SYMBOL,
137
+ label="Symbol",
138
+ info="Pick from the list or type any Yahoo Finance ticker",
139
+ allow_custom_value=True,
140
+ filterable=True,
141
+ )
142
  interval = gr.Dropdown(
143
  choices=["1m", "2m", "5m", "15m", "30m", "1h", "1d"],
144
  value="1m",
 
171
  refresh_button.click(refresh, inputs=inputs, outputs=outputs)
172
  demo.load(refresh, inputs=inputs, outputs=outputs)
173
 
174
+ # Changing the market selects that market's first symbol; any symbol
175
+ # change (from the list, a typed ticker, or a market switch) refreshes.
176
+ market.change(change_market, inputs=market, outputs=symbol)
177
+ symbol.change(refresh, inputs=inputs, outputs=outputs)
178
+
179
  timer = gr.Timer(value=60)
180
  timer.tick(refresh, inputs=inputs, outputs=outputs)
181
 
symbols.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Yahoo Finance symbol catalogue for the MAYTHOSLIVE symbol picker.
2
+
3
+ Each entry is ``(display label, Yahoo Finance ticker)``. Every ticker here was
4
+ checked against Yahoo Finance 1m chart data before being added.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Dict, List, Tuple
10
+
11
+ SymbolChoice = Tuple[str, str]
12
+
13
+ FOREX_SYMBOLS: List[SymbolChoice] = [
14
+ # Majors
15
+ ("EUR/USD (EURUSD=X)", "EURUSD=X"),
16
+ ("GBP/USD (GBPUSD=X)", "GBPUSD=X"),
17
+ ("USD/JPY (USDJPY=X)", "USDJPY=X"),
18
+ ("USD/CHF (USDCHF=X)", "USDCHF=X"),
19
+ ("AUD/USD (AUDUSD=X)", "AUDUSD=X"),
20
+ ("USD/CAD (USDCAD=X)", "USDCAD=X"),
21
+ ("NZD/USD (NZDUSD=X)", "NZDUSD=X"),
22
+ # Crosses
23
+ ("EUR/GBP (EURGBP=X)", "EURGBP=X"),
24
+ ("EUR/JPY (EURJPY=X)", "EURJPY=X"),
25
+ ("GBP/JPY (GBPJPY=X)", "GBPJPY=X"),
26
+ ("EUR/CHF (EURCHF=X)", "EURCHF=X"),
27
+ ("EUR/AUD (EURAUD=X)", "EURAUD=X"),
28
+ ("AUD/JPY (AUDJPY=X)", "AUDJPY=X"),
29
+ ("CAD/JPY (CADJPY=X)", "CADJPY=X"),
30
+ ("GBP/CHF (GBPCHF=X)", "GBPCHF=X"),
31
+ # Exotics
32
+ ("USD/INR (USDINR=X)", "USDINR=X"),
33
+ ("USD/SGD (USDSGD=X)", "USDSGD=X"),
34
+ ("USD/ZAR (USDZAR=X)", "USDZAR=X"),
35
+ ("USD/MXN (USDMXN=X)", "USDMXN=X"),
36
+ ("USD/TRY (USDTRY=X)", "USDTRY=X"),
37
+ ]
38
+
39
+ CRYPTO_SYMBOLS: List[SymbolChoice] = [
40
+ ("Bitcoin (BTC-USD)", "BTC-USD"),
41
+ ("Ethereum (ETH-USD)", "ETH-USD"),
42
+ ("BNB (BNB-USD)", "BNB-USD"),
43
+ ("Solana (SOL-USD)", "SOL-USD"),
44
+ ("XRP (XRP-USD)", "XRP-USD"),
45
+ ("Cardano (ADA-USD)", "ADA-USD"),
46
+ ("Dogecoin (DOGE-USD)", "DOGE-USD"),
47
+ ("TRON (TRX-USD)", "TRX-USD"),
48
+ ("Avalanche (AVAX-USD)", "AVAX-USD"),
49
+ ("Polkadot (DOT-USD)", "DOT-USD"),
50
+ ("Chainlink (LINK-USD)", "LINK-USD"),
51
+ ("Litecoin (LTC-USD)", "LTC-USD"),
52
+ ("Bitcoin Cash (BCH-USD)", "BCH-USD"),
53
+ ("Stellar (XLM-USD)", "XLM-USD"),
54
+ ("Cosmos (ATOM-USD)", "ATOM-USD"),
55
+ ("Ethereum Classic (ETC-USD)", "ETC-USD"),
56
+ ("Shiba Inu (SHIB-USD)", "SHIB-USD"),
57
+ ("Uniswap (UNI7083-USD)", "UNI7083-USD"),
58
+ ("Toncoin (TON11419-USD)", "TON11419-USD"),
59
+ ("Polygon POL (POL28321-USD)", "POL28321-USD"),
60
+ ("NEAR Protocol (NEAR-USD)", "NEAR-USD"),
61
+ ("Aptos (APT21794-USD)", "APT21794-USD"),
62
+ ("Arbitrum (ARB11841-USD)", "ARB11841-USD"),
63
+ ("Sui (SUI20947-USD)", "SUI20947-USD"),
64
+ ("Pepe (PEPE24478-USD)", "PEPE24478-USD"),
65
+ ]
66
+
67
+ MARKETS: Dict[str, List[SymbolChoice]] = {
68
+ "Crypto": CRYPTO_SYMBOLS,
69
+ "Forex": FOREX_SYMBOLS,
70
+ }
71
+
72
+ DEFAULT_MARKET = "Crypto"
73
+ DEFAULT_SYMBOL = "BTC-USD"
74
+
75
+
76
+ def symbols_for(market: str) -> List[SymbolChoice]:
77
+ """Return the symbol choices for a market, falling back to the default."""
78
+ return MARKETS.get(market, MARKETS[DEFAULT_MARKET])