feat(stock): edge diff(신규/해제/재무장) 순수 함수
This commit is contained in:
@@ -76,3 +76,24 @@ def build_monitor_set(conn, session: str, exit_params: dict, buy_params: dict) -
|
||||
"buy_params": buy_params,
|
||||
"exit_params": exit_params,
|
||||
}
|
||||
|
||||
|
||||
def diff_firing(reported: list, prev: set) -> dict:
|
||||
"""워커 발화집합(reported) vs 직전 발화상태(prev) edge diff.
|
||||
|
||||
reported 각 항목: {ticker,kind,condition,price,detail,name?}.
|
||||
key = (ticker,kind,condition).
|
||||
반환 {"new":[신규 alert...], "cleared":[해제 key...], "seen":[현재 key...]}.
|
||||
"""
|
||||
cur = {}
|
||||
for a in reported:
|
||||
key = (a["ticker"], a["kind"], a["condition"])
|
||||
cur[key] = a
|
||||
cur_keys = set(cur.keys())
|
||||
new_keys = cur_keys - prev
|
||||
cleared = sorted(prev - cur_keys)
|
||||
return {
|
||||
"new": [cur[k] for k in cur_keys if k in new_keys],
|
||||
"cleared": cleared,
|
||||
"seen": sorted(cur_keys),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user