Struct Candlestick
pub struct Candlestick {
pub time: i64,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: f64,
pub turnover: f64,
pub turnover_rate: f64,
pub trade_session: TradeSession,
pub ask: f64,
pub bid: f64,
}Expand description
OHLCV candlestick data used as VM input.
Each candlestick represents one bar of market data. Feed these to
Instance::run() via a DataProvider wrapped in a CandlestickItem.
§Examples
use navi_types::{Candlestick, TradeSession};
let bar = Candlestick::new(
1_700_000_000_000, // epoch milliseconds
150.0,
155.0,
149.0,
153.0,
1_000_000.0,
0.0,
TradeSession::Regular,
);
assert_eq!(bar.hl2(), (155.0 + 149.0) / 2.0);
assert_eq!(bar.ohlc4(), (150.0 + 155.0 + 149.0 + 153.0) / 4.0);Fields§
§time: i64Candle timestamp (epoch milliseconds).
open: f64Open price.
high: f64High price.
low: f64Low price.
close: f64Close price.
volume: f64Volume.
turnover: f64Turnover.
turnover_rate: f64Turnover rate — fraction of the float traded this bar.
f64::NAN when unavailable.
trade_session: TradeSessionTrading session for this candle.
ask: f64Best ask price. f64::NAN when unavailable (e.g. non-tick bars).
bid: f64Best bid price. f64::NAN when unavailable (e.g. non-tick bars).
Implementations§
§impl Candlestick
impl Candlestick
pub const fn new(
time: i64,
open: f64,
high: f64,
low: f64,
close: f64,
volume: f64,
turnover: f64,
trade_session: TradeSession,
) -> Candlestick
pub const fn new( time: i64, open: f64, high: f64, low: f64, close: f64, volume: f64, turnover: f64, trade_session: TradeSession, ) -> Candlestick
Creates a new candlestick.
The ask, bid, and turnover_rate fields default to f64::NAN
(unavailable). Use from_tick to build a candlestick
from a tick event that carries ask/bid data.
pub fn from_tick(tick: Tick) -> Candlestick
pub fn from_tick(tick: Tick) -> Candlestick
Creates a tick-level candlestick from a single Tick.
Sets OHLC = tick.price, volume = tick.volume, and carries
ask/bid from the tick. turnover is set to 0.0; turnover_rate
to f64::NAN (unavailable).
Trait Implementations§
§impl Clone for Candlestick
impl Clone for Candlestick
§fn clone(&self) -> Candlestick
fn clone(&self) -> Candlestick
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for Candlestick
impl Debug for Candlestick
§impl Default for Candlestick
impl Default for Candlestick
§fn default() -> Candlestick
fn default() -> Candlestick
§impl<'de> Deserialize<'de> for Candlestickwhere
Candlestick: Default,
impl<'de> Deserialize<'de> for Candlestickwhere
Candlestick: Default,
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Candlestick, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Candlestick, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Serialize for Candlestick
impl Serialize for Candlestick
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Candlestick
Auto Trait Implementations§
impl Freeze for Candlestick
impl RefUnwindSafe for Candlestick
impl Send for Candlestick
impl Sync for Candlestick
impl Unpin for Candlestick
impl UnsafeUnpin for Candlestick
impl UnwindSafe for Candlestick
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.