NewOrderLinkedList
This library implements a linked list data structure for managing orderbook prices.
Variables
PriceLinkedList
(struct)
PriceLinkedList
(struct)a storage struct type for storing price linked lists
Property | Type | Description |
---|---|---|
bidPrices | mapping(uint256 => uint256) | Hashmap-style linked list of bid prices, where key is the price and value is the next_price (next_price < price). |
askPrices | mapping(uint256 => uint256) | Hashmap-style linked list of ask prices, where key is the price and value is the next_price (next_price > price). |
bidHead | uint256 | Head of the bid price linked list (i.e., the highest bid price). |
askHead | uint256 | Head of the ask price linked list (i.e., the lowest ask price). |
lmp | uint256 | Last matched price. |
Internal Functions
_setLmp
_setLmp
Sets the last matched price in the PriceLinkedList.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList storage | The storage reference to the PriceLinkedList struct. |
lmp_ | uint256 | The last matched price to set. |
_heads
_heads
Returns the heads of the ask and bid price linked lists.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList storage | The storage reference to the PriceLinkedList struct. |
Returns
Name | Type | Description |
---|---|---|
askHead | uint256 | The head of the ask price linked list. |
bidHead | uint256 | The head of the bid price linked list. |
_askHead
_askHead
Returns the head of the ask price linked list.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList storage | The storage reference to the PriceLinkedList struct. |
Returns
Name | Type | Description |
---|---|---|
askHead | uint256 | The head of the ask price linked list. |
_bidHead
_bidHead
Returns the head of the bid price linked list.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList storage | The storage reference to the PriceLinkedList struct. |
Returns
Name | Type | Description |
---|---|---|
bidHead | uint256 | The head of the bid price linked list. |
_mktPrice
_mktPrice
Returns the last matched price.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList | The storage reference to the PriceLinkedList struct. |
Returns
Name | Return Type | Description |
---|---|---|
mktPrice | uint256 | Returns the last matched price. |
_next
_next
Returns the next price in the linked list based on the current price and whether it is a bid or ask price.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList storage | The storage reference to the PriceLinkedList struct. |
isBid | bool | A flag indicating whether the current price is a bid price. |
price | uint256 | The current price. |
Returns
Name | Type | Description |
---|---|---|
next | uint256 | The next price in the linked list. |
_insert
_insert
Inserts a new price into the linked list based on whether it is a bid or ask price. The new price is inserted in the correct position, maintaining the order of the linked list.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList | The storage reference to the PriceLinkedList struct. |
isBid | bool | A flag indicating whether the price is a bid price. |
price | uint256 | The price to insert. |
_getPrices
_getPrices
Retrieves an array of prices from the linked list, starting from the head and moving to the next price in the specified direction (bid or ask). The number of prices returned is limited by the n
parameter.
Parameters
Name | Type | Description |
---|---|---|
self | PriceLinkedList | The storage reference to the PriceLinkedList struct. |
isBid | bool | A flag indicating the direction of the prices to retrieve. |
n | uint256 | The maximum number of prices to retrieve. |
Returns
Name | Type | Description |
---|---|---|
prices | uint256[] memory | An array of prices retrieved from the linked list. |
Last updated