order-book

module
v0.0.0-...-033d69a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2025 License: Apache-2.0

README

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)
    }
}

Directories

Path Synopsis
util

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL