Skip to content

m--s/order-matching-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple order matching engine

Basic implementation of the order book and order matching engine done in TypeScript.

Features:

  • market orders
  • limit orders
  • market/limit stop orders when price is higher/lower than condition
it('stop loss', () => {
    matchingEngine.match(new Order(OrderType.LIMIT, OrderSide.BUY, 10, 4));
    matchingEngine.match(new Order(OrderType.LIMIT, OrderSide.BUY, 10, 6));

    // place order & add stop loss
    expect(matchingEngine.stopOrders.length).toBe(0);
    matchingEngine.match(new Order(OrderType.LIMIT, OrderSide.BUY, 5, 6));
    matchingEngine.addStopOrder(new StopOrder(new Order(OrderType.MARKET, OrderSide.SELL, 5), 5, StopOrderCondition.LESS_THAN));
    expect(matchingEngine.stopOrders.length).toBe(1);

    // wild seller appears
    matchingEngine.match(new Order(OrderType.MARKET, OrderSide.SELL, 16));

    expect(matchingEngine.stopOrders.length).toBe(0);
    expect(matchingEngine.orderBook.bids[0].quantity).toBe(4);
});

About

Basic implementation of order book and order matching engine done in TypeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published