Commit 69c8ac1
fix(src): Fix 24h price gap calculation by widening retention and lookup window (#300)
* Fix 24h price gap calculation by widening retention and lookup window
The Redis Time Series retention period (24h) and the 24h-ago lookup
threshold (5min tolerance) created only a 5-minute overlap window for
finding historical price data. As the token count grows and update
cycles take longer, this narrow window frequently contains no data
points, causing percentagePriceChange24h to return null.
- Increase RETENTION_PERIOD from 24h to 25h
- Increase DEFAULT_ONE_DAY_THRESHOLD_MS from 5min (300000ms) to 30min (1800000ms)
This expands the overlap window from 5 minutes to 90 minutes, tolerating
longer update cycles and transient Horizon outages without losing 24h
price change data.
* gap calculation by decoupling history gate from lookup tolerance
The 24h price change calculation frequently returns null because a single
threshold (oneDayThreshold) was used for both the minimum history
requirement and the revRange lookup window. With a 5-minute tolerance and
24h retention, the overlap window for finding a historical price point was
only 5 minutes — easily missed during update gaps.
- Increase RETENTION_PERIOD from 24h to 25h for wider data retention
- Add separate PRICE_LOOKUP_TOLERANCE_MS (30min) for the revRange lookup
- Keep DEFAULT_ONE_DAY_THRESHOLD_MS (5min) for the strict ~24h history gate
The history gate still requires ~23h55m of data before computing a 24h
change (no stale data). The lookup now searches with a 90-minute overlap
window instead of 5 minutes, tolerating gaps in price updates., wiring up the handoff from setup to live ingestion
* Add boundary tests for decoupled history gate and lookup tolerance
Add tests verifying that the 24h history gate and the lookup tolerance
operate independently:
- Token with 23h54m of history (1min under gate) returns null for
percentagePriceChange24h and does not attempt the revRange lookup
- Token with 23h56m of history (1min over gate) computes the 24h change
using the wider 30min PRICE_LOOKUP_TOLERANCE_MS, not the strict 5min
DEFAULT_ONE_DAY_THRESHOLD_MS
* Update retention comments to match new window
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* refactor: express PRICE_LOOKUP_TOLERANCE_MS as 30 * 60 * 1000 and improve doc comment
Agent-Logs-Url: https://github.com/stellar/freighter-backend/sessions/c6614a68-5178-48c6-911e-a16f20fb16b1
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>1 parent 14bbe0a commit 69c8ac1
2 files changed
Lines changed: 95 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| |||
161 | 161 | | |
162 | 162 | | |
163 | 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 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
164 | 231 | | |
165 | 232 | | |
166 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
| |||
211 | 219 | | |
212 | 220 | | |
213 | 221 | | |
214 | | - | |
| 222 | + | |
| 223 | + | |
215 | 224 | | |
216 | | - | |
| 225 | + | |
217 | 226 | | |
218 | 227 | | |
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
222 | 231 | | |
223 | | - | |
| 232 | + | |
224 | 233 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
229 | 241 | | |
230 | 242 | | |
231 | | - | |
232 | | - | |
| 243 | + | |
| 244 | + | |
233 | 245 | | |
234 | | - | |
| 246 | + | |
235 | 247 | | |
236 | 248 | | |
237 | 249 | | |
| |||
256 | 268 | | |
257 | 269 | | |
258 | 270 | | |
259 | | - | |
| 271 | + | |
260 | 272 | | |
261 | 273 | | |
262 | 274 | | |
| |||
0 commit comments