pub struct OrderRate { /* private fields */ }Expand description
Order rates impose limits on what trades the smart contract is allowed to execute. For example, the smart contract will reject a payload that requests a less favorable amount of asset_to than is imposed by the minimum order rate. For Sell orders, an order rate represented by currency B an in A/B market. For Buy orders, an order rate is represented in the protocol by currency A. Note that OrderRates are always created w.r.t. currency B, then potentially inverted during payload creation. This is because, unlike the smart contract, the ME always wants order prices expressed in currency B. In either case, these rates are encoded as 64 bit integers which take the initial price ratio, multiply by 10^8, and then drop all precision after the decimal.
Implementations§
Source§impl OrderRate
impl OrderRate
Sourcepub fn to_be_bytes(&self, precision: u32) -> Result<Vec<u8>>
pub fn to_be_bytes(&self, precision: u32) -> Result<Vec<u8>>
Serialize the OrderRate to bytes for payload creation. We always use a precision of 8 and multiplication factor of 10^8
Sourcepub fn from_be_bytes(bytes: [u8; 8]) -> Result<Self>
pub fn from_be_bytes(bytes: [u8; 8]) -> Result<Self>
Create OrderRate from big endian bytes in Ethereum FillOrder payload
Source§impl OrderRate
impl OrderRate
Sourcepub fn to_le_bytes(&self) -> Result<[u8; 8]>
pub fn to_le_bytes(&self) -> Result<[u8; 8]>
Serialize the OrderRate to bytes for payload creation. We always use a precision of 8 and multiplication factor of 10^8
Source§impl OrderRate
impl OrderRate
Sourcepub fn from_bigdecimal(decimal: BigDecimal) -> Self
pub fn from_bigdecimal(decimal: BigDecimal) -> Self
Create new OrderRate from bigdecimal
Sourcepub fn invert_rate(&self, precision: Option<u32>) -> Self
pub fn invert_rate(&self, precision: Option<u32>) -> Self
Invert the price to units of the other market pair. For example, if price is in terms of ETH in an ETH/USDC market, this will convert it to terms of USDC
Sourcepub fn to_bigdecimal(&self) -> BigDecimal
pub fn to_bigdecimal(&self) -> BigDecimal
Return a new BigDecimal based on OrderRate
Sourcepub fn subtract_fee(&self, fee: BigDecimal) -> Self
pub fn subtract_fee(&self, fee: BigDecimal) -> Self
Subtract fee from user by adjusting the order rate downwards. This will keep track of as much precision as BigDecimal is capable of. However, this method is exclusively used by the smart contract and will be reduced to an integer in scale of 10^8 before encoding
Trait Implementations§
Source§impl From<OrderRate> for Rate
Enum wrappers are kind of annoying. This allows us to use .into()
on a value to generate a wrapped value. For example:
OrderRate::new("1").unwrap().into() => Rate::OrderRate(...)
impl From<OrderRate> for Rate
Enum wrappers are kind of annoying. This allows us to use .into()
on a value to generate a wrapped value. For example:
OrderRate::new("1").unwrap().into() => Rate::OrderRate(...)
impl StructuralPartialEq for OrderRate
Auto Trait Implementations§
impl Freeze for OrderRate
impl RefUnwindSafe for OrderRate
impl Send for OrderRate
impl Sync for OrderRate
impl Unpin for OrderRate
impl UnwindSafe for OrderRate
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more