Skip to content

This is a prototype Go package to keep list of orders in an OrderBook

Notifications You must be signed in to change notification settings

shojaeix/go-orderlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

About

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.

How to use

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

Examples

import the package

import "github.com/shojaeix/go-order-list/order-list

Create a new list

bidsList := olist.OrderList{}

Set list's sort

bidsList.setSort("lowest") // lower bid must come first

Create a new order

newOrder := olist.Order{
   "price": 4302.23,
   "volume": 20,
}

Add order to list

id, err := bidsList.AddOrder(newOrder) // the newOrder.ID will overwrite

Get order row and volume ahead

row, volume, err := bidsList.GetRowAndAheadVolume(id)

Get edge order

edgeOrder := bidsList.GetEdgeOrder()

Get lowest and highest price

lowPrice, highPrice := bidsList.GetLowestAndHighestPrice()

Get total number and volume of orders

totalOrders, totalVolume := bidsList.GetTotals()

Update order

bidsList.UpdateOrder(orderId, newPrice, newVolume)

Delete order

bidsList.DeleteOrder(orderId)

TODO

  • Return callback chan in result of the AddOrder() func
  • Test
  • Implement the GetRowAndAheadVolume() func

About

This is a prototype Go package to keep list of orders in an OrderBook

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages