Orderbook
State Variables
pair
Pair (Private Struct)
Represents the pair of assets being traded in the orderbook. Contains the pair's ID, base asset address, quote asset address, and engine contract address.
decDiff
uint64 (Private)
The decimal difference used for converting between base and quote assets.
baseBquote
bool (Private)
Indicates whether the base asset is the quote asset or not.
priceLists
NewOrderLinkedList.PriceLinkedList (Private Instance)
An instance of the NewOrderLinkedList.PriceLinkedList struct representing the price linked list.
_askOrders
NewOrderOrderbook.OrderStorage (Private Instance)
An instance of the NewOrderOrderbook.OrderStorage struct representing the ask orders in the orderbook.
_bidOrders
NewOrderOrderbook.OrderStorage (Private Instance)
An instance of the NewOrderOrderbook.OrderStorage struct representing the bid orders in the orderbook.
Functions
initialize
initialize
Initializes the orderbook contract with the provided parameters.
Parameters
id_
uint256
The identifier for the pair
base_
address
The address of the base asset
quote_
address
The address of the quote asset
engine_
address
The address of the engine contract
setLmp
setLmp
Sets the last matched price in the price linked list.
Parameters
price
uint256
The last matched price.
placeAsk
placeAsk
Places an ask order in the orderbook.
Parameters
owner
address
The address of the order owner.
price
uint256
The price of the ask order.
amount
uint256
The amount of the ask order.
placeBid
placeBid
Places a bid order in the orderbook.
Parameters
owner
address
The address of the order owner.
price
uint256
The price of the bid order.
amount
uint256
The amount of the bid order.
cancelOrder
cancelOrder
Cancels an order from the orderbook.
Parameters
orderId
uint256
The identifier of the order to cancel.
isBid
bool
Indicates whether the order is a bid order.
owner
address
The address of the order owner.
Returns
remaining
uint256
The remaining amount of the canceled order.
base
address
The address of the base asset.
quote
address
The address of the quote asset.
execute
execute
Executes an order from the orderbook.
Parameters
orderId
uint256
The identifier of the order to execute.
isBid
bool
Indicates whether the order is a bid order.
price
uint256
The price at which the order is executed.
sender
address
The address of the sender executing the order.
amount
uint256
The amount of the order to execute.
Returns
owner
address
The address of the order owner.
fpop
fpop
Pops the first order with the given price from the orderbook.
Parameters
isBid
bool
Indicates whether the order is a bid order.
price
uint256
The price of the order to pop.
Returns
orderId
uint256
The identifier of the popped order.
getRequired
getRequired
Retrieves the required amount for executing the order.
Parameters
isBid
bool
Indicates whether the order is a bid order or not.
price
uint256
The price at which the order is executed.
orderId
uint256
The identifier of the order.
Returns
required
uint256
The required amount for executing the order.
heads()
heads()
Retrieves the head prices of the bid and ask lists.
Returns
bidHead
uint256
The head price of the bid list.
askHead
uint256
The head price of the ask list.
askHead()
askHead()
Retrieves the head price of the ask list.
Returns
askHead
uint256
The head price of the ask list.
bidHead()
bidHead()
Retrieves the head price of the bid list.
Returns
bidHead
uint256
The head price of the bid list.
mktPrice()
mktPrice()
Retrieves the market's last matched price.
Returns
mktPrice
uint256
The market price.
getPrices
getPrices
Retrieves the prices from the bid or ask list.
Parameters
isBid
bool
Indicates whether to retrieve prices from the bid list or the ask list.
n
uint256
The number of prices to match with.
Returns
prices
uint256[] memory
An array of prices.
getOrderIds
getOrderIds
Retrieves the order IDs at a specific price from the bid or ask list.
Parameters
isBid
bool
Indicates whether to retrieve order IDs from the bid list or the ask list.
price
uint256
The price to retrieve order IDs for.
n
uint256
The number of order IDs to retrieve.
Returns
orderIds
uint256[] memory
An array of order IDs.
getOrders
getOrders
Retrieves the orders at a specific price from the bid or ask list.
Parameters
isBid
bool
Indicates whether to retrieve orders from the bid list or the ask list.
price
uint256
The price to retrieve orders for.
n
uint256
The number of orders to retrieve.
Returns
orders
NewOrderOrderbook.Order[] memory
An array of orders.
getOrder
getOrder
Retrieves a specific order from the bid or ask list.
Parameters
isBid
bool
Indicates whether to retrieve the order from the bid list or the ask list.
orderId
uint256
The identifier of the order to retrieve.
Returns
order
NewOrderOrderbook.Order
The order.
assetValue
assetValue
Retrieves the asset value in the quote asset if isBid
is true, otherwise retrieves the asset value in the base asset.
Parameters
amount
uint256
The amount of the asset.
isBid
bool
Indicates whether to retrieve the asset value in the quote asset or the base asset.
Returns
converted
uint256
The converted asset value.
Last updated