@@ -19,6 +19,60 @@ def _plan_allocation(plan):
1919 return dict (plan .get ("allocation" ) or {})
2020
2121
22+ def _has_text (value ):
23+ return bool (str (value or "" ).strip ())
24+
25+
26+ def _has_benchmark_context (execution ):
27+ return any (
28+ float (execution .get (key ) or 0.0 ) > 0.0
29+ for key in ("benchmark_price" , "long_trend_value" , "exit_line" )
30+ )
31+
32+
33+ def _build_benchmark_line (execution ):
34+ if not _has_benchmark_context (execution ):
35+ return None
36+ benchmark_symbol = str (execution .get ("benchmark_symbol" ) or "QQQ" )
37+ benchmark_price = float (execution .get ("benchmark_price" ) or 0.0 )
38+ long_trend_value = float (execution .get ("long_trend_value" ) or 0.0 )
39+ exit_line = float (execution .get ("exit_line" ) or 0.0 )
40+ return (
41+ f"{ benchmark_symbol } : { benchmark_price :.2f} | "
42+ f"MA200: { long_trend_value :.2f} | Exit: { exit_line :.2f} "
43+ )
44+
45+
46+ def _append_status_lines (lines , * , execution , translator , signal_key ):
47+ status_display = str (execution .get ("status_display" ) or "" ).strip ()
48+ if status_display :
49+ lines .append (translator ("market_status" , status = status_display ))
50+
51+ deploy_ratio_text = str (execution .get ("deploy_ratio_text" ) or "" ).strip ()
52+ if deploy_ratio_text :
53+ lines .append (translator ("risk_position" , ratio = deploy_ratio_text ))
54+
55+ income_ratio_text = str (execution .get ("income_ratio_text" ) or "" ).strip ()
56+ if income_ratio_text :
57+ lines .append (translator ("income_target" , ratio = income_ratio_text ))
58+
59+ income_locked_ratio_text = str (execution .get ("income_locked_ratio_text" ) or "" ).strip ()
60+ if income_locked_ratio_text :
61+ lines .append (translator ("income_locked" , ratio = income_locked_ratio_text ))
62+
63+ signal_display = str (execution .get ("signal_display" ) or "" ).strip ()
64+ if signal_display :
65+ lines .append (translator (signal_key , msg = signal_display ))
66+
67+ benchmark_line = _build_benchmark_line (execution )
68+ if benchmark_line :
69+ lines .append (benchmark_line )
70+
71+ dashboard_text = str (execution .get ("dashboard_text" ) or "" ).strip ()
72+ if dashboard_text :
73+ lines .append (dashboard_text )
74+
75+
2276def record_skip_log (skip_logs , * , translator , with_prefix , kind , detail ):
2377 message = translator (kind , detail = detail )
2478 skip_logs .append (message )
@@ -104,12 +158,6 @@ def run_strategy(
104158 investable_cash = float (execution ["investable_cash" ])
105159 current_min_trade = float (execution ["current_min_trade" ])
106160 portfolio_rows = tuple (portfolio ["portfolio_rows" ])
107- market_status = str (execution ["status_display" ])
108- signal_message = str (execution ["signal_display" ])
109- deploy_ratio_text = str (execution ["deploy_ratio_text" ])
110- income_ratio_text = str (execution ["income_ratio_text" ])
111- income_locked_ratio_text = str (execution ["income_locked_ratio_text" ])
112-
113161 def record_dry_run (symbol , side , quantity , price , * , order_type ):
114162 price_text = f"${ price :.2f} " if price is not None else "market"
115163 suffix = " LIMIT" if order_type == "limit" else ""
@@ -216,12 +264,6 @@ def record_dry_run(symbol, side, quantity, price, *, order_type):
216264 investable_cash = float (execution ["investable_cash" ])
217265 current_min_trade = float (execution ["current_min_trade" ])
218266 portfolio_rows = tuple (portfolio ["portfolio_rows" ])
219- market_status = str (execution ["status_display" ])
220- signal_message = str (execution ["signal_display" ])
221- deploy_ratio_text = str (execution ["deploy_ratio_text" ])
222- income_ratio_text = str (execution ["income_ratio_text" ])
223- income_locked_ratio_text = str (execution ["income_locked_ratio_text" ])
224-
225267 buy_candidates = [
226268 symbol
227269 for symbol in strategy_assets
@@ -339,22 +381,17 @@ def record_dry_run(symbol, side, quantity, price, *, order_type):
339381 tg_lines = [translator ("rebalance_title" )]
340382 if dry_run_only :
341383 tg_lines .append (translator ("dry_run_banner" ))
342- tg_lines .extend (
343- [
344- translator ("market_status" , status = market_status ),
345- cash_summary ,
346- translator ("risk_position" , ratio = deploy_ratio_text ),
347- translator ("income_target" , ratio = income_ratio_text ),
348- translator ("income_locked" , ratio = income_locked_ratio_text ),
349- translator ("signal" , msg = signal_message ),
350- separator ,
351- formatted_logs ,
352- ]
384+ tg_lines .append (cash_summary )
385+ _append_status_lines (
386+ tg_lines ,
387+ execution = execution ,
388+ translator = translator ,
389+ signal_key = "signal" ,
353390 )
391+ tg_lines .extend ([separator , formatted_logs ])
354392 tg_message = "\n " .join (tg_lines )
355393 send_tg_message (tg_message )
356394 else :
357- cash_label = translator ("cash_label" )
358395 equity_text = f"{ total_strategy_equity :,.2f} "
359396 cash_summary = translator (
360397 "cash_summary" ,
@@ -363,33 +400,39 @@ def record_dry_run(symbol, side, quantity, price, *, order_type):
363400 )
364401 holdings_lines = []
365402 for row in portfolio_rows :
366- if len (row ) == 1 :
367- symbol = row [0 ]
368- holdings_lines .append (
369- f"{ symbol } : ${ market_values [symbol ]:,.2f} { cash_label } : ${ available_cash :,.2f} "
370- )
371- else :
372- holdings_lines .append (
373- " " .join (
374- f"{ symbol } : ${ market_values [symbol ]:,.2f} "
375- for symbol in row
376- )
403+ holdings_lines .append (
404+ " " .join (
405+ f"{ symbol } : ${ market_values [symbol ]:,.2f} "
406+ for symbol in row
377407 )
378- no_trade_message = (
379- f"{ translator ('heartbeat_title' )} \n "
380- f"{ translator ('market_status' , status = market_status )} \n "
381- f"{ translator ('equity' , value = equity_text )} \n "
382- f"{ cash_summary } \n "
383- f"{ separator } \n "
384- + "\n " .join (holdings_lines ) + "\n "
385- f"{ separator } \n "
386- f"{ translator ('risk_position' , ratio = deploy_ratio_text )} \n "
387- f"{ translator ('income_target' , ratio = income_ratio_text )} \n "
388- f"{ translator ('income_locked' , ratio = income_locked_ratio_text )} \n "
389- f"{ translator ('heartbeat_signal' , msg = signal_message )} \n "
390- f"{ separator } \n "
391- f"{ translator ('no_executable_orders' ) if (skip_logs or note_logs ) else translator ('no_trades' )} "
408+ )
409+ no_trade_lines = [
410+ translator ("heartbeat_title" ),
411+ translator ("equity" , value = equity_text ),
412+ ]
413+ if dry_run_only :
414+ no_trade_lines .append (translator ("dry_run_banner" ))
415+ no_trade_lines .extend (
416+ [
417+ cash_summary ,
418+ separator ,
419+ * holdings_lines ,
420+ separator ,
421+ ]
422+ )
423+ _append_status_lines (
424+ no_trade_lines ,
425+ execution = execution ,
426+ translator = translator ,
427+ signal_key = "heartbeat_signal" ,
428+ )
429+ no_trade_lines .extend (
430+ [
431+ separator ,
432+ translator ("no_executable_orders" ) if (skip_logs or note_logs ) else translator ("no_trades" ),
433+ ]
392434 )
435+ no_trade_message = "\n " .join (no_trade_lines )
393436 if skip_logs :
394437 no_trade_message += (
395438 f"\n { separator } \n "
0 commit comments