撤下交易员无须处理的历史数据说明
This commit is contained in:
parent
5978eb9cda
commit
4814f9aba9
|
|
@ -1,4 +1,4 @@
|
||||||
"""把资金监测的数据状态译成交易员提示;不生成交易信号。"""
|
"""交易员只看到当前提醒能力的异常;历史准备状态保留在内部巡检。"""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ def funds_warning(doc, codes, now=None, *, trade_day=True):
|
||||||
now = now or datetime.now(ZoneInfo('Asia/Shanghai'))
|
now = now or datetime.now(ZoneInfo('Asia/Shanghai'))
|
||||||
hm = now.strftime('%H:%M')
|
hm = now.strftime('%H:%M')
|
||||||
active = trade_day and ('09:45' <= hm <= '11:31' or '13:01' <= hm <= '15:01')
|
active = trade_day and ('09:45' <= hm <= '11:31' or '13:01' <= hm <= '15:01')
|
||||||
unavailable = '资金监测状态暂不可用,不能据此判断持仓和关注股票没有资金异动。'
|
unavailable = '资金异动提醒可能延迟,系统正在重试。'
|
||||||
try:
|
try:
|
||||||
at = datetime.fromisoformat(doc['at'])
|
at = datetime.fromisoformat(doc['at'])
|
||||||
as_of = datetime.fromisoformat(doc['as_of'])
|
as_of = datetime.fromisoformat(doc['as_of'])
|
||||||
|
|
@ -18,18 +18,15 @@ def funds_warning(doc, codes, now=None, *, trade_day=True):
|
||||||
if active and not 0 <= (now-as_of).total_seconds() <= 180:
|
if active and not 0 <= (now-as_of).total_seconds() <= 180:
|
||||||
return unavailable
|
return unavailable
|
||||||
rows = doc['priority']
|
rows = doc['priority']
|
||||||
if not isinstance(rows, dict) or doc.get('source') != 'redis_stock_flow_realtime':
|
if (not isinstance(rows, dict) or not all(isinstance(row, dict) for row in rows.values())
|
||||||
|
or doc.get('source') != 'redis_stock_flow_realtime'):
|
||||||
raise ValueError('invalid health report')
|
raise ValueError('invalid health report')
|
||||||
wanted = set(codes) | set(rows)
|
wanted = set(codes) | set(rows)
|
||||||
if not wanted:
|
if not wanted:
|
||||||
return ''
|
return ''
|
||||||
bad = sum(rows.get(c, {}).get('state') != 'available' for c in wanted)
|
bad = sum(rows.get(c, {}).get('state') != 'available' for c in wanted)
|
||||||
incomplete = sum(rows.get(c, {}).get('money_flow_baseline_ready') is False for c in wanted)
|
|
||||||
messages = []
|
|
||||||
if bad:
|
if bad:
|
||||||
messages.append(f'持仓及关注中有{bad}只股票资金数据暂不可用,暂无提示不代表没有资金异动。')
|
return '部分持仓及关注股的资金异动提醒暂不可用,系统正在重试。'
|
||||||
if incomplete:
|
return ''
|
||||||
messages.append('部分股票的资金流强度仍缺历史数据,该类提示暂不可用;其他信号继续监测。')
|
|
||||||
return ''.join(messages)
|
|
||||||
except (KeyError, TypeError, ValueError):
|
except (KeyError, TypeError, ValueError):
|
||||||
return unavailable if active else ''
|
return unavailable if active else ''
|
||||||
|
|
|
||||||
|
|
@ -22,20 +22,29 @@ class FundsHealthTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_frozen_reader_even_live_heartbeat_warns(self):
|
def test_frozen_reader_even_live_heartbeat_warns(self):
|
||||||
self.doc['as_of']=(self.now-timedelta(hours=3)).isoformat()
|
self.doc['as_of']=(self.now-timedelta(hours=3)).isoformat()
|
||||||
self.assertIn('不能据此',self.check())
|
self.assertIn('提醒可能延迟',self.check())
|
||||||
|
|
||||||
def test_missing_stale_and_future_status_visible(self):
|
def test_missing_stale_and_future_status_visible(self):
|
||||||
self.assertIn('不能据此',funds_warning(None,['300133.SZ'],self.now))
|
self.assertIn('提醒可能延迟',funds_warning(None,['300133.SZ'],self.now))
|
||||||
for delta in (-181,1):
|
for delta in (-181,1):
|
||||||
self.doc['at']=(self.now+timedelta(seconds=delta)).isoformat()
|
self.doc['at']=(self.now+timedelta(seconds=delta)).isoformat()
|
||||||
self.assertIn('不能据此',self.check())
|
self.assertIn('提醒可能延迟',self.check())
|
||||||
|
|
||||||
def test_missing_focus_detected(self):
|
def test_missing_focus_detected(self):
|
||||||
self.assertIn('1只',self.check(codes=('300133.SZ','601126.SH')))
|
self.assertIn('提醒暂不可用',self.check(codes=('300133.SZ','601126.SH')))
|
||||||
|
|
||||||
def test_bad_funds_and_baseline_separate(self):
|
def test_bad_funds_and_baseline_separate(self):
|
||||||
self.doc['priority']['300133.SZ']={'state':'stale','money_flow_baseline_ready':False}
|
self.doc['priority']['300133.SZ']={'state':'stale','money_flow_baseline_ready':False}
|
||||||
text=self.check();self.assertIn('1只',text);self.assertIn('仍缺历史数据',text)
|
text=self.check();self.assertIn('提醒暂不可用',text);self.assertNotIn('历史',text)
|
||||||
|
|
||||||
|
def test_history_preparation_is_not_a_trader_diagnostic_banner(self):
|
||||||
|
self.doc['priority']['300133.SZ']['money_flow_baseline_ready']=False
|
||||||
|
self.assertEqual(self.check(),'')
|
||||||
|
self.assertFalse(self.doc['priority']['300133.SZ']['money_flow_baseline_ready'])
|
||||||
|
|
||||||
|
def test_malformed_internal_status_does_not_break_signal_page(self):
|
||||||
|
self.doc['priority']['300133.SZ']=None
|
||||||
|
self.assertIn('提醒可能延迟',self.check())
|
||||||
|
|
||||||
def test_closed_and_lunch_do_not_expect_new_ticks(self):
|
def test_closed_and_lunch_do_not_expect_new_ticks(self):
|
||||||
for hour,minute in [(12,0),(18,0),(9,0)]:
|
for hour,minute in [(12,0),(18,0),(9,0)]:
|
||||||
|
|
@ -45,7 +54,7 @@ class FundsHealthTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_no_timezone_or_wrong_source_not_healthy(self):
|
def test_no_timezone_or_wrong_source_not_healthy(self):
|
||||||
self.doc['at']='2026-11-16T14:10:00'
|
self.doc['at']='2026-11-16T14:10:00'
|
||||||
self.assertIn('不能据此',self.check())
|
self.assertIn('提醒可能延迟',self.check())
|
||||||
|
|
||||||
|
|
||||||
if __name__=='__main__': unittest.main()
|
if __name__=='__main__': unittest.main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue