pub struct OrderBook { /* private fields */ }Expand description
Order book for peer-to-peer trades.
Implementations§
Source§impl OrderBook
impl OrderBook
pub fn new() -> Self
Sourcepub fn create_order(
&mut self,
seller: &str,
sell_currency: &str,
sell_amount: u64,
buy_currency: &str,
price: u64,
) -> SellOrder
pub fn create_order( &mut self, seller: &str, sell_currency: &str, sell_amount: u64, buy_currency: &str, price: u64, ) -> SellOrder
Create a new sell order and add it to the book.
Returns the created order. The caller must ensure the seller has sufficient balance before listing — the order book does not escrow.
Sourcepub fn list_offers(
&self,
currency_pair: Option<(&str, &str)>,
) -> Vec<&SellOrder>
pub fn list_offers( &self, currency_pair: Option<(&str, &str)>, ) -> Vec<&SellOrder>
List all active orders, optionally filtered by currency pair.
When currency_pair is Some((sell, buy)), only orders matching
that exact pair are returned.
Sourcepub fn cancel_order(
&mut self,
id: &str,
seller: &str,
) -> Result<SellOrder, PaymentError>
pub fn cancel_order( &mut self, id: &str, seller: &str, ) -> Result<SellOrder, PaymentError>
Cancel an order. Only the original seller can cancel.
Sourcepub fn execute_swap(
&mut self,
id: &str,
buyer: &str,
ledger: &mut WebLedger,
) -> Result<SwapResult, PaymentError>
pub fn execute_swap( &mut self, id: &str, buyer: &str, ledger: &mut WebLedger, ) -> Result<SwapResult, PaymentError>
Execute a swap against an existing sell order.
Atomic: debits the buyer in buy_currency, credits the seller in
buy_currency, debits the seller in sell_currency, credits the
buyer in sell_currency, then removes the order.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for OrderBook
impl<'de> Deserialize<'de> for OrderBook
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for OrderBook
impl RefUnwindSafe for OrderBook
impl Send for OrderBook
impl Sync for OrderBook
impl Unpin for OrderBook
impl UnsafeUnpin for OrderBook
impl UnwindSafe for OrderBook
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
Mutably borrows from an owned value. Read more