pub struct CandlePages<'a, S: MarketDataSource + ?Sized> { /* private fields */ }Expand description
A reader of candle history, one window per next_page call.
Pages come in time order. Inside the whole read every bar is delivered once: a bar that two
neighbouring windows both return (brokers differ on whether the end of a range is included) is
kept in the first. A page can be empty (a weekend, a halt): that is not the end, the end is None.
The type borrows the connector and the instrument and holds no network state of its own, so a
crash loses only the progress you did not save. Save resume_from after
each page you wrote.
§Examples
See the module history.
Implementations§
Source§impl<'a, S: MarketDataSource + ?Sized> CandlePages<'a, S>
impl<'a, S: MarketDataSource + ?Sized> CandlePages<'a, S>
Sourcepub fn new(
src: &'a S,
id: &'a InstrumentId,
tf: Timeframe,
range: TimeRange,
opts: HistoryOpts,
) -> Self
pub fn new( src: &'a S, id: &'a InstrumentId, tf: Timeframe, range: TimeRange, opts: HistoryOpts, ) -> Self
Prepares a read of tf bars of id over range. Nothing is sent yet.
Sourcepub fn resume_from(&self) -> UnixNanos
pub fn resume_from(&self) -> UnixNanos
The start of the next window: where to begin again after a stop. Equals the end of the range when everything is read.
Sourcepub fn requests(&self) -> u32
pub fn requests(&self) -> u32
How many candles calls were made, repeats included. A call that the local rate limiter refused is counted
too, although it never reached the broker: count the requests that went out on the broker’s side if you
need them.
Sourcepub fn rate_waits(&self) -> u32
pub fn rate_waits(&self) -> u32
How many times a rate limit was waited out inside this reader (a wait of your own loop is not counted).
Sourcepub async fn next_page(&mut self) -> Result<Option<Vec<Candle>>, HistoryError>
pub async fn next_page(&mut self) -> Result<Option<Vec<Candle>>, HistoryError>
Reads the next window. Ok(None) when the range is finished.
§Errors
HistoryError with the error that stopped the read and resume_from:
- [
Error::RateLimited] afterHistoryOpts::max_rate_waitspauses: the quota is spent by others too. Wait longer and start again fromresume_from. - [
Error::Transport] afterHistoryOpts::transport_retriesrepeats: the broker is unreachable. Start again later. - [
Error::Rejected], [Error::Config], [Error::Unsupported]: the same read fails again. Check the instrument, the timeframe and the window. Do not loop.