Skip to content

0xarash/order-book

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Order Book

A lightweight and efficient order book implementation in Go. I developed this project while learning Go, so it may include some unconventional or non-idiomatic uses of the language. It supports limit and market orders on both sides (buy/sell). The project uses a custom fixed-point number module for precise arithmetic, though it is still a work in progress.

Installation

Clone the repository and install dependencies:

git clone https://github.com/0xarash/order-book.git
cd order-book
go mod tidy

Usage Example

Here’s a minimal example of how to create and use the order book:

package main

import (
    "fmt"
    "github.com/0xarash/order-book/book"
    "github.com/0xarash/order-book/util/fixed"
)

func main() {
    ob := book.NewOrderBook()

    // Add a limit buy order
    ob.Add(book.LimitOrder, &book.AddParam{
        Price:    fixed.New(100.0, 2),
        Quantity: fixed.New(5.0, 2),
        OrderId:  1,
        Side:     book.BuySide,
    })

    // Add a limit sell order
    trades := ob.Add(book.LimitOrder, &book.AddParam{
        Price:    fixed.New(99.0, 2),
        Quantity: fixed.New(3.0, 2),
        OrderId:  2,
        Side:     book.SellSide,
    })

    // Print resulting trades
    for _, trade := range trades {
        fmt.Printf("Trade executed: %+v\n", trade)
    }
}

About

Simple order book implementation in Go language

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages