Add EUR/USD support and 4-button Telegram scanner

Add EURUSD pair with dynamic pair info lookup. Telegram bot now shows
4 scan buttons: EUR/USD 15M, EUR/USD 1H, USD/JPY 15M, USD/JPY 1H.
Each indicator displays directional arrows in the message output.
Price formatting adapts per pair (5dp for EUR, 3dp for JPY).
This commit is contained in:
Harwinder
2026-05-10 23:49:36 -04:00
parent 7ccd8c4b04
commit a708609f8b
3 changed files with 87 additions and 50 deletions
+63 -35
View File
@@ -28,7 +28,7 @@ from telegram.ext import (
ContextTypes,
)
from config import PlatformConfig, SignalStrength
from config import PlatformConfig, SignalStrength, Timeframe, EURUSD, USDJPY, PAIR_INFO
from signal_aggregator import SignalAggregator, SignalReport
# ── Force UTF-8 on Windows ────────────────────────────────────────────
@@ -46,7 +46,14 @@ logger = logging.getLogger("telegram_bot")
TOKEN = os.environ.get("TELEGRAM_TOKEN", "8228251480:AAFW2OAyQ2idMicql2t_CIXk1r9-qfRTfNE")
SCAN_CB = "scan_signal"
SCAN_BUTTONS = [
{"cb": "scan_eurusd_m15", "symbol": EURUSD, "tf": Timeframe.M15, "label": "EUR/USD 15M"},
{"cb": "scan_eurusd_h1", "symbol": EURUSD, "tf": Timeframe.H1, "label": "EUR/USD 1H"},
{"cb": "scan_usdjpy_m15", "symbol": USDJPY, "tf": Timeframe.M15, "label": "USD/JPY 15M"},
{"cb": "scan_usdjpy_h1", "symbol": USDJPY, "tf": Timeframe.H1, "label": "USD/JPY 1H"},
]
SCAN_LOOKUP = {b["cb"]: b for b in SCAN_BUTTONS}
_executor = ThreadPoolExecutor(max_workers=2)
@@ -80,14 +87,19 @@ def _mtf_line(report: SignalReport) -> str:
return " | ".join(parts)
def _compact_reasons(reasons: list[str], n: int = 3) -> list[str]:
out = []
for r in reasons[:n]:
s = r.replace("STRONG: ", "")
if " | " in s:
s = s.split(" | ", 1)[0]
out.append(s.strip())
return out
_ARROW = {
SignalStrength.STRONG_BUY: "⬆️",
SignalStrength.BUY: "↗️",
SignalStrength.NEUTRAL: "➡️",
SignalStrength.SELL: "↘️",
SignalStrength.STRONG_SELL: "⬇️",
}
def _indicator_line(name: str, ind) -> str:
arrow = _ARROW.get(ind.signal, "➡️")
short = ind.description.split(" | ")[0] if " | " in ind.description else ind.description
return f"{arrow} *{ind.name}*: {short}"
def format_signal_message(report: SignalReport) -> str:
@@ -102,10 +114,10 @@ def format_signal_message(report: SignalReport) -> str:
# Header
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
lines += [
f"🔍 *USD/JPY Signal Analysis*",
f"🔍 *{report.display_name} Signal Analysis* ({report.primary_analysis.timeframe if report.primary_analysis else ''})",
f"🕐 {now}",
"",
f"💰 Price: *{report.current_price:.3f}*",
f"💰 Price: *{report.current_price:.5f}*" if report.current_price < 10 else f"💰 Price: *{report.current_price:.3f}*",
f"📊 Regime: {report.market_regime.replace('_', ' ').title()} | Vol: {report.volatility_regime}",
"",
"━━━━━━━━━━━━━━━━━━━━",
@@ -119,15 +131,13 @@ def format_signal_message(report: SignalReport) -> str:
if mtf:
lines += ["", f"📈 *MTF*: {mtf}"]
# Reasons
bulls = _compact_reasons(report.bullish_reasons)
bears = _compact_reasons(report.bearish_reasons)
if bulls or bears:
lines.append("")
for r in bulls:
lines.append(f"✅ {r}")
for r in bears:
lines.append(f"❌ {r}")
# Indicator breakdown with arrows
if report.primary_analysis:
lines += ["", "━━━━━━━━━━━━━━━━━━━━", "📋 *Indicators*"]
for name, ind in report.primary_analysis.indicators.items():
if name.startswith("_") or ind.weight == 0:
continue
lines.append(_indicator_line(name, ind))
# Warnings
if report.warnings:
@@ -161,29 +171,44 @@ def format_signal_message(report: SignalReport) -> str:
# ── Keyboard helper ───────────────────────────────────────────────────
def scan_keyboard() -> InlineKeyboardMarkup:
return InlineKeyboardMarkup([[
InlineKeyboardButton("🔍 Scan Signal", callback_data=SCAN_CB)
]])
return InlineKeyboardMarkup([
[InlineKeyboardButton(f"🔍 {b['label']}", callback_data=b["cb"])
for b in SCAN_BUTTONS[:2]],
[InlineKeyboardButton(f"🔍 {b['label']}", callback_data=b["cb"])
for b in SCAN_BUTTONS[2:]],
])
# ── Async signal runner (offloaded to thread pool) ────────────────────
def _run_signal_sync() -> SignalReport:
TF_CONFIRMATIONS = {
Timeframe.M15: [Timeframe.M5, Timeframe.H1],
Timeframe.H1: [Timeframe.M15, Timeframe.H4],
}
def _run_signal_sync(symbol: str, timeframe: Timeframe) -> SignalReport:
config = PlatformConfig()
config.symbol = symbol
config.primary_timeframe = timeframe
config.confirmation_timeframes = TF_CONFIRMATIONS.get(
timeframe, [Timeframe.M15, Timeframe.H4]
)
aggregator = SignalAggregator(config)
return aggregator.analyze_pair()
return aggregator.analyze_pair(symbol=symbol)
async def run_signal(loop: asyncio.AbstractEventLoop) -> SignalReport:
return await loop.run_in_executor(_executor, _run_signal_sync)
async def run_signal(symbol: str, timeframe: Timeframe) -> SignalReport:
loop = asyncio.get_event_loop()
return await loop.run_in_executor(_executor, _run_signal_sync, symbol, timeframe)
# ── Handlers ──────────────────────────────────────────────────────────
async def cmd_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
text = (
"👋 *ForexBot2 — USD/JPY Signal Intelligence*\n\n"
"Press the button below to fetch a live signal.\n"
"👋 *ForexBot2 — Signal Intelligence*\n\n"
"Pick a pair and timeframe to scan.\n"
"Strong signals include a full trade setup with entry, SL and TP."
)
await update.message.reply_text(
@@ -197,15 +222,18 @@ async def cb_scan(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
query = update.callback_query
await query.answer()
# Replace button with spinner while scanning
btn = SCAN_LOOKUP.get(query.data)
if not btn:
return
pair_display = btn["label"]
await query.edit_message_text(
"⏳ Scanning USD/JPY…",
f"⏳ Scanning {pair_display}…",
parse_mode=ParseMode.MARKDOWN,
)
loop = asyncio.get_event_loop()
try:
report = await run_signal(loop)
report = await run_signal(btn["symbol"], btn["tf"])
text = format_signal_message(report)
except Exception as exc:
logger.exception("Signal scan failed")
@@ -233,7 +261,7 @@ def main() -> None:
)
app.add_handler(CommandHandler("start", cmd_start))
app.add_handler(CallbackQueryHandler(cb_scan, pattern=f"^{SCAN_CB}$"))
app.add_handler(CallbackQueryHandler(cb_scan, pattern="^scan_"))
logger.info("Bot running — press Ctrl+C to stop")
app.run_polling(allowed_updates=Update.ALL_TYPES)