Coder Social home page Coder Social logo

boerberl's Introduction

Market Data Processing

💡 This repository aims to provide code with good readability and consistent style for the given prompt in C++20.

Formatting

Language Formatter Style Guide Configuration
C++ ClangFormat Google C++ Style Guide .clang-format
C++ files should end in .cc and header files should end in .h. Files that rely on being textually included at specific points should end in .inc (see also the section on self-contained headers).

Do not use filenames that already exist in /usr/include, such as db.h.

In general, make your filenames very specific. For example, use http_server_logs.h rather than logs.h. A very common case is to have a pair of files called, e.g., foo_bar.h and foo_bar.cc, defining a class called FooBar.

Objective

Create a C++ function to process and efficiently store market data. The user should be able to retrieve the latest top-of-book market data snapshot by symbol.

Function Signature

void on_market_data(char const* data);

Input Data Format

The function will receive a stream of strings with the following format:

<SYMBOL> <BID_PRICE> <ASK_PRICE> <BID_SIZE> <ASK_SIZE>\n
  • Each item in the string is separated by a space.
  • Each string is delimited by a newline (\n).

Build and Run:

  1. Create a build directory: mkdir build && cd build
  2. Configure CMake: cmake ..
  3. Build: cmake --build .
  4. Run Clang-Tidy (optional, TODO: troubleshoot): cmake --build . --target clang-tidy
  5. Run Clang-Format (optional, TODO: troubleshoot): clang-format -i src/* test/*
  6. Run Tests: ctest

Sample Usage:

Build and Run tests

Build and Run tests screenshot

Read from input file

input file output screenshot

Read from user input

Important:

  • The code reads lines from the standard input until the end of the file (EOF) is reached.

  • Usually, the user needs to use Ctrl+D on Unix-like systems or Ctrl+Z followed by Enter on Windows systems.

  • In the following example, the user used a Macbook. After the first line, they pressed Enter to write on additional lines and finally used Ctrl+D.

user input screenshot

Sample Data:

Terminology:

  • Level 1 or top-of-book market data provides the highest bid and the lowest ask across multiple exchanges (or a single exchange).

Future Improvements:

  1. Keep the state while continously processing new user market data input.
  2. Add the ability to filter on multiple symbols simultaneously.
  3. Add the ability to also filter on bid price, ask price, bid size, and ask size either individually or simultaneously.
  4. Increase test coverage.
  5. Add logging. For example, if the ask price was lower than the bid price note that we observed a “crossed market”.
  6. Use std::multimap if we eventually incorporate level 2 market data.
  7. Consider displaying the spread as a percent.
  8. Consider adding the volume data.
  9. Consider adding the last trade price.

References

License

Licensed under the MIT License, Copyright © 2019-2024 Axel Iota.

Assembled with ❤️ in New York.

boerberl's People

Contributors

iotaaxel avatar

Watchers

 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.