Skip to main content

Crate ferrochart_orderflow

Crate ferrochart_orderflow 

Source
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.
DepthSnapshot
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_series and feed it with crate::append_trades.
FootprintColors
Colors of a footprint.
FootprintOptions
Options of a Footprint.
Heatmap
A heatmap series: add it with Chart::add_custom_series and feed it with crate::append_depth or crate::append_trades.
HeatmapColors
Colors of a heatmap: five evenly spaced stops, from the smallest to the largest value, interpolated per channel (alpha included).
HeatmapGpu
The native implementation of Heatmap (kind HEATMAP_KIND); register it with register_gpu, which checks that the device supports it.
HeatmapOptions
Options of a Heatmap.
PriceLevels
The price grid of an order flow series.
SessionProfile
The profile of one session, in levels (see PriceLevels).
SparseGrid
Time columns of price levels with two f32 values each.
TickColumns
Trades as columns of equal length.
TickRule
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_series and feed it with crate::append_bars.
TpoColors
Colors of a TPO profile.
TpoOptions
Options of a Tpo.

Enums§

ColorScale
How values map to the color ramp.
FootprintMode
What a footprint cell shows.
HeatmapRange
The value range of the color ramp.
HeatmapSource
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 with renderer (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 k of a session: A–Z, then a–z, repeating.