IOrderbook

This interface defines the functions that can be called on the Orderbook contract. These functions provide various operations related to initializing the orderbook, managing orders, retrieving orderbook information, and executing trades.

Functions

initialize

Initializes the orderbook with the specified ID, base asset, quote asset, and engine address.

Parameters

NameTypeDescription

id

uint256

The ID of the orderbook.

base_

address

The address of the base asset in the pair.

quote_

address

The address of the quote asset in the pair.

engine_

address

The address of the engine contract.

fpop

Removes and returns the first order from the orderbook at the specified price.

Parameters

NameTypeDescription

isBid

bool

Flag indicating whether the order is a bid (true) or ask (false).

price

uint256

The price at which the order is placed.

Returns

NameTypeDescription

orderId

uint256

The ID of the removed order.

setLmp

Sets the last matched price (LMP) of the orderbook.

Parameters

NameTypeDescription

lmp

uint256

The last matched price.

mktPrice()

Retrieves the market price of the orderbook.

Returns

NameTypeDescription

mktPrice

uint256

The market price of the orderbook.

assetValue

Converts the specified amount of base or quote asset to its corresponding value in the other asset.

Parameters

NameTypeDescription

amount

uint256

The amount of the asset to convert.

isBid

bool

Flag indicating whether the asset is a bid asset (true) or ask asset (false).

Returns

NameTypeDescription

converted

uint256

The converted value of the asset.

isEmpty

Checks if the orderbook at the specified price is empty.

Parameters

NameTypeDescription

isBid

bool

Flag indicating whether the orderbook is a bid orderbook (true) or ask orderbook (false).

price

uint256

The price at which to check.

Returns

NameTypeDescription

isEmpty

bool

Flag indicating if the orderbook at the specified price is empty.

getRequired

Retrieves the required amount to execute the specified order at the given price.

Parameters

NameTypeDescription

isBid

bool

Flag indicating whether the order is a bid (true) or ask (false).

price

uint256

The price at which the order is placed.

orderId

uint256

The ID of the order.

Returns

NameTypeDescription

required

uint256

The required amount to execute the order.

placeAsk

Places an ask order in the orderbook with the specified owner, price, and amount.

Parameters

NameTypeDescription

owner

address

The address of the order owner.

price

uint256

The price at which to place the ask order.

amount

uint256

The amount of the ask order.

placeBid

Places a bid order in the orderbook with the specified owner, price, and amount.

Parameters

VariableTypeDescription

owner

address

The address of the order owner.

price

uint256

The price at which to place the ask order.

amount

uint256

The amount of the ask order.

cancelOrder

Cancels the specified order in the orderbook.

Parameters

NameTypeDescription

orderId

uint256

The ID of the order to cancel.

isBid

bool

Flag indicating whether the order is a bid (true) or ask (false).

owner

address

The address of the order owner.

Returns

NameTypeDescription

remaining

uint256

The remaining amount of the canceled order.

base

address

The address of the base asset of the canceled order.

quote

address

The address of the quote asset of the canceled order.

execute

Executes the specified order at the given price and amount.

Parameters

NameTypeDescription

orderId

uint256

The ID of the order to execute.

isBid

bool

Flag indicating whether the order is a bid (true) or ask (false).

price

uint256

The price at which to execute the order.

sender

address

The address of the sender executing the order.

amount

uint256

The amount to execute.

Returns

NameTypeDescription

owner

address

The address of the order owner.

heads()

Retrieves the head of the bid and ask orderbooks.

Returns

NameTypeDescription

bidHead

uint256

The head of the bid orderbook.

askHead

uint256

The head of the ask orderbook.

askHead()

Retrieves the head of the ask orderbook.

Returns

NameTypeDescription

askHead

uint256

The head of the ask orderbook.

bidHead()

Retrieves the head of the bid orderbook.

Returns

NameTypeDescription

bidHead

uint256

The head of the bid orderbook.

getPrices

Retrieves the prices from the orderbook.

Parameters

NameTypeDescription

isBid

bool

Flag indicating whether to retrieve prices from the bid orderbook (true) or ask orderbook (false).

n

uint256

The number of prices to retrieve.

Returns

NameTypeDescription

prices

uint256[] memory

An array of prices retrieved from the orderbook.

getOrders

Retrieves the orders from the orderbook at the specified price.

Parameters

NameTypeDescription

isBid

bool

Flag indicating whether to retrieve orders from the bid orderbook (true) or ask orderbook (false).

price

uint256

The price at which to retrieve orders.

n

uint256

The number of orders to retrieve.

Returns

NameTypeDescription

orders

NewOrderOrderbook.Order[] memory

An array of orders from the orderbook.

getOrder

Retrieves the order from the orderbook with the specified ID.

Parameters

NameTypeDescription

isBid

bool

Flag indicating whether to retrieve the order from the bid orderbook (true) or ask orderbook (false).

orderId

uint256

The ID of the order to retrieve.

Returns

NameTypeDescription

order

NewOrderOrderbook.Order

The order from the orderbook.

getOrderIds

Retrieves the order IDs from the orderbook at the specified price.

Parameters

NameTypeDescription

isBid

bool

Flag indicating whether to retrieve order IDs from the bid orderbook (true) or ask orderbook (false).

price

uint256

The price at which to retrieve order IDs.

n

uint256

The number of order IDs to retrieve.

Returns

NameTypeDescription

orderIds

uint256[] memory

An array of order IDs from the orderbook.

Last updated