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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

orderId

uint256

The ID of the removed order.

setLmp

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

Parameters

Name
Type
Description

lmp

uint256

The last matched price.

mktPrice()

Retrieves the market price of the orderbook.

Returns

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

converted

uint256

The converted value of the asset.

isEmpty

Checks if the orderbook at the specified price is empty.

Parameters

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Variable
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

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

Name
Type
Description

owner

address

The address of the order owner.

heads()

Retrieves the head of the bid and ask orderbooks.

Returns

Name
Type
Description

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

Name
Type
Description

askHead

uint256

The head of the ask orderbook.

bidHead()

Retrieves the head of the bid orderbook.

Returns

Name
Type
Description

bidHead

uint256

The head of the bid orderbook.

getPrices

Retrieves the prices from the orderbook.

Parameters

Name
Type
Description

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

Name
Type
Description

prices

uint256[] memory

An array of prices retrieved from the orderbook.

getOrders

Retrieves the orders from the orderbook at the specified price.

Parameters

Name
Type
Description

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

Name
Type
Description

orders

NewOrderOrderbook.Order[] memory

An array of orders from the orderbook.

getOrder

Retrieves the order from the orderbook with the specified ID.

Parameters

Name
Type
Description

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

Name
Type
Description

order

NewOrderOrderbook.Order

The order from the orderbook.

getOrderIds

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

Parameters

Name
Type
Description

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

Name
Type
Description

orderIds

uint256[] memory

An array of order IDs from the orderbook.

Last updated