Remove chart from /signal, explain score bar, and optimize API calls to run concurrently
This commit is contained in:
@@ -196,10 +196,18 @@ async def chart_cmd(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
async def signal_cmd(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
async def signal_cmd(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
try:
|
try:
|
||||||
pair, tf = _parse_pair_tf(ctx.args)
|
pair, tf = _parse_pair_tf(ctx.args)
|
||||||
df = await fetch_ohlc(pair, tf)
|
|
||||||
|
|
||||||
htf = HTF_OF.get(tf)
|
htf = HTF_OF.get(tf)
|
||||||
htf_df = await fetch_ohlc(pair, htf) if htf and htf != tf else None
|
|
||||||
|
# Fetch both timeframes concurrently to double the network speed
|
||||||
|
import asyncio
|
||||||
|
if htf and htf != tf:
|
||||||
|
df, htf_df = await asyncio.gather(
|
||||||
|
fetch_ohlc(pair, tf),
|
||||||
|
fetch_ohlc(pair, htf)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
df = await fetch_ohlc(pair, tf)
|
||||||
|
htf_df = None
|
||||||
|
|
||||||
report = analyze(df, htf_df)
|
report = analyze(df, htf_df)
|
||||||
price = report["price"]
|
price = report["price"]
|
||||||
@@ -221,12 +229,12 @@ async def signal_cmd(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
"",
|
"",
|
||||||
*_fmt_group(report["readings"], "volatility", "*-- VOLATILITY*"),
|
*_fmt_group(report["readings"], "volatility", "*-- VOLATILITY*"),
|
||||||
"",
|
"",
|
||||||
# Score line — bar + plain-English label so the number has context
|
"*-- FINAL VERDICT --*",
|
||||||
f"`[{_score_bar(report['score'], report['max_score'])}]` "
|
f"`[{_score_bar(report['score'], report['max_score'])}]` "
|
||||||
f"{ascii_indicator(verdict)} *{verdict}*",
|
f"{ascii_indicator(verdict)} *{verdict}*",
|
||||||
f"Score `{report['score']:+d}` of +/-`{report['max_score']}` "
|
f"Score `{report['score']:+d}` of maximum +/-`{report['max_score']}`",
|
||||||
f"({_score_label(report['score'], report['max_score'])} signal, "
|
f"_{report['confidence']}% overall strength ({_score_label(report['score'], report['max_score'])} signal)_",
|
||||||
f"{report['confidence']}% of max)",
|
"> _The bar above visualizes the signal strength. The more # symbols, the stronger the conviction. +20 is maximum Buy, -20 is maximum Sell._",
|
||||||
]
|
]
|
||||||
|
|
||||||
if report["context"]:
|
if report["context"]:
|
||||||
@@ -249,9 +257,8 @@ async def signal_cmd(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
f"_ATR-based zones:_ SL `{sl}` | TP `{tp}`",
|
f"_ATR-based zones:_ SL `{sl}` | TP `{tp}`",
|
||||||
]
|
]
|
||||||
|
|
||||||
caption = "\n".join(lines) + DISCLAIMER
|
text = "\n".join(lines) + DISCLAIMER
|
||||||
img = generate_chart(df, pair, tf, verdict=verdict, confidence=report["confidence"])
|
await update.message.reply_text(text, parse_mode="Markdown")
|
||||||
await update.message.reply_photo(img, caption=caption, parse_mode="Markdown")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("signal_cmd failed")
|
logger.exception("signal_cmd failed")
|
||||||
await _reply(update, f"Error: {e}")
|
await _reply(update, f"Error: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user