Expand description
Order flow series for FerroChart: footprint,
heatmap and TPO, as CustomSeries plugins. The exact rules (price
levels, aggressor classification, imbalances, color scales, value area)
are in docs/book/src/orderflow.md.
Prices are stored as level numbers of a fixed grid (PriceLevels).
The footprint and the heatmap share a sparse “time column × level” grid
(SparseGrid); only the last column changes, so real-time trades cost
O(levels of the last column).
With the default feature gpu, register_gpu adds the heatmap’s
native wgpu path (a compute shader) to a renderer whose device supports
it; elsewhere (WebGL2, the CPU backend) the heatmap draws through its
portable path with the same output.
use ferrochart_core::chart::SeriesOptions;
use ferrochart_core::testing::MonoMeasurer;
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.5, 60_000, &Theme::light()))?;
let id = chart.add_custom_series(chart.main_pane(), Box::new(fp), SeriesOptions::default())?;
let trades = TickColumns {
time: (0..600).map(|i| i * 1_000).collect(),
price: (0..600).map(|i| 100.0 + f64::from(i % 7) * 0.5).collect(),
size: vec![1.0; 600],
side: vec![Side::Unknown; 600],
};
append_trades(&mut chart, id, &trades)?;
chart.build_frame(0.0, &MonoMeasurer);Structs§
- Column
- One column of a
SparseGrid: levels ascending, with their two values. - Depth
Snapshot - One order book snapshot: the resting size at each price (bids and asks together). Prices are expected in book order (sorted either way): adjacent prices in the same row are added up.
- Footprint
- A footprint series: add it with
Chart::add_custom_seriesand feed it withcrate::append_trades. - Footprint
Colors - Colors of a footprint.
- Footprint
Options - Options of a
Footprint. - Heatmap
- A heatmap series: add it with
Chart::add_custom_seriesand feed it withcrate::append_depthorcrate::append_trades. - Heatmap
Colors - Colors of a heatmap: five evenly spaced stops, from the smallest to the largest value, interpolated per channel (alpha included).
- Heatmap
Gpu - The native implementation of
Heatmap(kindHEATMAP_KIND); register it withregister_gpu, which checks that the device supports it. - Heatmap
Options - Options of a
Heatmap. - Price
Levels - The price grid of an order flow series.
- Session
Profile - The profile of one session, in levels (see
PriceLevels). - Sparse
Grid - Time columns of price levels with two
f32values each. - Tick
Columns - Trades as columns of equal length.
- Tick
Rule - Classifies trades of unknown side by the tick rule: a trade above the previous price is a buy, below it a sell, at the same price the same as the previous trade. The first unknown trade with no reference is a buy.
- Tpo
- A TPO series: add it with
Chart::add_custom_seriesand feed it withcrate::append_bars. - TpoColors
- Colors of a TPO profile.
- TpoOptions
- Options of a
Tpo.
Enums§
- Color
Scale - How values map to the color ramp.
- Footprint
Mode - What a footprint cell shows.
- Heatmap
Range - The value range of the color ramp.
- Heatmap
Source - What a heatmap aggregates.
- Side
- The aggressor of a trade.
Constants§
- CELLS_
MIN_ SPACING - Below this bar spacing (CSS px) nothing is drawn.
- FOOTPRINT_
KIND - The kind name of footprint series.
- HEATMAP_
KIND - The kind name of heatmap series.
- MAX_
LEVELS_ PER_ ROW - Nothing is drawn when the plot shows more than this many levels per pixel row (levels are far below a pixel; zoom the price scale in).
- NUMBERS_
MIN_ SPACING - From this bar spacing (CSS px) the volumes are written in the cells.
- TPO_
KIND - The kind name of TPO series.
- TPO_
MIN_ FONT - Smallest letter size (CSS px); with smaller rows the profile is drawn as a histogram.
- TPO_
MIN_ SPACING - Below this slot width (CSS px) nothing is drawn.
Functions§
- append_
bars - Adds bars (time, high and low are used) to a TPO series in
chart. - append_
depth - Adds an order book snapshot to a depth heatmap in
chart. - append_
trades - Adds trades to a footprint (or a trade heatmap) in
chart. - register_
gpu - Registers the native order flow series that
ctx’s device supports withrenderer(pass the context the renderer was created with). Returns whether the native heatmap was registered; without it the heatmap draws through its portable path. - supports_
native_ heatmap - Whether
ctx’s device can run the native heatmap: compute shaders, storage buffers in fragment shaders and at least four storage buffers per stage. Devices created with the WebGL2 limits (e.g. by a host that asked for them) cannot. - tpo_
letter - The letter of period
kof a session: A–Z, then a–z, repeating.