Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building Low Latency Applications with C++

You're reading from  Building Low Latency Applications with C++

Product type Book
Published in Jul 2023
Publisher Packt
ISBN-13 9781837639359
Pages 506 pages
Edition 1st Edition
Languages
Author (1):
Sourav Ghosh Sourav Ghosh
Profile icon Sourav Ghosh

Table of Contents (19) Chapters

Preface 1. Part 1:Introducing C++ Concepts and Exploring Important Low-Latency Applications
2. Chapter 1: Introducing Low Latency Application Development in C++ 3. Chapter 2: Designing Some Common Low Latency Applications in C++ 4. Chapter 3: Exploring C++ Concepts from A Low-Latency Application’s Perspective 5. Chapter 4: Building the C++ Building Blocks for Low Latency Applications 6. Part 2:Building a Live Trading Exchange in C++
7. Chapter 5: Designing Our Trading Ecosystem 8. Chapter 6: Building the C++ Matching Engine 9. Chapter 7: Communicating with Market Participants 10. Part 3:Building Real-Time C++ Algorithmic Trading Systems
11. Chapter 8: Processing Market Data and Sending Orders to the Exchange in C++ 12. Chapter 9: Building the C++ Trading Algorithm’s Building Blocks 13. Chapter 10: Building the C++ Market Making and Liquidity Taking Algorithms 14. Part 4:Analyzing and Improving Performance
15. Chapter 11: Adding Instrumentation and Measuring Performance 16. Chapter 12: Analyzing and Optimizing the Performance of Our C++ System 17. Index 18. Other Books You May Enjoy

Preface

A theoretical knowledge of C++ is not sufficient for building practical low latency applications. The C++ programming language is also quite feature-rich, so it can be difficult to decide which features to use and which ones to avoid for ultra-low latency applications. This book dives into the technical details of the features available in the C++ programming language as well as C++ compilers, from the perspective of low latency performance optimization.

Low latency trading system development in C++ is a highly sought-after skill in quantitative finance. Designing and building a low latency electronic trading ecosystem from scratch in C++ can be daunting, which this book will present in detail. It builds a complete low latency trading ecosystem completely from scratch so that you can learn by following the development and evolution of a trading system. We will learn the important details when building low latency applications in C++ using step-by-step examples and explanations.

Additionally, measuring and optimizing performance is a continuous evolution of all low latency systems, which will also be covered in this book. By the end of this book, you will have a very good understanding of low latency trading systems as well as C++ features and techniques to focus on low latency development.

Who this book is for

This book is for beginner or intermediate-level C++ developers who want to learn how to build low latency systems. This book is also for C++ developers who are especially interested in learning about low latency electronic trading systems in C++.

What this book covers

Chapter 1, Introducing Low Latency Application Development in C++, introduces the desired behavior and performance profile of low latency applications. It also discusses what attributes of the C++ programming language have made it the preferred language for low latency application development. This chapter also discusses some of the most important low latency applications in different business areas.

Chapter 2, Designing Some Common Low Latency Applications in C++, dives into a discussion of the technical details driving some important low latency applications in practice. This chapter explores the details of low latency applications, such as live video streaming, online and offline gaming applications, Internet of Things (IoT) applications, and low latency electronic trading.

Chapter 3, Exploring C++ Concepts from a Low Latency Application’s Perspective, jumps into the details of the C++ programming language from the perspective of low latency application development. It will discuss how to approach the design and development of these applications in C++ and best practices. It will discuss the technical details of the C++ programming language itself and discuss which features are particularly helpful for low latency applications, along with which features to avoid when trying to boost performance. This chapter will also dive into all the modern compiler optimization techniques employed by modern C++ compilers, as well as the optimization parameters and flags supported in the GCC compiler.

Chapter 4, Building the C++ Building Blocks for Low Latency Applications, implements some of the basic C++ building blocks that find use in a lot of low latency applications. The first component built in this chapter is a threading library to support multi-threaded processing in low latency applications. The second component is a memory pool abstraction that avoids dynamic memory allocations, which are extremely slow. This chapter then builds a low latency lock-free queue to transfer generic data between threads without the use of locks, which are too slow for many low latency applications. The chapter also builds a flexible and low latency logging framework. Finally, this chapter will build a library of utilities and classes to support TCP and UDP network socket operations.

Chapter 5, Designing Our Trading Ecosystem, discusses the theory, requirements, and design of a full electronic trading ecosystem and all the components that we will build from scratch in C++ over the next few chapters. This chapter will describe the requirements and design of the matching engine at the trading exchange, which is responsible for executing orders against each other. We will also describe the order server and market data publisher components, which communicate with market participants. We will also discuss the requirements and design of the order gateway client and market data consumer components that exist in trading clients’ systems to communicate with the exchange. This chapter concludes by describing and designing the trade engine framework used to build and run different trading algorithms in the clients’ systems.

Chapter 6, Building the C++ Matching Engine, describes the details behind the design of the matching engine component at the exchange, which is responsible for building the limit order book and performing matching between client orders. The limit order book tracks all orders sent by all market participants. The chapter then fully implements the matching engine and limit order book components in C++ with all the functionality they need.

Chapter 7, Communicating with Market Participants, describes the details behind the design of the market data publisher and order server components at the exchange, which are responsible for publishing market data updates and communicating with the trading clients. It then fully implements these two components in C++ with all the functionality they need. This chapter concludes by building the binary to be used as the electronic trading exchange, tying together components from Chapter 6 and Chapter 7.

Chapter 8, Processing Market Data and Sending Orders to the Exchange in C++, describes the details behind the design of the market data consumer and the limit order book in the trading strategy framework, which are responsible for consuming market data updates and building order books in clients’ systems. This chapter will also discuss the order gateway in the trading clients’ systems that is used to communicate with the exchange and send orders. This chapter then fully implements these three components in C++ with all the needed functionality.

Chapter 9, Building the C++ Trading Algorithm Building Blocks, describes the design of the trading strategy framework and its sub-components, which will be used to run the trading algorithms. We will implement the full framework in C++, including all the components to track positions, profits, and losses, compute trading features/signals to build intelligence, send and manage live orders in the market, and perform risk management.

Chapter 10, Building the C++ Market Making and Liquidity Taking Algorithms, completes the C++ implementation of the entire electronic trading ecosystem. This chapter builds the market-making and liquidity-taking trading algorithms in the framework we built in the previous chapter. Before we implement the trading algorithms, we will discuss the trading behavior of these algorithms, the motivation behind building them, and how these strategies aim to profit. This chapter also builds the trade engine framework needed to build the final trading client application, tying together components from Chapter 8, Chapter 9, and Chapter 10. This chapter concludes by running a fully electronic trading ecosystem and understanding the interactions between the different exchange and trading client components.

Chapter 11, Adding Instrumentation and Measuring Performance, creates a system to measure the performance of our low latency components at a higher granularity level. We will also add a system to timestamp order and market data events through our system as they move from component to component. This chapter concludes by rerunning our electronic trading ecosystem with the performance measurement system, generating performance data.

Chapter 12, Analyzing and Optimizing the Performance of Our C++ System, starts off by analyzing and visualizing the performance data from the previous chapter. It then presents specific tips and techniques that can be used to optimize the performance of our electronic trading components and the overall ecosystem. It implements some of the performance optimization ideas and benchmarks the performance improvements. This chapter concludes by presenting a couple of possible future enhancements to the electronic trading system that was built in this book, and implements and benchmarks one such idea.

To get the most out of this book

You need to have at least beginner-level experience with the C++ programming language and have a basic level of comfort when it comes to compiling, building, and running C++ code in a Linux environment. Prior knowledge of low latency applications and electronic trading is a plus but not required, since all of the information relevant to that will be covered.

Software/hardware covered in the book

Operating system requirements

C++ 20

Linux

GCC 11.3.0

Linux

This book was developed on a Linux 5.19.0-41-generic #42~22.04.1-Ubuntu x86_64 x86_64 x86_64 GNU/Linux operating system. It uses CMake 3.23.2 and Ninja 1.10.2 as the build systems. However, the source code presented in this book is expected to work on all Linux distributions that have at least the GCC 11.3.0 compiler.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Building-Low-Latency-Applications-with-CPP. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/ulPYN.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The –Werror parameter turns these warnings into errors and will force the developer to inspect and fix each case that generates a compiler warning before compilation can succeed.”

A block of code is set as follows:

if(!a && !b) {}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

main:
.LFB1
    Movl    $100, %edi
    Call    _Z9factorialj

Any command-line input or output is written as follows:

SpecificRuntimeExample::placeOrder()
SpecificCRTPExample::actualPlaceOrder()

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Building Low Latency Applications with C++, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere? Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application. 

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781837639359

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon The rest of the chapter is locked
Next Chapter arrow right
You have been reading a chapter from
Building Low Latency Applications with C++
Published in: Jul 2023 Publisher: Packt ISBN-13: 9781837639359
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}