OLD Automated Trading Systems: Architecture, Protocols, Types of Latency

21 min read

By Chainika Thakar and Rekhit Pachanekar

The growth in automated trading has led to significant changes in the basic architecture of automated trading systems over the past decade and continues to do so.

For firms, especially those using high-frequency trading systems, it has become a necessity to innovate technology in order to compete in the world of algo trading.

In this post, we demystify the architecture behind automated trading systems for our readers. We compare the new architecture of automated trading systems with the traditional trading architecture and understand some of the significant components behind these systems.

This blog covers:


What is automated trading?

Automated trading refers to the complete automation of the trading process, which involves automation of decision making, order creation, order submission and order execution. It also includes quantitative modelling, risk monitoring and algorithmic trading in most cases.

Automated trading systems are used by an increasingly large percentage of market participants including trading firms, banks, hedge funds, asset managers and pension funds. They may develop their own systems or use systems provided by third parties. The degree of automation varies from system to system and other factors such as regulatory environment, stock exchanges, and cultural differences.


Difference between automated trading and algorithmic trading

There is one key difference between algorithmic trading and automated trading.

Algorithmic trading is the subset of automated trading and is used to buy and sell large amounts of assets while minimising transaction costs and increasing speed of trade order execution. Algorithmic trading systems execute the provided orders.

Conversely, automated trading software involves the complete automation of the trading process. This means that even the buying and selling decisions are automatic once the user enters the preferences such as the financial instrument to trade, the order and loss limits etc. In the process of automated trading, even the portfolio and risk management are automated. Start mastering the market with these Algorithmic Trading books.

Becoming top algorithmic traders isn't just about your quantitative skills; it's also about the methodology and tools you choose to analyze, formulate, and execute your strategies.


Evolution of trading systems

The traditional trading system was a mere interaction between the broker and the exchange for these three operations:

  • Receiving market data
  • Sending order requests
  • Receiving replies from the exchange

In order to buy or sell the stocks and securities, the trader had to approach a broker. This broker could be an individual or a firm. This broker used to be hired to trade on behalf of the trader who would do the buying and selling of financial instruments manually.

This traditional form of trading would be time-consuming and would involve making trading decisions based on emotions such as fear, greed, etc. Moreover, traditional trading lacked analytical accuracy since it was done manually. Going by the famous saying “to err is human”, the traditional or manual form of trading needed to be evolved.

With the advent of automated trading, the trading scenario changed or rather evolved into a more accurate, time-saving, and faster approach. In its basic form, we can portray the transfer of data from the exchange and the automated trading system as follows:

Algo trading system
Algo trading system

The market data, that is received, typically informs the automated trading system of the latest order book. It may also contain some additional information like the volume traded so far, the last traded price, and the quantity of the trading order.

However, to make a decision based on the data, the automated system looks at the old values or derives certain patterns from the history. Based on this historical analysis of data and patterns, the system goes forward to create a trading strategy and execute the same.

Last but not least, a GUI interface is needed for the trader to view all this information on a screen.

Taking all the points above into consideration, the traditional architecture of the entire automated trading system can now be broken down into -

  • The exchange(s) – the external world
  • The server
    • Receives market data 
    • Stores the market data
    • Store orders generated by the user
  • Application
    • Takes inputs from the user initially for the decisions such as stop loss, limits, the preferred financial instrument for trading etc.
    • Acts as an interface for viewing the information including the data and orders
    • Acts as an order manager sending orders to the exchange
Evolution of automated system
Evolution of automated system

The need for an automated trading system

The traditional architecture lacked the facilities that the automated trading with Direct Market Access (DMA) provided. The latency between the origin of the strategy creation to the order generation went beyond the dimension of human ability and entered the realms of milliseconds and microseconds with automated trading.

With time, it was realised that order management also needed to be more robust and capable of handling many more orders per second.

Since the time frame of order execution with algorithmic trading is less compared to manual order execution, risk management measures were also needed. For such practices as fast order execution and simultaneous risk management, an automated system was needed.

For example, even if the reaction time for an order is 1 millisecond, the system is still capable of making 1000 trading decisions in a single second. Thus, each of these 1000 trading decisions needs to go through risk management measures within the same second to avoid losses. You could say that when it comes to automated trading systems, this is just a problem of complexity.


Automated trading architecture

The automated trading system or algorithmic trading (You can enroll for our course on Algo Trading Course!) has been at the centre stage of the trading world for more than a decade now. A “trading system”, more commonly referred to as a “trading strategy” is nothing but a set of rules, which is applied to the given input data to generate entry and exit signals (buy/sell).

Although formulating a successful trading strategy seems like an easy task, in reality, it’s not! But, with the grit and determination towards creating such a strategy, it is very much possible to create one.

Creating a successful trading strategy requires exhaustive quantitative research, and the brains behind quantitative trading strategies are known as “Quants” in the algorithmic trading world.

We can define a quant as a professional, employed by a quantitative trading firm, who applies advanced mathematical and statistical models with the sole objective to create an alpha-seeking strategy. The alpha-seeking strategy is nothing but a profitable trading strategy that can consistently generate returns without being dependent on the overall market direction.

The percentage of volumes attributed to algorithmic trading has seen a significant rise in the last decade. Going further, the algorithmic trading market size is expected to reach the USD 42.99 billion mark by 2030 ⁽¹⁾. This growth expectation is attributed to the fact that most traders nowadays look for an effective, reliable and faster order execution at a reduced transaction cost.

You can see the automated trading system in the representation below:

Architecture
Architecture

Although the application layer is primarily a view, some of the risk checks can be offloaded to the application layer, especially those that are to do with the sanity of user inputs like fat finger errors.

The rest of the risk checks in automated trading systems are now performed by a separate Risk Management System (RMS) within the Order Manager (OM), just before releasing an order. The problem of scale also means that where earlier there were 100 different traders managing their risk, there is now only one RMS system to manage risk across all logical units/strategies.

However, some risk checks may be particular to certain strategies, and some might need to be done across all strategies. Hence the RMS itself involves strategy-level RMS (SLRMS) and global RMS (GRMS). It might also involve a UI to view the SLRMS and GRMS.

Now let us understand the server components in more detail.

System architecture
System architecture

Market Adapter

Exchange or any market data vendor sends data in their own format. Your algorithmic trading system may or may not understand that language. Exchange provides you with an API or an Application Program Interface ⁽²⁾ which allows you to program and create your own adapter which can convert the format of the data into a format that your system can understand.

Complex Event Processing Engine

This part is the brain of your strategy. Once you have the data, you would need to work with it as per your strategy, which involves doing various statistical calculations, comparisons with historical data and decision-making for order generation. The type of order and order quantity is prepared in this block.

What do you call a trading system which is actually a CEP System?

A complex event is a set of other events that together implies an occurrence of something of significance. These include stock trends, market movements, news etc. Complex event processing is performing computational operations on complex events in a short time.

In an automated trading system, the operations can include detecting complex patterns, building correlations, and relationships such as causality and timing between any incoming events.

CEP systems process events in real-time, thus the faster the processing of events, the better a CEP system is. For example, if an automated trading system is designed to detect a profit-making opportunity for the next 1 second, but the time taken by the CEP system exceeds this threshold, then the trading system won’t be able to make any profits.

The CEP system comprises of four parts:

  • CEP engine
  • CEP rules
  • CEP WS
  • CEP result interface

The two primary components of any CEP system are the CEP engine and the set of CEP rules. The CEP engine processes incoming events based on CEP rules. These rules and the events that go as input to the CEP engine are determined by the trading system (trading strategy) applied.

CEP
CEP

For a quant, the majority of his work is concentrated in this CEP system block. A quant will spend most of his time formulating trading strategies; performing rigorous backtesting, optimization, and position-sizing among other things.

This is done to ensure the viability of the trading strategy in real markets. No single strategy can guarantee everlasting profits. Hence, quants are required to come up with new strategies on a regular basis to maintain an edge in the markets.

There are a number of popular automated trading systems that are widely used in current markets. These are classified as different strategies namely momentum strategies, statistical arbitrage, market making, etc.

Order Routing System

The order is encrypted in the language that the exchange can understand, using the APIs which are provided by the exchange. There are two kinds of APIs provided by the exchange: native API and FIX API. Native APIs are those which are specific to a certain exchange.

The FIX (Financial Information Exchange) protocol is a set of rules used across different exchanges to make the data flow in security markets easier and more effective. We will talk about FIX further in the next section.

One can send orders through the automated trading system to exchanges or non-exchanges, and ORP should be able to handle orders to different destinations.

Here, we would like to point out that the order signal can either be executed manually by an individual or in an automated way. The latter part is what we consider an “Automated trading system”. The order manager module comprises different execution strategies which execute the buy/sell orders based on pre-defined logic.

Some of the popular execution strategies include VWAP, TWAP, etc. There are different processes like order routing, order encoding, transmission, etc. that form part of this module. See our blog on Order Management System (OMS) to know more about these processes.

Order management system
Order management system

Risk management in Automated Trading Systems

Since automated trading systems work without any human intervention, it becomes pertinent to have thorough risk checks to ensure that the trading systems perform as designed. The absence of risk checks or faulty risk management can lead to enormous irrecoverable losses for a quantitative firm. Thus, a risk management system (RMS) forms a very critical component of any automated trading system.

There are 2 places where risk management is handled in automated trading systems:

  • Within the application – We need to ensure those wrong parameters are not set by the trader. It should not allow a trader to set grossly incorrect values or any fat-finger errors.
  • Before generating an order in the order management system (OMS) – Before the order flows out of the system we need to make sure it goes through some risk management system. This is where the most critical risk management check happens.

Automated trading system protocols

Since the new architecture is capable of scaling many strategies per server, the need to connect to multiple destinations from a single server has emerged. So the order manager hosts several adapters to send orders to multiple destinations and receive data from multiple exchanges.

Each adaptor acts as an interpreter between the protocol that is understood by the exchange and the protocol of communication within the system. Multiple exchanges, thus, required multiple adapters.

However, to add a new exchange to the automated trading system, a new adapter has to be designed and plugged into the architecture. The need for a new adapter arises because each exchange follows its protocol that is optimised for the features that the exchange provides.

To avoid this hassle of adapter addition, standard protocols have been designed. The most prominent among them is the FIX protocol. This not only makes it manageable to connect to different destinations but also drastically reduces the go-to-market time when it comes to connecting with a new destination.

The presence of standard protocols makes it easy for the automated trading system to integrate with third-party vendors for analytics or market data feeds. As a result, the market becomes very efficient as integrating with a new destination/vendor is no more a constraint.

In addition, simulation becomes very easy as receiving data from the real market and sending orders to a simulator is just a matter of using the FIX protocol to connect to a simulator.

The simulator itself can be built in-house or procured from a third-party vendor. Similarly, recorded data can be replayed with the adaptors being agnostic as to whether the data is being received from the live market or from a recorded data set.

Automated trading system protocols
Automated trading system protocols

Take a moment to watch this captivating video as we explore automated trading and learn how to set it up for yourself.  This video introduces essential concepts of automated trading, including its significance and the process. It also demonstrates a rule-based strategy's automation, offering valuable insights for those seeking to enhance their trading skills.


Low latency architectures

With the building blocks of an automated trading system in place, the strategies now have the ability to process huge amounts of data in real-time and make quick trading decisions.

Today, with the advent of standard communication protocols like FIX, the technology entry barrier to setting up an algorithmic trading desk or an automated trading system, has become lower.

Consequently, the world of algorithmic trading has become more competitive.

We have curated a list of some of our most demanded blogs on Algorithmic Trading written by experts!

As servers got more memory and higher clock frequencies, the focus shifted towards reducing the latency for decision-making. Over time, reducing latency has become a necessity for many reasons, such as:

  • The strategy makes sense only in a low latency environment
  • Survival of the fittest – competitors pick you off if you are not fast enough

The problem, however, is that latency is really an overarching term that encompasses several different delays. Although latency is very easily understood, it is quite difficult to quantify. It, therefore, becomes increasingly important as to how the problem of reducing latency is approached.

If we look at the basic life cycle in an automated trading system, the steps are as follows:

  1. A market data packet is published by the exchange.
  2. The packet travels over the wire.
  3. The packet arrives at a router on the server side.
  4. The router forwards the packet over the network on the server side.
  5. The packet arrives on the Ethernet port of the server.
  6. Depending on whether this is UDP/TCP, processing takes place, and the packet makes its way to the memory of the adapter.
  7. The adaptor then parses the packet and converts it into a format internal to the algorithmic trading platform.
  8. This packet now travels through the several modules of the system – CEP, tick store, etc.
  9. The CEP analyses and sends an order request.
  10. The order request again goes in reverse from here as the market data packet.

In an automated trading system design, high latency at any of these steps ensures a high latency for the entire cycle. Hence latency optimization usually starts with the first step in this cycle that is in our control i.e., “the packet travels over the wire”. The easiest thing to do here would be to shorten the distance to the destination as much as possible.

Collocations are facilities provided by exchanges to host the trading server in close proximity to the exchange. The following diagram illustrates how a lesser latency is better and can be achieved by cutting the distance between the exchange and the host server. Hence, the lesser the distance, the lesser the time in terms of milliseconds (ms) and microseconds (S) for trade order execution.

Advantages of kernel bypass
Advantages of kernel bypass

In an automated trading system design, for any kind of high-frequency strategy involving a single destination, collocation has become a defacto must. However, strategies that involve multiple destinations need some careful planning.

Factors like the time taken by the destination to reply to order requests and its comparison with the ping time between the two destinations must be considered before making such a decision. The decision may be dependent on the nature of the strategy as well.

Network latency is usually the first step in reducing the overall latency of an automated trading system design. However, there are plenty of other places where the architecture can be optimised.

Propagation latency

In an automated trading system design, propagation latency signifies the time taken to send the bits along the wire, constrained by the speed of light. Several optimisations have been introduced to reduce the propagation latency apart from reducing the physical distance.

For example, the estimated roundtrip time for an ordinary cable between Chicago and New York is 13.1 milliseconds. Spread Networks, in October 2012, announced latency improvements which brought the estimated roundtrip time to 12.98 milliseconds.

Microwave communication was adopted by firms such as Tradeworx bringing the estimated roundtrip time to 8.5 milliseconds. Note that the theoretical minimum is about 7.5 milliseconds. Continuing innovations are pushing the boundaries of science and fast reaching the theoretical limit of the speed of light. (You can explore the course on Millisecond trading.)

Latest developments in laser communication, earlier adopted in defence technologies, have further shaved off an already thinning latency by nanoseconds over short distances.

Network processing latency

Network processing latency signifies the latency introduced by routers, switches, etc.

The next level of optimization in the architecture of an automated trading system design would be in the number of hops that a packet would take to travel from point A to point B.

A hop is defined as one portion of the path between source and destination during which a packet doesn’t pass through a physical device like a router or a switch.

For example, a packet could travel the same distance via two different paths. But It may have two hops on the first path versus 3 hops on the second. Assuming the propagation delay is the same, the routers and switches each introduce their own latency and usually as a thumb rule, the more hops, the more the latency.

Network processing latency may also be affected by what we refer to as microbursts. Microbursts are defined as a sudden increase in the rate of data transfer which may not necessarily affect the average rate of data transfer.

Since automated trading systems are rule-based, all such systems will react to the same event in the same way. As a result, a lot of participating systems may send orders leading to a sudden flurry of data transfer between the participants and the destination leading to a microburst. The following diagram represents what a microburst is.

Network processing latency
Network processing latency

The first figure shows a 1-second view of the data transfer rate. We can see that the average rate is well below the bandwidth available of 1Gbps. However, if we dive deeper and look at the second image (the 5-millisecond view), we see that the transfer rate has spiked above the available bandwidth several times each second.

Serialisation latency

Serialisation latency for an automated trading system design signifies the time taken to pull the bits on and off the wire.

A packet size of 1500 bytes transmitted on a T1 line (1,544,000 bps) would produce a serialisation delay of about 8 milliseconds. However, the same 1500-byte packet using a 56K modem would take 200 milliseconds. A 1G Ethernet line would reduce this latency to about 11 microseconds.

Interrupt latency

Interrupt latency in an automated trading system design implies a latency introduced by interrupts while receiving the packets on a server. Interrupt latency is defined as the time elapsed between when an interrupt is generated to when the source of the interrupt is serviced.

When is an interrupt generated?

Interrupts are signals to the processor emitted by hardware or software indicating that an event needs immediate attention. The processor, in turn, responds by suspending its current activity, saving its state and handling the interrupt.

Whenever a packet is received on the Network Interface Card (NIC), an interrupt is sent to handle the bits that have been loaded into the receive buffer of the NIC. The time taken to respond to this interrupt not only affects the processing of the newly arriving payload, but also the latency of the existing processes on the processor.

Solarflare introduced “OpenOnload” in 2011, which implements a technique known as kernel bypass, where the processing of the packet is not left to the operating system kernel but to the userspace itself. The entire packet is directly mapped into the userspace by the NIC and is processed there. As a result, interrupts are completely avoided.

You can see below how it works with this diagram below:

Solarstorm controller
Solarstorm controller

As you can see, the left side of the diagram shows how the processing of the packet happens through the operating system kernel and leads to high latency.

Whereas, on the right side of the diagram you can see how “OpenOnload” makes the latency go down as the userspace sends the packet in lesser milliseconds.

The following diagram clearly demonstrates the advantages of kernel bypass.

Advantages of kernel bypass
Advantages of kernel bypass

Application latency

Application latency for an automated trading system signifies the time taken by the application to process. This is dependent on several packets, the processing allocated to the application logic, the complexity of the calculation involved, programming efficiency, etc.

Increasing the number of processors on the system would, in general, reduce the application latency. The same is the case with increased clock frequency.

A lot of automated trading systems take advantage of dedicating processor cores to essential elements of the application like the strategy logic for example. This avoids the latency introduced by the process of switching between cores.

Similarly, if the programming of the strategy in an automated trading system design has been done keeping in mind the cache sizes and locality of memory access, then there would be a lot of memory cache hits resulting in further reduction of latency.

To facilitate this, a lot of systems use very low-level programming languages to optimise the code to the specific architecture of the processors.

Some firms have even gone to the extent of burning complex calculations onto hardware using Fully Programmable Gate Arrays (FPGA). With increasing complexity comes increasing cost and the following diagram aptly illustrates this.

Cost and complexity
Cost and complexity

Levels of sophistication

The world of high-frequency algorithmic trading has entered an era of intense competition. With each participant adopting new methods of ousting the competition, technology has progressed by leaps and bounds.

Modern-day algorithmic trading architectures are quite complex compared to their early-stage counterparts. Accordingly, advanced automated trading systems are more expensive to build both in terms of time and money.

 

 

Standard 10GE network card

Low latency 10GE network card

Field Programmable Gate Array (FPGA)

Application Specific Integrated Circuit (ASIC)

Latency

20 microseconds + application time

5 microseconds + application time

3-5 microseconds

Sub microsecond latency

Ease of deployment

Trivial

Kernel driver installation

Retraining of programmers

Specialists

Man years effort to develop

Weeks

Months

2-3 man-years

2-3 man-years

Building an entire automated trading system can be beyond the scope of an individual retail trader. Traders who want to explore the algorithmic way of trading can opt for automated trading systems that are available in the markets on a subscription basis.

A trader can subscribe to these automated systems and use the algorithmic trading strategies that are made available to the users of these systems. Traders, who know programming can formulate and backtest their strategies in programming platforms like Python and C (You can enroll for our course on Python for Trading!).


Steps to build automated trading systems

Beginner traders can learn to build their own automated trading system with the algorithms and trade profitably in the markets. For building your own automated trading system, you will be needing to code the strategy in a programming language, backtest the strategy on historical data to find out its performance, paper trade and then live trade.

Let us see the abovementioned steps in detail below that can serve as a rough guideline for building an algorithmic trading strategy:

Step 1: Ideation or trading plan

Come up with a trading idea or a strategy that you believe would be profitable in live markets. This idea will help you build an automated system that exactly suits your trading needs. The idea can be based on your market observations or can be borrowed from trading books, research papers, trading blogs, trading forums or any other source.

Step 2: Creating the system

This step requires you to create an automated system to identify the trading opportunities in the market in accordance with your preferred financial instruments. Also, you will need to feed the automated trading system with the information regarding how to perform once it finds the opportunities.

In addition, you will also need to give the inputs regarding risk management by entering the parameters such as stop loss, limit order etc.

This entire process of creating the automated system will need you to have the knowledge of a programming language such as Python, C, etc. With this programming language, you will be able to code the system with all the necessary abovementioned preferences.

Step 3: Test and refine your system

The next step is to test and refine the automated trading system so as to improvise the system in case of any malfunctions. After making any necessary changes or improvements, you can be sure that the system is set for taking your trades to the live market.

Step 4: Take your automated system live!

Once you’re sure of your automated system, you can take your trade live with your trading idea or the strategy.


Now that you have successfully built an automated trading system, here is a tutorial to help you through the process of downloading historical stock data using Python. If you are interested in automated trading and want to analyze historical stock data for developing your trading strategies, this video is perfect for you.


Advantages of using automated trading systems

The advantages of using automated trading systems are as follows:

  • Ease of use: Orders can be placed quickly with the help of the software navigating you through the different parameters. Moreover, your own automated system will make it even easier for you to place orders since it is always at your disposal.
  • Live portfolio review and market updates: With the automated trading system, you can view market data of financial instruments such as shares, commodities, stock indices, etc anytime. You can also keep track of your portfolio, its underlying assets and performance with the software.
  • Notification feature: One of the most advantageous features of the automated trading system is the notification feature. The automated system will send you alerts to notify you about the latest events in your portfolio as well as broker recommendations.
  • Related news updates:  Users can also track live updates on developments related to a particular stock or segment with the help of automated systems. The system helps you to be updated so as to modify your trade related inputs such as the selection of financial instruments, updating of the stop loss value, limit value etc.
  • Analysis and charts: Another feature is the provision of historical charts and analysis that allows you to look at previous indices data, stock prices and provides analytical tools for the same.

Disadvantages of using automated trading systems

Let us know a couple of disadvantages of using the automated trading systems, which are:

  • Expenses to use the automated system: The automated trading system comes with an expense and that may be a disadvantage for some who do not wish to invest in the same. Also, building the automated system will take some expenses such as hiring a developer to help with coding part while building the system, etc.
  • Connectivity: A generic disadvantage of using the automated trading system is connectivity. In some remote regions, connectivity disturbances are common, and this may lead to losses during order placements.

Bibliography


Conclusion

This was a detailed post on automated trading system architecture to give you an in-depth and insightful knowledge of the components involved. Also, there are various challenges that the architecture developers need to handle or overcome in order to build a robust automated trading system. So what are you waiting for? Go Algo!!

If you want to learn various aspects of algorithmic trading and automated trading systems, then check out our course on “Algorithmic Trading for Beginners!”. This course builds a foundation in algorithmic trading and is perfect for those who want to get a complete picture of the domain. It includes the what, how and why of algorithmic trading. Different algorithmic trading strategies and regulations for setting up an algorithmic trading business are also included.

Note: The original post has been revamped on 28th January 2023 for accuracy, and recentness.

Disclaimer: All data and information provided in this article are for informational purposes only. QuantInsti® makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information in this article and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.

Learn Trading Using LLM