Giter Site home page Giter Site logo

order-book-matching-engine's Introduction

Order Book Matching Engine (Low Latency)

Latency to match an order with a thick order book: ~1us.

No dependencies required (except Java).

Example

OrderBookEngine engine = new OrderBookEngine();
// Bid
// <99.95, 100>
//<99.90, 50>
//<99.85,50>
engine.onOrder(99.95, 100, OrderBookEngine.Side.BUY);
engine.onOrder(99.90, 50, OrderBookEngine.Side.BUY);
engine.onOrder(99.85, 50, OrderBookEngine.Side.BUY);

// Ask
// <100.00, 1000>
// <100.05, 50>
// <100.10, 90>
engine.onOrder(100.0, 1000, OrderBookEngine.Side.SELL);
engine.onOrder(100.05, 50, OrderBookEngine.Side.SELL);
engine.onOrder(100.10, 90, OrderBookEngine.Side.SELL);

engine.printOrderBook();

engine.onOrder(99.97, 1, OrderBookEngine.Side.BUY);
engine.onOrder(100.0, 1, OrderBookEngine.Side.BUY);

engine.printOrderBook();
System.out.println(engine.getBBO());
___ ORDER BOOK ___
Asks:
90 @ 100.1
50 @ 100.05
999 @ 100.0
Bids:
1 @ 99.97
100 @ 99.95
50 @ 99.9
50 @ 99.85
_________________
BBO{bid_price=99.97, bid_quantity=1.0, ask_price=100.0, ask_quantity=999.0}

order-book-matching-engine's People

Contributors

philipperemy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

order-book-matching-engine's Issues

Issue in buying and selling order

If there are 3 bid orders

<99.95, 100>
<99.90, 50>
<99.85,50>

and 3 ask orders

<100.00, 1000>
<100.05, 50>
<100.10, 90>

if a new bid(buy) order comes for <99.97, 1> then

for (double ask_price : ask_prices_list) {
	if (quantity > 0 && price >= ask_price) {

will be false since price(99.97) is not greater than ask_price(100.00) and the order is never executed.
This is a bug. i guess same issue with sell order as well

Improving for loop

In the receiveOrder function, you dont need to go over all the ask and bid orders right? Once the quantity is 0, you can exit the for loop.

Lets say there are 1million ask orders and a new bid order comes for just 1 quantity with sutiable price. Then even after satisfying the order, you will still iterate 1million - 1 times which is not needed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.