Building Low Latency Applications with C++ by Sourav Ghosh
Author:Sourav Ghosh
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2023-07-17T00:00:00+00:00
Consuming from and publishing to the order gateway queue
First, we will start with the implementation of processClientRequest() in the MatchingEngine class in the matching_engine.h header file. This implementation simply checks for the type of the MEClientRequest and forwards it to the limit order book for the corresponding instrument. It finds the correct order book instance that this MEClientRequest is meant for by accessing the ticker_order_book_ container, using the ticker_id_ field in MEClientRequest:
auto processClientRequest(const MEClientRequest *client_request) noexcept { auto order_book = ticker_order_book_[client_request ->ticker_id_];
For client requests that try to add a new order (ClientRequestType::NEW), we call the MEOrderBook::add() method and let it service that request:
switch (client_request->type_) { case ClientRequestType::NEW: { order_book->add(client_request->client_id_, client_request->order_id_, client_request->ticker_id_, client_request->side_, client_request->price_, client_request->qty_); } break;
Similarly, client requests that try to cancel an existing order (ClientRequestType::CANCEL) are forwarded to the MEOrderBook::cancel() method:
case ClientRequestType::CANCEL: { order_book->cancel(client_request->client_id_, client_request->order_id_, client_request->ticker_id_); } break; default: { FATAL("Received invalid client-request-type:" + clientRequestTypeToString(client_request->type_)); } break; } }
We will also define a method in the same class that the limit order book will use to publish order responses through MEClientResponse messages. This simply writes the response to the outgoing_ogw_responses_ lock-free queue and advances the writer index. It does that by finding the next valid index to write the MEClientResponse message to by calling the LFQueue::getNextToWriteTo() method, moving the data into that slot, and updating the next write index by calling the LFQueue::updateWriteIndex() method:
auto sendClientResponse(const MEClientResponse *client_response) noexcept { logger_.log("%:% %() % Sending %
", __FILE__, __LINE__, __FUNCTION__, Common::getCurrentTimeStr(&time_str_), client_response->toString()); auto next_write = outgoing_ogw_responses_ ->getNextToWriteTo(); *next_write = std::move(*client_response); outgoing_ogw_responses_->updateWriteIndex(); }
Now, we will look at some code that is similar to what we just saw, except it is used to publish market data updates.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Linux Device Driver Development Cookbook by Rodolfo Giometti(3897)
Embedded Programming with Modern C++ Cookbook by Igor Viarheichyk(3406)
Implementing Cellular IoT Solutions for Digital Transformation by Dennis McCain(3358)
Embedded Linux Development Using Yocto Project - Third Edition by Otavio Salvador & Daiane Angolini(3191)
TinyML Cookbook by Gian Marco Iodice(3136)
Simplifying 3D Printing with OpenSCAD by Colin Dow(2821)
TinyML Cookbook by Gian Marco Iodice & Ronan Naughton(2580)
Fusion 360 for Makers by Lydia Sloan Cline(2198)
Networking A Beginner's Guide by Bruce Hallberg(2186)
Hands-On Linux for Architects by Denis Salamanca(2021)
But How Do It Know? by J. Clark Scott(2007)
Computers For Seniors For Dummies by Nancy C. Muir(1976)
Raspberry Pi and MQTT Essentials by Dhairya Parikh(1928)
Arduino Project Handbook, Volume 2: 25 Simple Electronics Projects for Beginners by Geddes Mark(1924)
9781803246888-ENHANCING DEEP LEARNING WITH BAYESIAN INFERENCE by Unknown(1876)
Hack and HHVM by Owen Yamauchi(1862)
31 Days Before Your CompTIA A+ Exams (Shanette Luellen's Library) by Benjamin Patrick Conry(1839)
MicroPython Projects by Jacob Beningo(1702)
Hands-On Internet of Things with MQTT by Tim Pulver(1678)
