{"id":13412859,"url":"https://github.com/i25959341/orderbook","last_synced_at":"2025-03-14T18:32:25.248Z","repository":{"id":53116564,"uuid":"130894888","full_name":"i25959341/orderbook","owner":"i25959341","description":"Matching Engine for Limit Order Book in Golang","archived":false,"fork":false,"pushed_at":"2024-04-22T08:11:56.000Z","size":157,"stargazers_count":416,"open_issues_count":6,"forks_count":146,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-07-31T20:51:30.910Z","etag":null,"topics":["exchange","execution-engine","orderbook","trading"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i25959341.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-24T18:05:26.000Z","updated_at":"2024-07-22T22:21:59.000Z","dependencies_parsed_at":"2024-01-08T15:02:48.837Z","dependency_job_id":"11bc7e83-46f0-4397-8e9d-e1bad6e0b5f4","html_url":"https://github.com/i25959341/orderbook","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i25959341%2Forderbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i25959341%2Forderbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i25959341%2Forderbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i25959341%2Forderbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i25959341","download_url":"https://codeload.github.com/i25959341/orderbook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243625183,"owners_count":20321250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exchange","execution-engine","orderbook","trading"],"created_at":"2024-07-30T20:01:30.176Z","updated_at":"2025-03-14T18:32:24.932Z","avatar_url":"https://github.com/i25959341.png","language":"Go","funding_links":[],"categories":["Financial","Go","金融","金融领域相关库`处理货币与金融领域的库`","Relational Databases","金融领域相关库"],"sub_categories":["Search and Analytic Databases","检索及分析资料库","Advanced Console UIs","SQL 查询语句构建库"],"readme":"# Go orderbook\n\nImproved matching engine written in Go (Golang)\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/i25959341/orderbook)](https://goreportcard.com/report/github.com/i25959341/orderbook)\n[![GoDoc](https://godoc.org/github.com/i25959341/orderbook?status.svg)](https://godoc.org/github.com/i25959341/orderbook)\n[![gocover.run](https://gocover.run/github.com/i25959341/orderbook.svg?style=flat\u0026tag=1.10)](https://gocover.run?tag=1.10\u0026repo=github.com%2Fi25959341%2Forderbook)\n[![Stability: Active](https://masterminds.github.io/stability/active.svg)](https://masterminds.github.io/stability/active.html)\n[![Build Status](https://travis-ci.org/i25959341/orderbook.svg?branch=master)](https://travis-ci.org/i25959341/orderbook)\n\n## Features\n\n- Standard price-time priority\n- Supports both market and limit orders\n- Supports order cancelling\n- High performance (above 300k trades per second)\n- Optimal memory usage\n- JSON Marshalling and Unmarsalling\n- Calculating market price for definite quantity\n\n## Usage\n\nTo start using order book you need to create object:\n\n```go\nimport (\n  \"fmt\" \n  ob \"github.com/muzykantov/orderbook\"\n)\n\nfunc main() {\n  orderBook := ob.NewOrderBook()\n  fmt.Println(orderBook)\n}\n\n```\n\nThen you be able to use next primary functions:\n\n```go\n\nfunc (ob *OrderBook) ProcessLimitOrder(side Side, orderID string, quantity, price decimal.Decimal) (done []*Order, partial *Order, err error) { ... }\n\nfunc (ob *OrderBook) ProcessMarketOrder(side Side, quantity decimal.Decimal) (done []*Order, partial *Order, quantityLeft decimal.Decimal, err error) { .. }\n\nfunc (ob *OrderBook) CancelOrder(orderID string) *Order { ... }\n\n```\n\n## About primary functions\n\n### ProcessLimitOrder\n\n```go\n// ProcessLimitOrder places new order to the OrderBook\n// Arguments:\n//      side     - what do you want to do (ob.Sell or ob.Buy)\n//      orderID  - unique order ID in depth\n//      quantity - how much quantity you want to sell or buy\n//      price    - no more expensive (or cheaper) this price\n//      * to create new decimal number you should use decimal.New() func\n//        read more at https://github.com/shopspring/decimal\n// Return:\n//      error   - not nil if quantity (or price) is less or equal 0. Or if order with given ID is exists\n//      done    - not nil if your order produces ends of anoter order, this order will add to\n//                the \"done\" slice. If your order have done too, it will be places to this array too\n//      partial - not nil if your order has done but top order is not fully done. Or if your order is\n//                partial done and placed to the orderbook without full quantity - partial will contain\n//                your order with quantity to left\n//      partialQuantityProcessed - if partial order is not nil this result contains processed quatity from partial order\nfunc (ob *OrderBook) ProcessLimitOrder(side Side, orderID string, quantity, price decimal.Decimal) (done []*Order, partial *Order, err error) { ... }\n```\n\nFor example:\n```\nProcessLimitOrder(ob.Sell, \"uinqueID\", decimal.New(55, 0), decimal.New(100, 0))\n\nasks: 110 -\u003e 5      110 -\u003e 5\n      100 -\u003e 1      100 -\u003e 56\n--------------  -\u003e  --------------\nbids: 90  -\u003e 5      90  -\u003e 5\n      80  -\u003e 1      80  -\u003e 1\n\ndone    - nil\npartial - nil\n\n```\n\n```\nProcessLimitOrder(ob.Buy, \"uinqueID\", decimal.New(7, 0), decimal.New(120, 0))\n\nasks: 110 -\u003e 5\n      100 -\u003e 1\n--------------  -\u003e  --------------\nbids: 90  -\u003e 5      120 -\u003e 1\n      80  -\u003e 1      90  -\u003e 5\n                    80  -\u003e 1\n\ndone    - 2 (or more orders)\npartial - uinqueID order\n\n```\n\n```\nProcessLimitOrder(ob.Buy, \"uinqueID\", decimal.New(3, 0), decimal.New(120, 0))\n\nasks: 110 -\u003e 5\n      100 -\u003e 1      110 -\u003e 3\n--------------  -\u003e  --------------\nbids: 90  -\u003e 5      90  -\u003e 5\n      80  -\u003e 1      90  -\u003e 5\n\ndone    - 1 order with 100 price, (may be also few orders with 110 price) + uinqueID order\npartial - 1 order with price 110\n\n```\n\n### ProcessMarketOrder\n\n```go\n// ProcessMarketOrder immediately gets definite quantity from the order book with market price\n// Arguments:\n//      side     - what do you want to do (ob.Sell or ob.Buy)\n//      quantity - how much quantity you want to sell or buy\n//      * to create new decimal number you should use decimal.New() func\n//        read more at https://github.com/shopspring/decimal\n// Return:\n//      error        - not nil if price is less or equal 0\n//      done         - not nil if your market order produces ends of anoter orders, this order will add to\n//                     the \"done\" slice\n//      partial      - not nil if your order has done but top order is not fully done\n//      partialQuantityProcessed - if partial order is not nil this result contains processed quatity from partial order\n//      quantityLeft - more than zero if it is not enought orders to process all quantity\nfunc (ob *OrderBook) ProcessMarketOrder(side Side, quantity decimal.Decimal) (done []*Order, partial *Order, quantityLeft decimal.Decimal, err error) { .. }\n```\n\nFor example:\n```\nProcessMarketOrder(ob.Sell, decimal.New(6, 0))\n\nasks: 110 -\u003e 5      110 -\u003e 5\n      100 -\u003e 1      100 -\u003e 1\n--------------  -\u003e  --------------\nbids: 90  -\u003e 5      80 -\u003e 1\n      80  -\u003e 2\n\ndone         - 2 (or more orders)\npartial      - 1 order with price 80\nquantityLeft - 0\n\n```\n\n```\nProcessMarketOrder(ob.Buy, decimal.New(10, 0))\n\nasks: 110 -\u003e 5\n      100 -\u003e 1\n--------------  -\u003e  --------------\nbids: 90  -\u003e 5      90  -\u003e 5\n      80  -\u003e 1      80  -\u003e 1\n                    \ndone         - 2 (or more orders)\npartial      - nil\nquantityLeft - 4\n\n```\n\n### CancelOrder\n\n```go\n// CancelOrder removes order with given ID from the order book\nfunc (ob *OrderBook) CancelOrder(orderID string) *Order { ... }\n```\n\n```\nCancelOrder(\"myUinqueID-Sell-1-with-100\")\n\nasks: 110 -\u003e 5\n      100 -\u003e 1      110 -\u003e 5\n--------------  -\u003e  --------------\nbids: 90  -\u003e 5      90  -\u003e 5\n      80  -\u003e 1      80  -\u003e 1\n                    \ndone         - 2 (or more orders)\npartial      - nil\nquantityLeft - 4\n\n```\n\n## License\n\nThe MIT License (MIT)\n\nSee LICENSE and AUTHORS files\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi25959341%2Forderbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi25959341%2Forderbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi25959341%2Forderbook/lists"}