#pragma once // A single OHLC candle — the shared shape for per-exchange candlestick charts. Kept in its own tiny, // dependency-free header so both the parser (data/exchange_candles.h, which pulls in nlohmann/json) // and the model (data/wallet_state.h, included widely) can use it without dragging json everywhere. #include #include namespace dragonx { namespace data { struct Candle { std::time_t time = 0; // epoch SECONDS (the candle's open/bucket time) double open = 0.0; double high = 0.0; double low = 0.0; double close = 0.0; }; // Aggregate fine candles into fixed time buckets (e.g. 5-min -> hourly for the 1D view): open = first // open, high = max high, low = min low, close = last close. Input must be ascending by time. inline std::vector bucketOHLC(const std::vector& src, long windowSec) { std::vector out; if (src.empty() || windowSec <= 0) return out; long curBucket = -1; Candle cur; for (const auto& c : src) { const long b = (long)(c.time / windowSec); if (b != curBucket) { if (curBucket >= 0) out.push_back(cur); curBucket = b; cur = c; cur.time = (std::time_t)(b * windowSec); } else { if (c.high > cur.high) cur.high = c.high; if (c.low < cur.low) cur.low = c.low; cur.close = c.close; } } if (curBucket >= 0) out.push_back(cur); return out; } } // namespace data } // namespace dragonx