Skip to main content

DataSource

Trait DataSource 

Source
pub trait DataSource: Send {
Show 16 methods // Required methods fn symbols(&self) -> Vec<String>; fn subscribe( &mut self, symbol: String, timeframe: Timeframe, ) -> Result<(), DataSourceError>; fn unsubscribe(&mut self, symbol: String) -> Result<(), DataSourceError>; fn poll(&mut self) -> Vec<DataUpdate>; fn fetch_historical( &mut self, request: HistoricalDataRequest, ) -> Result<Vec<Bar>, DataSourceError>; fn get_timeframe(&self, symbol: &str) -> Option<Timeframe>; // Provided methods fn supports_historical(&self) -> bool { ... } fn is_connected(&self) -> bool { ... } fn search_symbols( &self, _user_input: &str, _exchange: &str, _symbol_type: &str, _max_records: usize, ) -> Result<Vec<SymbolSearchResult>, DataSourceError> { ... } fn supports_symbol_search(&self) -> bool { ... } fn get_marks( &self, _symbol: &str, _from: i64, _to: i64, ) -> Result<Vec<BarMark>, DataSourceError> { ... } fn supports_marks(&self) -> bool { ... } fn get_timescale_marks( &self, _symbol: &str, _from: i64, _to: i64, ) -> Result<Vec<TimescaleMark>, DataSourceError> { ... } fn supports_timescale_marks(&self) -> bool { ... } fn get_server_time(&self) -> Result<i64, DataSourceError> { ... } fn supports_server_time(&self) -> bool { ... }
}
Expand description

Data source trait – the primary integration point for feeding market data into the chart engine.

Implementors supply OHLCV bars from any source (WebSocket, REST, CSV, etc.). The chart engine calls methods on this trait to subscribe to symbols, poll for live updates, and request historical data when the user scrolls back in time.

§Required methods

MethodPurpose
symbolsList available instrument identifiers
subscribeBegin receiving live data for a symbol
unsubscribeStop receiving live data for a symbol
pollNon-blocking check for new data updates
fetch_historicalLoad older bars when the user scrolls left
get_timeframeTimeframe a symbol was subscribed with

§Optional capabilities

Override the supports_* / get_* method pairs to enable:

  • Symbol search – typeahead search across instruments
  • Bar marks – event annotations on individual bars
  • Timescale marks – event annotations on the time axis
  • Server time – accurate exchange clock for countdown widget

§Thread safety

DataSource requires Send so it can be owned by the chart state which may be passed across threads. If your implementation wraps a connection handle that is not Send, consider using a channel-based architecture.

Required Methods§

Source

fn symbols(&self) -> Vec<String>

Returns the list of symbol identifiers available from this data source.

Source

fn subscribe( &mut self, symbol: String, timeframe: Timeframe, ) -> Result<(), DataSourceError>

Subscribe to live updates for symbol at the given timeframe.

After subscribing, subsequent calls to poll should return DataUpdate::NewBars or DataUpdate::FullDataset for this symbol.

Source

fn unsubscribe(&mut self, symbol: String) -> Result<(), DataSourceError>

Unsubscribe from live updates for symbol.

Source

fn poll(&mut self) -> Vec<DataUpdate>

Non-blocking poll for data updates since the last call.

The chart engine calls this on every frame. Return an empty Vec when there is nothing new.

Source

fn fetch_historical( &mut self, request: HistoricalDataRequest, ) -> Result<Vec<Bar>, DataSourceError>

Fetch historical bars older than the data already loaded.

Called when the user scrolls left beyond the currently loaded range. The implementation may block or use internal async machinery – the chart engine will not call this from the UI thread if it would block.

Source

fn get_timeframe(&self, symbol: &str) -> Option<Timeframe>

Returns the timeframe the given symbol was subscribed with, or None if the symbol is not currently subscribed.

Provided Methods§

Source

fn supports_historical(&self) -> bool

Whether this data source supports fetch_historical.

Return false (default) if the data source only provides a fixed dataset.

Source

fn is_connected(&self) -> bool

Whether the data source is currently connected and able to deliver data.

Defaults to true. Override to reflect real connection state for WebSocket / network-based sources.

Source

fn search_symbols( &self, _user_input: &str, _exchange: &str, _symbol_type: &str, _max_records: usize, ) -> Result<Vec<SymbolSearchResult>, DataSourceError>

Search for symbols matching _user_input.

Override together with supports_symbol_search to enable the symbol-search dialog in the UI.

Whether this data source supports the symbol search API.

Source

fn get_marks( &self, _symbol: &str, _from: i64, _to: i64, ) -> Result<Vec<BarMark>, DataSourceError>

Returns event marks attached to bars in the time range [_from, _to] (Unix milliseconds).

Source

fn supports_marks(&self) -> bool

Whether this data source provides bar marks.

Source

fn get_timescale_marks( &self, _symbol: &str, _from: i64, _to: i64, ) -> Result<Vec<TimescaleMark>, DataSourceError>

Returns event marks on the timescale in the range [_from, _to] (Unix milliseconds).

Source

fn supports_timescale_marks(&self) -> bool

Whether this data source provides timescale marks.

Source

fn get_server_time(&self) -> Result<i64, DataSourceError>

Returns the exchange server time as a Unix timestamp (seconds).

Used by the countdown-to-next-bar widget. Defaults to the local system clock.

Source

fn supports_server_time(&self) -> bool

Whether this data source provides authoritative server time.

Implementors§