Intelligence, Advanced Charting & Trading Platform
security(alert): bind every rule to exact provider, canonical instrument and quote unit
davoodmehraban89 committed
Oct 21, 2026 at 08:57 UTC
4dae1abcaec3cafcd6f3324b64b5e1fcd19a592b
1 file changed
+7
-2
packages/market-domain/src/informational-alert-engine.mjs
+7
-2
@@ -44,7 +44,11 @@ export function initialAlertState(id) {
44
selectedLeg:null,cooldownUntil:null};
45
}
46
const checkRule=r=>{
47
- if(!r||typeof r.id!=='string'||!r.id||!Array.isArray(r.legs)||!r.legs.length||r.legs.length>2)
47
+ if(!r||typeof r.id!=='string'||!r.id||
48
+ typeof r.symbol!=='string'||!r.symbol||
49
+ typeof r.unit!=='string'||!r.unit||
50
+ typeof r.provider!=='string'||!r.provider||
51
+ !Array.isArray(r.legs)||!r.legs.length||r.legs.length>2)
52
throw new TypeError('alert id + 1 or 2 legs');
53
for(const leg of r.legs)checkLeg(leg);
54
if(r.legs.length===2&&r.legs[0].type===r.legs[1].type)
@@ -70,7 +74,8 @@ export function stepAlert(rule,previous,quote,gate) {
74
return {state:{...state,consecutive:0,firstCandidateAt:null},events:[],reason:'QUALITY_HOLD'};
75
const t=when(quote.timestamp),last=state.lastTimestamp===null?null:when(state.lastTimestamp);
76
if(last!==null&&t<=last)return {state,events:[],reason:t===last?'DUPLICATE':'OUT_OF_ORDER'};
73
- if(!positive(quote.price)||quote.side!==rule.legs[0].side)
77
+ if(!positive(quote.price)||quote.side!==rule.legs[0].side||
78
+ quote.symbol!==rule.symbol||quote.unit!==rule.unit||quote.provider!==rule.provider)
79
return {state,events:[],reason:'QUOTE_SIDE_OR_PRICE_INVALID'};
80
let high=state.highWater,low=state.lowWater,stop=state.stop;
81
// Trailing state must advance on each valid observation before evaluating.