This package will help you to keep your bids/asks list with minimum memory usage and fast speed.
This package supports dynamic-resizing mechanism and have n(1) time complexity in most operations.
After importing the package, you should create a new variable with type OrderList
.
Then you can use below functions to work on your list
- add/delete/update order
- get order's row and ahead volume
- get unique ID for each order
- get lowest/highest price and order
- get total number and volume of orders
import "github.com/shojaeix/go-order-list/order-list
bidsList := olist.OrderList{}
bidsList.setSort("lowest") // lower bid must come first
newOrder := olist.Order{
"price": 4302.23,
"volume": 20,
}
id, err := bidsList.AddOrder(newOrder) // the newOrder.ID will overwrite
row, volume, err := bidsList.GetRowAndAheadVolume(id)
edgeOrder := bidsList.GetEdgeOrder()
lowPrice, highPrice := bidsList.GetLowestAndHighestPrice()
totalOrders, totalVolume := bidsList.GetTotals()
bidsList.UpdateOrder(orderId, newPrice, newVolume)
bidsList.DeleteOrder(orderId)
- Return callback chan in result of the AddOrder() func
- Test
- Implement the GetRowAndAheadVolume() func