[][src]Struct nash_protocol::types::exchange::OrderRate

pub struct OrderRate { /* fields omitted */ }

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

impl OrderRate[src]

pub fn to_be_bytes(&self) -> Result<[u8; 8]>[src]

Serialize the OrderRate to bytes for payload creation. We always use a precision of 8 and multiplication factor of 10^8

pub fn from_be_bytes(bytes: [u8; 8]) -> Result<Self>[src]

Create OrderRate from big endian bytes in Ethereum FillOrder payload

impl OrderRate[src]

pub fn to_le_bytes(&self) -> Result<[u8; 8]>[src]

Serialize the OrderRate to bytes for payload creation. We always use a precision of 8 and multiplication factor of 10^8

impl OrderRate[src]

pub fn new(str_num: &str) -> Result<Self>[src]

Construct a new OrderRate from a numerical string

pub fn from_bigdecimal(decimal: BigDecimal) -> Self[src]

Create new OrderRate from bigdecimal

pub fn invert_rate(&self, precision: Option<u32>) -> Self[src]

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

pub fn to_bigdecimal(&self) -> BigDecimal[src]

Return a new BigDecimal based on OrderRate

pub fn subtract_fee(&self, fee: BigDecimal) -> Self[src]

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

impl Clone for OrderRate[src]

impl Debug for OrderRate[src]

impl From<OrderRate> for Rate[src]

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 PartialEq<OrderRate> for OrderRate[src]

impl StructuralPartialEq for OrderRate[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.