Skip to main content

Orders

Users can create limit or market orders, modify orders, and cancel orders. The BalanceManager must have the necessary funds to process orders. DeepBookV3 has four order options and three self matching options. If you set the pay_with_deep flag to true, trading fees are paid with the DEEP token. If you set the pay_with_deep flag to false, trading fees are paid with the input token.

Users can modify their existing order, reducing the size, lowering the expiration time, or both. Users cannot modify their order to increase their size or increase their expiration time. To do that, they must cancel the original order and place a new order.

Users can cancel a single order or cancel all of their orders.

API

Following are the order related endpoints that Pool exposes.

Order options

The following constants define the options available for orders.

Self-matching options

The following constants define the options available for self-matching orders.

OrderInfo struct

Placing a limit order or a market order creates and returns an OrderInfo object. DeepBookV3 automatically drops this object after the order completes or is placed in the book. Use OrderInfo to inspect the execution details of the request as it represents all order information. DeepBookV3 does not catch any errors, so if there’s a failure of any kind, then the entire transaction fails.

OrderDeepPrice struct

The OrderDeepPrice struct represents the conversion rate of DEEP at the time the order was placed.

Fill struct

The Fill struct represents the results of a match between two orders. Use this struct to update the state.

Events

DeepBookV3 emits OrderFilled when a maker order is filled.

DeepBookV3 emits OrderCanceled when a maker order is canceled.

DeepBookV3 emits OrderModified on modification of a maker order.

DeepBookV3 emits OrderPlaced when it injects a maker order into the order book.

Place limit order

Place a limit order. Quantity is in base asset terms. For current version pay_with_deep must be true, so the fee is paid with DEEP tokens.

You must combine a BalanceManager call of generating a TradeProof before placing orders.

Place market order

Place a market order. Quantity is in base asset terms. Calls place_limit_order with a price of MAX_PRICE for bids and MIN_PRICE for asks. DeepBookV3 cancels the order for any quantity not filled.

Modify order

Modifies an order given order_id and new_quantity. New quantity must be less than the original quantity and more than the filled quantity. Order must not have already expired.

The modify_order function does not return anything. If the transaction is successful, then assume the modification was successful.

Cancel order

Cancel an order. The order must be owned by the balance_manager. The order is removed from the book and the balance_manager open orders. The balance_manager balance is updated with the order's remaining quantity.

Similar to modify, cancel_order does not return anything. DeepBookV3 emits OrderCanceled event.

Withdraw settled amounts

Withdraw settled amounts to the balance_manager. All orders automatically withdraw settled amounts. This can be called explicitly to withdraw all settled funds from the pool.

DeepBookV3 repository

The DeepBookV3 repository on GitHub.