pub struct Footprint { /* private fields */ }Expand description
A footprint series: add it with
Chart::add_custom_series
and feed it with crate::append_trades.
Columns share the slots of the host’s candles (AxisMode::Slots): a
column’s time is the open time of its bar. Below 12 CSS px of bar
spacing nothing is drawn (the candles stay visible); from 12 px the
cells are shaded; from 60 px the volumes are written in them (raise
ChartOptions::max_bar_spacing, 50 px by default, to zoom in that far).
§Examples
use ferrochart_core::chart::SeriesOptions;
use ferrochart_core::theme::Theme;
use ferrochart_core::{Chart, ChartOptions};
use ferrochart_orderflow::{Footprint, FootprintOptions, Side, TickColumns, append_trades};
let mut chart = Chart::new(ChartOptions::default());
let fp = Footprint::new(FootprintOptions::new(0.25, 60_000, &Theme::light()))?;
let id = chart.add_custom_series(chart.main_pane(), Box::new(fp), SeriesOptions::default())?;
let trades = TickColumns {
time: vec![0, 1_000, 61_000],
price: vec![100.0, 100.25, 100.0],
size: vec![2.0, 1.0, 5.0],
side: vec![Side::Buy, Side::Sell, Side::Unknown],
};
append_trades(&mut chart, id, &trades)?;
let fp = chart.custom_series::<Footprint>(id).unwrap();
assert_eq!(fp.grid().columns(), 2);
// 100.0 is level 400: 2 bought; 100.25 is level 401: 1 sold.
assert_eq!(fp.grid().column(0).unwrap().at(400), (0.0, 2.0));
assert_eq!(fp.grid().column(0).unwrap().at(401), (1.0, 0.0));Implementations§
Source§impl Footprint
impl Footprint
Sourcepub fn new(opts: FootprintOptions) -> Result<Self>
pub fn new(opts: FootprintOptions) -> Result<Self>
An empty footprint.
§Errors
Error::InvalidArgument for a bad price grid, a non-positive
timeframe or an imbalance ratio below 1.
Sourcepub fn options(&self) -> &FootprintOptions
pub fn options(&self) -> &FootprintOptions
The options.
Sourcepub fn set_display(
&mut self,
mode: FootprintMode,
imbalance_ratio: Option<f64>,
colors: FootprintColors,
)
pub fn set_display( &mut self, mode: FootprintMode, imbalance_ratio: Option<f64>, colors: FootprintColors, )
Changes what the cells show and their colors (the data stays).
Sourcepub fn grid(&self) -> &SparseGrid
pub fn grid(&self) -> &SparseGrid
The cells: a is sell volume, b buy volume.
Sourcepub fn push_trade(
&mut self,
time: Timestamp,
price: f64,
size: f64,
side: Side,
) -> Result<bool>
pub fn push_trade( &mut self, time: Timestamp, price: f64, size: f64, side: Side, ) -> Result<bool>
Adds one trade; returns whether it opened a column.
§Errors
Error::InvalidArgument for a non-finite price or a negative size;
Error::TimeNotIncreasing if its bar is before the last column;
Error::OutOfMemory.
Trait Implementations§
Source§impl CustomSeries for Footprint
impl CustomSeries for Footprint
Source§fn kind(&self) -> &'static str
fn kind(&self) -> &'static str
"orderflow.heatmap"; renderers that draw it natively
declare this name.Source§fn axis_mode(&self) -> AxisMode
fn axis_mode(&self) -> AxisMode
Source§fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>
fn extremes(&self, from: usize, to: usize) -> Option<(f64, f64)>
from..to, for auto scaling. Called every
frame, so it must be O(log n) (see crate::plugin::MinMaxIndex).Source§fn last_value(&self) -> Option<f64>
fn last_value(&self) -> Option<f64>
None hides it.Source§fn crosshair_value(&self, point: usize) -> Option<f64>
fn crosshair_value(&self, point: usize) -> Option<f64>
point for the crosshair and magnet.