GithubHelp home page GithubHelp logo

esse-byte / limit-order-book Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ziaagikian/limit-order-book

0.0 0.0 0.0 1.61 MB

Fast, Multi threaded and Efficient Trade Matching Engine

Shell 0.80% Python 97.03% Makefile 2.17%

limit-order-book's Introduction

Limit OrderBook

Fast OrderMatching Engine

Limited OrderBook application is developed to implement limit order functionality. FIFO based approach is followed and Price Priority algorithm is used to develop Matching Engine.

Architecture

Salient points and considerations are explained below.

  • Code for Matching Engine is developed keeping in mind HFT i-e High Frequency Trading.

  • Efficient Data Structures are implemented in such away to attain objectives for HFT.

  • Time complexity for critical operations are as.

    • Add – O(log M) for the first order at a limit, O(1) for all others
    • Cancel – O(1)
    • Execute – O(1)

    Where M is price Limit and << N

  • Data processing i-e store transaction and history logs operation are carried out on separate thread[s].The number of thread[s] are configurable and benchmark for 4 threads are given in thread_result.

  • Data between Main Thread and Worker Thread[s] is shared using Configurable Queues.

  • Batched Data is inserted in Database and batch size can be configured for different operations.

Installation

Pre requisite

  • python version > 3.0.0
  • Mongo version > 4.4.0

In order to run multi-threaded script MongoDB server need to be configured on Machine. Make script is developed to ease installation, configuring dependencies and has other util methods.

Install Dependencies

make deps-install
       OR
pip install -r requirements.txt

Install Application

make install

Test

#All Tests
make run-tests
# Single
python -m unittest test.testOrder

BenchMark

make run-benchmarks

Running

Large order file for benchmarking or testing.

script_runner.py < ./sample_data/largeOrder600K.txt

Multi-threaded script for inserting data in persistence layer.

threaded_script.py < sample_data/largeOrder600K.txt

Un Installation

make uninstall

Input Data Format

Limit Orderbook scripts expect the following input format i-e [in a DAT or txt file]

  • Bid or Sell => B or S
  • Order ID => Unique or autoincrementing Integer
  • Price => Integer
  • Quantity => Integer Sample Order format in a file can be

Sample Order => S,0,23,1000

Test Environment

Application is developed and tested on Ubuntu 18.04 x86_64 LTS with the following software version.

  • Python v3.8.5
  • Conda based Python Environment
  • MongoDB v4.4.3
  • 3rd Party/Official dependencies listed in requirement.txt

References

  1. Limit Order Book
  2. How to Build a Fast Limit Order Book

limit-order-book's People

Contributors

ziaagikian avatar

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.