data.validator¶
What a bad bar stream looks like, and which defects are fatal versus merely worth knowing about.
validator
¶
Bar-stream sanity validation: catch bad data BEFORE it reaches the engine.
Severity encoding (documented contract): severity is derived from the issue
code — codes in INFO_CODES (currently only "session_gap") are
informational; every other code is an ERROR. ValidationReport.ok is True
iff no ERROR-severity issue is present.
Codes emitted
ohlc_inconsistentERROR high < max(open, close) or low > min(open, close)stamp_invertedERRORts_event>=ts_init— the bar's open does not precede its close (the classic off-by-one look-ahead stamp bug)negative_volumeERROR volume < 0duplicate_tsERROR same instrument, repeatedts_initnon_monotonicERRORts_initdecreases along the sequenceoff_gridERROR a price off the instrument's tick gridin_maintenance_haltERRORts_eventinside the 17:00-18:00 ET haltweekend_barERROR bar's trading day falls on Sat/Sunsession_gapINFO > 3x step missing between consecutive bars of the same instrument within one trading day
Ordering checks (duplicate_ts, non_monotonic) anchor ts_ns to the
bar's ts_init; event-time checks (halt/weekend) anchor to ts_event.
There is deliberately no exchange-holiday check: this package ships no holiday
calendar (see the note in core/time.py), so a bar landing on a market
holiday is indistinguishable from any other weekday bar here.
ValidationIssue
¶
ValidationReport
¶
Bases: Struct
All findings for a bar sequence; ok means no ERROR-severity issues.
validate_bars
¶
validate_bars(bars: Sequence[Bar], spec: InstrumentSpec) -> ValidationReport
Run every check over bars and return the full report (never raises).
Source code in src/topstep_backtest/data/validator.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |