Skip to content

1. Terminology

ArjunVachhani-CCM edited this page Jun 30, 2023 · 3 revisions

Order

Order is an intent to buy or sell a specific quantity of stock at a desired price. The order includes information such as OrderId, UserId, Price, Quantity, Side(buy or sell), etc.

PriceLevel

PriceLevel is a collection of orders at the same price. A PriceLevel can contain multiple orders at the same price of same side. All Orders of Pricelevels are stored and exceuted in FIFO manner. PriceLevels are maintained for Limit orders and Stop Orders. PriceLevel also contain aggregate information such as total quantity at and no. of orders for that price.

OrderBook

OrderBook maintains PriceLevels. One OrderBook contains 4 ordered collection of PriceLevels. PricelLevels are sorted based on price. For limit buy side, PriceLevels are sorted by price in descending order. for limit sell side, PriceLevels are sorted by price in ascending order. Order Book also maintains PriceLevels for stop orders. For stop buy side price levels are sorted by stop price in ascending order and stop sell side are sorted by descending order.

  1. Bid Side Price Levels
  2. Ask Side Price Levels
  3. Stop Bid Price Levels
  4. Stop Ask Price Levels

MatchingEngine

MatchingEngine is responsible for order execution. Each MatchingEngine Instance internally maintains OrderBook. it exposes method to add new order and cancel order. it also triggers events when order is accepted, matched, cancelled, or stop order is triggered.

ITradeListener

MatchingEngine sends evets to ITradeListener instance. An instance of ITradeListener should be passed to MatchingEngine to listen to events emitted by MatchingEngine. MatchingEngine exceutes method on ITradeListner for all the events. ITradeListener can then forward this information to other component to update state of the order, fills and balance. Below events are available on ITradeListner.

  1. Order Accept
  2. Order Cancel
  3. Match
  4. Self Match
  5. Decrement Quantity

IFeeProvider

MatchingEngine calcualtes fee on the order. Fees can be provided by IFeeProvider instance. IFeeProvider is queried everytime when match occures. This allows configuring different fee for different tiers of users. MatchingEngine supports maker and take fee model. maker order provides liquidity while taker order takes liquidity. MatchingEngine calculates fee and passes that information to ITradeListener when order is filled completely or cancelled.

Serializers

Serializers converts objects to byte array and vice versa. You could use any serializers(Json, Bson, Protobuf, msgapck) you like but serializers provided with order-matcher are fast and works with order matcher types only.

Clone this wiki locally