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
| Method | Purpose |
|---|---|
symbols | List available instrument identifiers |
subscribe | Begin receiving live data for a symbol |
unsubscribe | Stop receiving live data for a symbol |
poll | Non-blocking check for new data updates |
fetch_historical | Load older bars when the user scrolls left |
get_timeframe | Timeframe 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§
Sourcefn symbols(&self) -> Vec<String>
fn symbols(&self) -> Vec<String>
Returns the list of symbol identifiers available from this data source.
Sourcefn subscribe(
&mut self,
symbol: String,
timeframe: Timeframe,
) -> Result<(), DataSourceError>
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.
Sourcefn unsubscribe(&mut self, symbol: String) -> Result<(), DataSourceError>
fn unsubscribe(&mut self, symbol: String) -> Result<(), DataSourceError>
Unsubscribe from live updates for symbol.
Sourcefn poll(&mut self) -> Vec<DataUpdate>
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.
Sourcefn fetch_historical(
&mut self,
request: HistoricalDataRequest,
) -> Result<Vec<Bar>, DataSourceError>
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.
Sourcefn get_timeframe(&self, symbol: &str) -> Option<Timeframe>
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§
Sourcefn supports_historical(&self) -> bool
fn supports_historical(&self) -> bool
Whether this data source supports fetch_historical.
Return false (default) if the data source only provides a fixed dataset.
Sourcefn is_connected(&self) -> bool
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.
Sourcefn search_symbols(
&self,
_user_input: &str,
_exchange: &str,
_symbol_type: &str,
_max_records: usize,
) -> Result<Vec<SymbolSearchResult>, DataSourceError>
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.
Sourcefn supports_symbol_search(&self) -> bool
fn supports_symbol_search(&self) -> bool
Whether this data source supports the symbol search API.
Sourcefn get_marks(
&self,
_symbol: &str,
_from: i64,
_to: i64,
) -> Result<Vec<BarMark>, DataSourceError>
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).
Sourcefn supports_marks(&self) -> bool
fn supports_marks(&self) -> bool
Whether this data source provides bar marks.
Sourcefn get_timescale_marks(
&self,
_symbol: &str,
_from: i64,
_to: i64,
) -> Result<Vec<TimescaleMark>, DataSourceError>
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).
Sourcefn supports_timescale_marks(&self) -> bool
fn supports_timescale_marks(&self) -> bool
Whether this data source provides timescale marks.
Sourcefn get_server_time(&self) -> Result<i64, DataSourceError>
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.
Sourcefn supports_server_time(&self) -> bool
fn supports_server_time(&self) -> bool
Whether this data source provides authoritative server time.