Skip to content

Historical and streaming data

Choose the simplest path that fits your source: supply bars directly, or attach a Datafeed for asynchronous history and live subscriptions. The host owns credentials, connections, retries and data acquisition.

Create a Chart from BarData. Replace history with set_data, or send forming bars through update. The first chart shows both. Keep timestamps ordered and give a forming bar the same opening time on each update.

Only Datafeed::history is required. This in-memory adapter returns the newest requested bars strictly before the request boundary, in chronological order:

use egui_charts::data::{Datafeed, HistoryPage, HistoryRequest, Reply};
use egui_charts::model::Bar;
struct InMemory(Vec<Bar>);
impl Datafeed for InMemory {
fn history(&self, request: HistoryRequest, reply: Reply<HistoryPage>) {
let end = self.0.partition_point(|bar| {
request.before.is_none_or(|before| bar.time < before)
});
let start = end.saturating_sub(request.count);
reply.send(Ok(HistoryPage::new(self.0[start..end].to_vec(), start == 0)));
}
}

Pass an Arc of your feed to ChartBuilder::with_feed. The chart calls feed methods from show on the UI thread. Return promptly; a worker or browser task can answer Reply later. Set end_of_history only when no earlier page remains. The chart asks for older pages as the viewport reaches the start of loaded history. A request covers [since, before): since is inclusive and set when the chart needs bars back to a time it does not hold, before is exclusive. A window with no bars, such as a weekend, answers HistoryPage::with_continue_before to say where older bars continue; an empty page without it ends history. Trade and depth pages work the same way.

Implement subscribe and retain its Subscription::sink in your producer. Push forming bars with push_bar, or executions with push_tick to build bars using the selected interval. The sink wakes the chart when data arrives. For execution history and book data, continue with order flow.

Stop producing when Sink::is_active becomes false. Symbol and interval changes end the old subscription. Implement unsubscribe when your backend needs explicit cleanup. Never wait for a worker that may be waking the chart from inside unsubscribe: dropping a chart may happen while an egui context lock is held.

Read Chart::feed_state for loading, failures and rejected updates. Feed methods return failures through the reply rather than blocking a frame. Your host decides how to retry or present a disconnected source.

The repository’s live feed example implements paging and a cancellable execution producer. The builder guide connects feed setup to events and the rest of the application.