pub struct Grid { /* private fields */ }Expand description
One asset’s grid: its size decimals, and whether its prices take the perp or the spot ceiling.
Implementations§
Source§impl Grid
impl Grid
Sourcepub const fn perp(sz_decimals: u32) -> Grid
pub const fn perp(sz_decimals: u32) -> Grid
A perp, main dex or HIP-3, by its szDecimals in meta.
Sourcepub const fn spot(sz_decimals: u32) -> Grid
pub const fn spot(sz_decimals: u32) -> Grid
A spot pair, by its base token’s szDecimals in spotMeta.
pub const fn sz_decimals(self) -> u32
Sourcepub const fn price_places(self) -> u32
pub const fn price_places(self) -> u32
Places a price may use: six (perp) or eight (spot), less the size decimals.
Sourcepub fn tick(self, price: Dec, round: Round) -> Option<Dec>
pub fn tick(self, price: Dec, round: Round) -> Option<Dec>
price on the grid, rounded as asked, once: at the coarser of the
places allowed and five significant figures, and never past the whole
part (a whole price is always taken). Rounding to the places and then
to the figures would round twice: to the nearest, 81800.45 would
become 81801, not 81800. None when nothing positive is left.
Sourcepub fn price(self, price: Dec, side: Side) -> Option<Dec>
pub fn price(self, price: Dec, side: Side) -> Option<Dec>
A limit price for side, never worse for the trader than asked: a buy
rounds down and a sell up.
Sourcepub fn is_on_grid(self, price: Dec) -> bool
pub fn is_on_grid(self, price: Dec) -> bool
Whether the venue takes price exactly as written.
Sourcepub fn size(self, size: Dec) -> Option<Dec>
pub fn size(self, size: Dec) -> Option<Dec>
A size cut toward zero to the size decimals. None when nothing is
left.
Sourcepub fn market_bound(
self,
reference: Dec,
slippage: Dec,
side: Side,
) -> Result<Dec, TradeError>
pub fn market_bound( self, reference: Dec, slippage: Dec, side: Side, ) -> Result<Dec, TradeError>
The worst price a market order takes: reference moved by slippage
(a fraction, 0.01 for 1%) on the side that costs more, then rounded
back toward reference, so the bound is never looser than asked.
Sourcepub fn least_size(self, price: Dec) -> Option<Dec>
pub fn least_size(self, price: Dec) -> Option<Dec>
The smallest size worth MINIMUM_ORDER_VALUE at price, rounded up
to the size decimals.
Sourcepub fn meets_minimum(price: Dec, size: Dec) -> bool
pub fn meets_minimum(price: Dec, size: Dec) -> bool
Whether size at price is worth the venue’s minimum.
Trait Implementations§
impl Copy for Grid
impl Eq for Grid
impl StructuralPartialEq for Grid
Auto Trait Implementations§
impl Freeze for Grid
impl RefUnwindSafe for Grid
impl Send for Grid
impl Sync for Grid
impl Unpin for Grid
impl UnsafeUnpin for Grid
impl UnwindSafe for Grid
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.