Skip to main content

CandlePages

Struct CandlePages 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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).

Source

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] after HistoryOpts::max_rate_waits pauses: the quota is spent by others too. Wait longer and start again from resume_from.
  • [Error::Transport] after HistoryOpts::transport_retries repeats: 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.

Auto Trait Implementations§

§

impl<'a, S> Freeze for CandlePages<'a, S>
where S: ?Sized,

§

impl<'a, S> RefUnwindSafe for CandlePages<'a, S>
where S: RefUnwindSafe + ?Sized,

§

impl<'a, S> Send for CandlePages<'a, S>
where S: ?Sized,

§

impl<'a, S> Sync for CandlePages<'a, S>
where S: ?Sized,

§

impl<'a, S> Unpin for CandlePages<'a, S>
where S: ?Sized,

§

impl<'a, S> UnsafeUnpin for CandlePages<'a, S>
where S: ?Sized,

§

impl<'a, S> UnwindSafe for CandlePages<'a, S>
where S: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more