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.
Building Low Latency Applications with C++ by Sourav Ghosh(2951)
Fusion 360 for Makers by Lydia Sloan Cline(1988)
Networking A Beginner's Guide by Bruce Hallberg(1935)
But How Do It Know? by J. Clark Scott(1817)
Computers For Seniors For Dummies by Nancy C. Muir(1771)
Arduino Project Handbook, Volume 2: 25 Simple Electronics Projects for Beginners by Geddes Mark(1756)
Hands-On Linux for Architects by Denis Salamanca(1740)
Hack and HHVM by Owen Yamauchi(1678)
31 Days Before Your CompTIA A+ Exams (Shanette Luellen's Library) by Benjamin Patrick Conry(1665)
MicroPython Projects by Jacob Beningo(1475)
PrestaShop Recipes by Arnaldo Pérez Castaño(1468)
9781803246888-ENHANCING DEEP LEARNING WITH BAYESIAN INFERENCE by Unknown(1460)
Hands-On Internet of Things with MQTT by Tim Pulver(1419)
Raspberry Pi Electronics Projects for the Evil Genius (Tab) by Norris Donald & Norris Donald(1385)
Getting Started with Soldering: A Hands-On Guide to Making Electrical and Mechanical Connections by Vinck Marc de(1381)
Embedded Systems Architecture by Daniele Lacamera(1378)
Healthcare Information Security and Privacy (All-In-One) by Sean Murphy(1371)
Shaping the Fourth Industrial Revolution by Klaus Schwab & Nicholas Davis & Satya Nadella(1358)
Mastering Kubernetes by Gigi Sayfan(1349)