https://github.com/danielgatis/go-orderbook
The pkg go-orderbook implements a limit order book for high-frequency trading (HFT), as described by WK Selph.
https://github.com/danielgatis/go-orderbook
exchange matching-engine orderbook
Last synced: 2 months ago
JSON representation
The pkg go-orderbook implements a limit order book for high-frequency trading (HFT), as described by WK Selph.
- Host: GitHub
- URL: https://github.com/danielgatis/go-orderbook
- Owner: danielgatis
- License: mit
- Created: 2021-12-11T00:14:08.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-08T02:41:25.000Z (about 2 years ago)
- Last Synced: 2025-03-19T00:06:42.324Z (7 months ago)
- Topics: exchange, matching-engine, orderbook
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 22
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go - Orderbook
[](https://goreportcard.com/report/github.com/danielgatis/go-orderbook)
[](https://raw.githubusercontent.com/danielgatis/go-orderbook/master/LICENSE)
[](https://godoc.org/github.com/danielgatis/go-orderbook)The pkg `go-orderbook` implements a limit order book for high-frequency trading (HFT), as described by WK Selph.
Based on WK Selph's Blogpost:
https://goo.gl/KF1SRm## Install
```bash
go get -u github.com/danielgatis/go-orderbook
```And then import the package in your code:
```go
import "github.com/danielgatis/go-orderbook"
```### Example
An example described below is one of the use cases.
```go
package mainimport (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"time""github.com/danielgatis/go-orderbook"
"github.com/google/uuid"
"github.com/shopspring/decimal"
)func main() {
book := orderbook.NewOrderBook("BTC/BRL")for i := 0; i < 10; i++ {
rand.Seed(time.Now().UnixNano())
side := []orderbook.Side{orderbook.Buy, orderbook.Sell}[rand.Intn(2)]book.ProcessPostOnlyOrder(uuid.New().String(), uuid.New().String(), side, decimal.NewFromInt(rand.Int63n(1000)), decimal.NewFromInt(rand.Int63n(1000)))
}depth, _ := json.Marshal(book.Depth())
var buf bytes.Buffer
json.Indent(&buf, depth, "", " ")
fmt.Println(buf.String())
}
``````
❯ go run main.go
{
"bids": [
{
"amount": "392",
"price": "930"
},
{
"amount": "872",
"price": "907"
},
{
"amount": "859",
"price": "790"
},
{
"amount": "643",
"price": "424"
},
{
"amount": "269",
"price": "244"
},
{
"amount": "160",
"price": "83"
},
{
"amount": "74",
"price": "65"
}
],
"asks": [
{
"amount": "178",
"price": "705"
},
{
"amount": "253",
"price": "343"
},
{
"amount": "805",
"price": "310"
}
]
}
```## License
Copyright (c) 2020-present [Daniel Gatis](https://github.com/danielgatis)
Licensed under [MIT License](./LICENSE)
### Buy me a coffee
Liked some of my work? Buy me a coffee (or more likely a beer)