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.
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.
void on_market_data(char const* data);
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
).
- Create a
build
directory:mkdir build && cd build
- Configure CMake:
cmake ..
- Build:
cmake --build .
- Run Clang-Tidy (optional, TODO: troubleshoot):
cmake --build . --target clang-tidy
- Run Clang-Format (optional, TODO: troubleshoot):
clang-format -i src/* test/*
- Run Tests:
ctest
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 orCtrl+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
.
- Sample data observed on Yahoo Finance's Most Bought by Hedge Funds is used to create a text file representing the input format.
- Level 1 or top-of-book market data provides the highest bid and the lowest ask across multiple exchanges (or a single exchange).
- Keep the state while continously processing new user market data input.
- Add the ability to filter on multiple symbols simultaneously.
- Add the ability to also filter on bid price, ask price, bid size, and ask size either individually or simultaneously.
- Increase test coverage.
- Add logging. For example, if the ask price was lower than the bid price note that we observed a “crossed market”.
- Use std::multimap if we eventually incorporate level 2 market data.
- Consider displaying the spread as a percent.
- Consider adding the volume data.
- Consider adding the last trade price.
- Quickstart: Building with CMake
- Google Googletest Repository
- Examples of using
.h
and.cc
files with GoogleTest tests built with CMake
- Examples of using
- Google C++ Style Guide
- Clang-Format
- CMake Resources
- CMake Latest Releases
- Homebrew for CMake
- Clang-Format Style Options
Licensed under the MIT License, Copyright © 2019-2024 Axel Iota.