# Orderbook A Rust interface for interacting with an orderbook smart contract. Supports limit orders, market orders, and order management. ## Quick Reference ```rust // Initialize let orderbook = Orderbook::new("0x1234...", provider).await?; // Place limit orders let (tx_hash, order_id) = orderbook.add_buy_order("100.5", "1.5", false, None, None).await?; let (tx_hash, order_id) = orderbook.add_sell_order("101.0", "2.0", false, None, None).await?; // Place market orders let tx_hash = orderbook.market_buy("1.5", "150", false, false, None, None).await?; let tx_hash = orderbook.market_sell("2.0", "190", false, false, None, None).await?; // Cancel orders let tx_hash = orderbook.batch_cancel_orders(&vec![order_id1, order_id2], None, None).await?; // View orderbook let book = orderbook.fetch_orderbook().await?; ``` ## Main Types ### Order Types ```rust pub enum Order { Limit(LimitOrder), Market(MarketOrder) } pub struct LimitOrder { pub price: String, pub size: String, pub order_type: OrderSide, pub post_only: bool, } pub struct MarketOrder { pub size: String, pub min_amount_out: String, pub is_margin: bool, pub order_type: OrderSide, pub fill_or_kill: bool, } ``` ### Error Types ```rust pub enum OrderbookError { TxBuildError, TransactionError, BuyOrderError, SellOrderError, InsufficiantBalance, InactiveMarket, NormalizationError, FunctionNotFound, EncodingError, GasEstimationError, GasPriceError, } ``` ## Key Methods ### Order Management - `add_buy_order(price, size, post_only, gas_price?, gas_limit?) -> (tx_hash, order_id)` - `add_sell_order(price, size, post_only, gas_price?, gas_limit?) -> (tx_hash, order_id)` - `market_buy(size, min_amount_out, is_margin, fill_or_kill, gas_price?, gas_limit?) -> tx_hash` - `market_sell(size, min_amount_out, is_margin, fill_or_kill, gas_price?, gas_limit?) -> tx_hash` - `batch_cancel_orders(order_ids, gas_price?, gas_limit?) -> tx_hash` ### View Methods - `fetch_orderbook() -> L2Book`: Returns current orderbook state - `check_order_status(order_id) -> OrderStatus`: Check status of an order - `get_vault_params() -> VaultParams`: Get AMM vault parameters - `amm_prices() -> (Vec, Vec)`: Get AMM bid/ask prices ### Utility Methods - `base_and_quote_assets() -> (Address, Address)` - `base_and_quote_decimals() -> (U256, U256)` - `address() -> Address` ## Notes - All monetary values should be passed as strings - Gas parameters are optional - Price/size values are automatically normalized based on contract decimals - Supports both regular limit/market orders and margin trading - Includes AMM integration for additional liquidity