thinking about rolling time windows for dex data in substrate-based chains
been spending time with streaming DEX data lately and one thing that kept tripping me up was how to handle time-bucketed metrics cleanly. most real-time price feeds just give you point-in-time pric...

Source: DEV Community
been spending time with streaming DEX data lately and one thing that kept tripping me up was how to handle time-bucketed metrics cleanly. most real-time price feeds just give you point-in-time prices, which is fine until you need to answer questions like "what's the 1h volume for this pair" or "how has liquidity moved over the last 5 minutes" without building your own aggregation layer. the pattern i've seen work best is pre-computing rolling windows server-side across multiple horizons (5m, 1h, 6h, 24h) and streaming those as part of the pair update payload. that way your subscriber doesn't have to maintain state across potentially thousands of pairs simultaneously. the tradeoff is you're trusting the upstream aggregation logic and you lose some flexibility if you want non-standard windows. for anyone building trading bots or dashboards on parachain DEXes, this distinction matters more than it seems. polkadot's block times are shorter than most EVM chains, so the 5-minute window in pa