pub struct GridState {
pub center_price: f64,
pub grid_lines: Vec<GridLine>,
pub spacing: GridSpacing,
pub active: bool,
}Expand description
State for a grid trading strategy.
The grid is symmetric around center_price. Lines below the center
are Buy orders; lines above are Sell orders.
Fields§
§center_price: f64§grid_lines: Vec<GridLine>§spacing: GridSpacing§active: boolImplementations§
Source§impl GridState
impl GridState
Sourcepub fn new(
center: f64,
num_lines: u8,
spacing: GridSpacing,
atr: Option<f64>,
) -> Self
pub fn new( center: f64, num_lines: u8, spacing: GridSpacing, atr: Option<f64>, ) -> Self
Create a new symmetric grid around center.
num_lines is the number of lines per side (so total lines = 2 × num_lines).
For GridSpacing::Fixed(pct), each line is spaced center * pct / 100
apart. For GridSpacing::AtrBased(mult), the spacing is atr * mult
(requires atr to be Some).
Sourcepub fn check_fills(&mut self, current_price: f64) -> Vec<GridSignal>
pub fn check_fills(&mut self, current_price: f64) -> Vec<GridSignal>
Check which unfilled grid lines have been crossed by the current price and mark them as filled.
Returns signals for each newly filled line.
Sourcepub fn should_reset(&self, current_price: f64, threshold_pct: f64) -> bool
pub fn should_reset(&self, current_price: f64, threshold_pct: f64) -> bool
Whether the price has moved far enough from center to warrant a reset.
Returns true if |current_price − center| / center > threshold_pct / 100.
Sourcepub fn reset(&mut self, new_center: f64, atr: Option<f64>)
pub fn reset(&mut self, new_center: f64, atr: Option<f64>)
Reset the grid around a new center price, clearing all fills.
Sourcepub fn unfilled_count(&self) -> usize
pub fn unfilled_count(&self) -> usize
Count of unfilled grid lines.
Sourcepub fn filled_count(&self) -> usize
pub fn filled_count(&self) -> usize
Count of filled grid lines.
Sourcepub fn total_lines(&self) -> usize
pub fn total_lines(&self) -> usize
Total number of grid lines.