feat: live execution — replay approach для ORB+FVG+Engulfing
config.yaml + config.py: конфигурация с YAML + env var overrides state.py: SQLite state (equity, sessions, positions, orders) exchange.py: Bybit linear futures executor (dry-run + live) executor.py: торговый цикл — fetch candles → run_day() → reconcile cli.py: Click CLI (run, status, history, daemon с APScheduler 5m) notify.py: Telegram alerts (entry, exit, OR) Существующие backtest-скрипты не затронуты. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
"""Telegram notifications for scalp-bot."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
import httpx
|
||||
|
||||
from config import TelegramConfig
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def send_telegram(cfg: TelegramConfig, message: str) -> bool:
|
||||
"""Send message via Telegram bot API. Returns True on success."""
|
||||
if not cfg.enabled or not cfg.bot_token or not cfg.chat_id:
|
||||
return False
|
||||
|
||||
url = f"https://api.telegram.org/bot{cfg.bot_token}/sendMessage"
|
||||
try:
|
||||
resp = httpx.post(url, json={
|
||||
"chat_id": cfg.chat_id,
|
||||
"text": message,
|
||||
"parse_mode": "HTML",
|
||||
}, timeout=10)
|
||||
if resp.status_code != 200:
|
||||
log.warning("Telegram API error: %s", resp.text)
|
||||
return False
|
||||
return True
|
||||
except httpx.HTTPError as e:
|
||||
log.warning("Telegram send failed: %s", e)
|
||||
return False
|
||||
|
||||
|
||||
def notify_entry(cfg: TelegramConfig, symbol: str, side: str,
|
||||
entry: float, stop: float, tp: float) -> None:
|
||||
tag = symbol.split("/")[0]
|
||||
icon = "\U0001f7e2" if side == "long" else "\U0001f534"
|
||||
msg = (
|
||||
f"{icon} <b>{tag} {side.upper()}</b>\n"
|
||||
f"Entry: ${entry:,.2f}\n"
|
||||
f"Stop: ${stop:,.2f}\n"
|
||||
f"TP: ${tp:,.2f}"
|
||||
)
|
||||
send_telegram(cfg, msg)
|
||||
|
||||
|
||||
def notify_exit(cfg: TelegramConfig, symbol: str, pnl: float,
|
||||
reason: str) -> None:
|
||||
tag = symbol.split("/")[0]
|
||||
icon = "\u2705" if pnl >= 0 else "\u274c"
|
||||
msg = f"{icon} <b>{tag} CLOSED</b> ({reason}) PnL ${pnl:+,.2f}"
|
||||
send_telegram(cfg, msg)
|
||||
|
||||
|
||||
def notify_or(cfg: TelegramConfig, dt_str: str,
|
||||
or_high: float, or_low: float) -> None:
|
||||
msg = (
|
||||
f"\U0001f4ca <b>Opening Range</b> {dt_str}\n"
|
||||
f"High: ${or_high:,.2f} | Low: ${or_low:,.2f}\n"
|
||||
f"Range: ${or_high - or_low:,.2f}"
|
||||
)
|
||||
send_telegram(cfg, msg)
|
||||
Reference in New Issue
Block a user