Chapter 11: High-Frequency FPGA and Crypto

Welcome to the final chapter of this book. In the previous chapters, we saw how to optimize traditional trading to obtain a high-frequency trading (HFT) system working with a tick-to-trade latency of 5 microseconds. In the next section, we will discuss how to improve this latency to 500 nanoseconds using advanced hardware optimization. Finally, we will conclude this book by exploring the difference between traditional and cryptocurrency trading.

Our goal in this chapter is to show that the software solution we used in the past chapters has limitations in achieving latency lower than 1 microsecond. Using a specific piece of hardware, we will show you that it is possible. The second goal is to apply the optimization we explained in this book to cryptocurrencies. We will elaborate by extending the design to the cloud.

In this chapter, we will cover the following topics:

  • How Field Programmable Gate Arrays (FPGAs) hardware can perform for HFT to reduce latency
  • How to trade cryptocurrencies with HFT techniques
  • How to build a trading system in the cloud

    Important Note

    In order to guide you among all the optimizations, you can refer to the following list of icons that represent a group of optimizations lowering the latency by a specific number of microseconds:

    Icon

Description automatically generated: Lower than 20 microseconds

    Icon

Description automatically generated with medium confidence: Lower than 5 microseconds

    A picture containing pinwheel, ax, outdoor object, vector graphics

Description automatically generated: Lower than 500 nanoseconds

    You will find these icons in the headings of this chapter.

Reducing latencies with FPGA A picture containing pinwheel, ax, outdoor object, vector graphics

Description automatically generated

In this section, we will look at the Field Programmable Gate Array (FPGA), investigate the evolution of the fierce competition of speed in HFT, and then discuss the motivation for using FPGAs in modern HFT. We will also explore how an FPGA itself works, the design of an FPGA-based trading system, and the advantages and disadvantages of using FPGAs in HFT systems.

Evolution of the fierce competition of speed in HFT

As we have seen in this book, HFT has received a lot of attention, become extremely popular, and also grown to become a significant component of all financial market liquidity and trading. We have also seen that HFT (as the name implies) is all about speed/latency – the speed at which HFT systems and algorithms can analyze market data information, send order requests, and execute trades.

To summarize, latency refers to the total time to travel from one point to another for a data packet. However, specifically in trading, latency means the time, in nanoseconds/microseconds/milliseconds, that it takes from when a market participant receives a market update to when they can get their order to the exchange. Improving technology is the key to winning on trades at the best prices before the price moves, or some other market participant trades against the orders at a cost, or before the orders at that price are canceled. This is true for all market participants – manual traders, market makers, statistical arbitrage traders, or high-frequency traders.

For HFT, since speed is the critical component, the faster a participant's system becomes at processing and trade execution, the higher the profit they receive. So, there is endless fierce competition in this space, with competitors constantly investing massive amounts of money allocated to more powerful and faster trading solutions approaching the ability to trade securities/derivatives/stocks/financial instruments in a few nanoseconds. In addition to increasing profits by increasing the speed of HFT systems, the firms that fall behind by failing to keep up with continuous technological innovations will be unable to compete and, therefore, might go out of business.

To keep up, investment banks, hedge funds, and HFT firms spend massive amounts of money on faster software, co-location setups closest to the exchanges, and networks with the lowest latencies – we saw these in Chapter 7, HFT Optimization – Logging, Performance, and Networking. Participants purchase the fastest servers, processors, memory, and network cards when optimizing the hardware itself. Still, even that is not enough anymore – now, they need to invest in hardware acceleration-based solutions. The approach to hardware acceleration is to offload compute/CPU-intensive portions of trading systems to custom processors, graphics processing units (GPUs), or FPGAs. There are numerous solutions to scaling hardware computing performance. But, finally, right now, FPGAs are responsible for the technological revolution as far as HFT systems and algorithms are concerned. FPGAs have exciting and specific characteristics that enable them to execute relatively simple trading strategies/algorithms magnitudes (1000x) faster than even the most highly-optimized software solutions.

Introduction to FPGA

In this section, we will introduce the FPGA and then investigate the details of the components of an FPGA and its characteristics. An FPGA is hardware (in this case, a chip) that can be programmed (although not easily) for whatever purpose is required. It can also be reprogrammed as needed and as mentioned already, has the advantages of ultra-low latency, high performance, and energy efficiency.

To understand where an FPGA fits in; you can think of a performance spectrum for processors/chips. We have central processing units (CPUs) on one end, which offer a generic and flexible instruction set. The instructions available can be combined in many different ways to perform almost any task, making them general purpose. But this flexibility leads to slow/poor performance when performing these tasks since it is not specialized; that is, a couple of instructions have to be executed to achieve any task.

On the other end, we have application-specific integrated circuits (ASICs), which are extremely fast because they are custom built with a specific/single task in mind, but they cannot be changed once built. They also cost a lot of time and money to develop. For example, a chip is used to mine Bitcoin.

FPGAs are in between CPUs and ASICs on this performance spectrum.

What is an FPGA?

An FPGA is nothing more than a chip that contains thousands, sometimes millions, of core logic blocks (CLBs) – CLB is Xilinx terminology. A comparison can be drawn to the microprocessors in laptops and smartphones, among others, which are composed of millions of logic blocks called Lookup Tables (LUTs). These contain Boolean logical operations such as AND, OR, NAND, and XOR, which are also referred to as gates. Additionally, LUTs work by acting as an n-input function that reduces to a single output. This means Xilinx's UltraScale CLB has a six-input LUT architecture (though this can be reconfigured to two five-input LUTs with unique outputs each). So, you can implement a sequence of Boolean operations in the LUT (that is, a six-input function can be reduced to a single LUT).

In the FPGA, the CLBs can be configured and combined to process tasks, but compared to CPUs, they are not bogged down by extra hardware to slow them down. FPGAs are not great at control-flow-heavy operations but are fantastic for data flow applications. The bog down that CPUs see is that FPGAs are inherently parallel in the way they operate (you are simultaneously evaluating many n-input functions in parallel to achieve the same result). Still, they aren't infinite in terms of their performance. There's a steep penalty if your logic functions become too complex and your data buses become too wide (therefore, slowing the clock rate, you can close the design's synthesis).

FPGAs do not run code but rather implement logic circuits. FPGAs let you implement application-specific functions directly in hardware, slower than an ASIC would be but faster than executing a single code path on a CPU to do the same thing, potentially. FPGAs can be used to carry out extremely specific tasks and perform them extremely quickly and can also execute tasks in parallel simultaneously. Algorithms such as trading strategies are implemented directly on the FPGA.

The first FPGA was invented in 1985; the chip had a very small capacity, and it was very hard to implement logic on it. Modern FPGAs have multi-million gate counts and can accommodate very complex and large-scale designs. The major vendors are AMD, which manufactured Xilinx, Intel, which designed Altera, and Achronix, among others.

Characteristics of FPGA

In this section, we will discuss the important characteristics of FPGAs, which will help you understand and make it obvious in the next section why HFT firms benefit greatly from using FPGAs.

Programmability

We have already discussed in the previous section that FPGAs contain logic-blocks/CLBs/LUTs connected with configurable switches and flexible fabric. This makes them relatively easily programmable (and reprogrammable) and capable of supporting complex trading algorithms.

Capacity

Modern FPGAs are equipped with millions of CLBs, which yield tremendous capacity. Not only can the algorithms be extremely complex, but they are also capable of scaling tremendously. Capacity comes at the cost of physics, though; a signal needs to propagate across the die. Conceptually, processor dies are just the silicon semiconductor material on which the CPU processors reside. As the silicon dies get larger, so do the times for signal propagation. Capacity is huge but not unlimited. In contrast, a CPU has a few points where physics is your enemy; implementing an FPGA requires some knowledge of electrical engineering along with logic design to be successful.

Parallelism

FPGAs, unlike CPUs, do not have a fixed processor architecture – meaning no operating system (OS) overhead and interrupts, and so on. On FPGAs, the processing paths are parallel, so different functions/operations are not competing for resources but can instead be running in parallel. On a modern FPGA, a single chip can have 10+ code paths running on it simultaneously at different rates.

This parallel architecture on the FPGA is key to it being able to execute buy and sell trades at maximum capacity and speed. One caveat here is that the algorithms or mathematical computations need to be broken down into a set of tasks. Only then can they be processed within different cycles in parallel.

The parallelism also makes FPGAs very resilient and capable of providing a high level of service. Being stable and self-contained, FPGAs make the whole HFT infrastructure function smoothly and makes the infrastructure resilient against changes in non-FPGA hardware and software.

Determinism

As explained in Chapter 4, HFT System Foundations – From Hardware to OS, when executing instructions on CPUs, there is an element of possible non-determinism (out-of-order processors). Additionally, the OS and event-driven interrupts can lead to many control paths that lead to a lot of randomness. CPUs are great for general purpose tasks that evolve/change over time but not great for guaranteeing performance metrics.

With FPGAs, we can implement hardware algorithms, which leads to a high level of determinism. So, when there are bursts in market activity and networks can be overloaded with data, FPGAs can process and provide market data very quickly and with low variance. An FPGA goes through the same sequence of states each time, providing repeatable and predictable latency/performance.

We talked about FPGA features; we will now talk about how the HFT system can leverage FPGAs.

Diving into FPGA trading systems

FPGA trading systems are the ones that utilize low-latency, high-frequency, and algorithmic trading strategies. These systems need to perform many different tasks and do so within a few nanoseconds. Some of the tasks that such a system would need to perform are described in the following subsections.

Market data

The very first task of an FPGA is to analyze market data from multiple stock exchanges. This involves building the network protocol stack and addressing components such as the Ethernet layer, the Internet Protocol (IP) layer, the User Datagram Protocol (UDP) layer, and market data protocols.

Network stacks

Since network input/output (I/O) is handled at the kernel and OS layers in an FPGA setup, building the network stack on the FPGA is often the first step in optimizing a trading system. This means handling the Ethernet layer, the IP layer, the UDP layer, and to some extent, the transmission control protocol (TCP) layer. There are also opportunities to use hybrid stacks – there's a TCP stack that runs on the host to deal with weird circumstances, while the FPGA can receive TCP market data and decode it until one of these weird states happens (which is rare). The TCP straight in an FPGA is doable but difficult and often a non-elegant solution.

Feed arbitration and replication

Most trading exchanges disseminate market data on multiple channels for redundancy and fairness reasons. FPGA feed handlers that consume market data need to handle A/B feed arbitration (in HFT, it is pretty common to have two channels of communication, A and B, for redundancy when receiving market data) and deal with the redundant feeds. Conversely, trading exchanges or market data providers also need to use similar FPGA technology to process and distribute large volumes of market data updates.

Feed parsers and normalizers

FPGA feed handlers need to process different market data protocols – the FIX Adapted for STreaming (FAST) protocol is a very common example. Even the market data update semantics can differ based on the exchange, and FPGA market data parsers and normalizers need to deal with these optimally.

Trading signals

After processing market data received from the exchange, the next step is to calculate different trading signals for the algorithm to find trading opportunities. These trading signals find mispricing in prices and/or orders to see where some profitable trading possibilities exist.

Low-latency execution algorithms

After the trading signals/models are updated based on new market updates, we use the output to exploit fleeting trading opportunities by sending orders as quickly as possible to the market. Algorithms have to be extremely high-performant to beat other orders, that is, get to the exchange before other orders rush for the same opportunity.

Considerations

FPGA trading systems need to be easily customizable and capable of being optimized and tested when handling live updates. Another consideration is to push trading algorithms as close to the Network Interface Cards (NICs) and minimize system latencies to the maximum possible extent. In this first part, we introduced FPGAs, their characteristics, and how they can be used in HFT systems. We will now talk about the advantages of trading systems built with an FPGA.

Advantages of FPGA trading systems

This section will investigate the advantages that HFT firms get from using FPGAs. In Chapter 1, Fundamentals of a High-Frequency Trading System, we explained the advantages of using HFT systems. FPGAs help make HFT systems even faster. This section will summarize the main benefits of using FPGAs in trading systems.

Higher profits

HFT algorithms that use FPGAs can beat other participants by being able to execute orders at a price before others. FPGA algorithms can detect and act on opportunities before other participants have a chance to react, and execution at the best prices leads to increased profits right away. The reprogrammable nature of FPGAs means you can change the algorithm's behavior and trading parameters quickly and stay ahead of the competition. The scalability that FPGA trading systems offer leads to being able to execute multiple trades on many instruments simultaneously and leads to even higher revenues. FPGA-based trading systems also allow HFT firms to create safer trading environments, save expenses, and so increase revenue even more.

Security compliance

Over the past several years, trading operations and HFT specifically have come under increased tightening of regulations and risk management. HFT firms have, therefore, been forced to look for new solutions to monitor trading activities and detect/handle potential losses. Traditional CPU-driven systems often have a limitation of being able to view/compute portfolio risks instead of being in real time, so not providing the required level of security. FPGAs allow for near-real-time risk assessment on portfolios and allow firms to meet the stringent risk/regulation requirements that regulatory bodies ask for.

Cheaper maintenance

Relying on FPGAs means HFT businesses can reduce expenses related to the maintenance of computer systems. A single well-designed FPGA can replace a lot of generic CPUs and help bring down company expenses by saving on energy costs, office rentals, and system cooling expenses. Being reprogrammable also means that the device can be modified after installation to meet evolving requirements, which leads to more cost savings related to maintenance.

Disadvantages of FPGA trading systems

We have discussed the advantages that having an FPGA brings to HFT firms; now, this section will look at what disadvantages an FPGA system has.

Hardware cost

FPGA chips are expensive; they can sometimes be significantly more expensive than traditional servers. Traditional servers are also a more cost-effective solution when it comes to running many processes that are not super performance sensitive. FPGAs tend to be hosted inside a normal server anyway, so FPGAs do not replace traditional servers. So, depending on the applications, if the systems are not well thought out and well designed, FPGA chips can lead to many hardware costs.

Development and debugging cost

FPGA chips are much harder to program algorithms for than traditional CPUs. Verilog is generally harder to develop, debug, and troubleshoot algorithms than traditional languages such as C, C++, Java, and so on. The tools and APIs available are much fewer too and quite limited for FPGAs compared to other languages. Debugging FPGA algorithms is also much harder than debugging traditional algorithms due to limited logging abilities and complex decision paths on the chip.

Additionally, there are many capable developers for traditional software development languages, but finding FPGA developers is harder due to less availability and higher costs. There are ongoing efforts to make the development process itself easier and faster. New tools are emerging, such as high-level synthesis tools that convert algorithms to gate-level designs. They have limitations but could support rapid time-to-market or at least prototyping. There are a lot of such tools on the market today, but some popular examples would be Simulink (provided by Matlab), ISE, Vivado, Vitis, ChipScope (provided by Xilinx), and Altera Quartus (provided by Intel; Altera was a company acquired by Intel).

Added trading risk

Generally, FPGA-driven HFT systems and trading algorithms reduce the risk caused by failing software components. But poorly designed or tested FPGAs can have the opposite impact and increase risks. This can be from bugs in the FPGA systems that only trigger under certain market conditions and/or trading parameters, leading to incorrect FPGA behavior. Another factor with FPGA systems is that they are extremely fast in their reactions and order executions, which means that a berserk FPGA system issue can cause significant losses before traditional risk systems can detect the problem and shut them down. In all these cases, firms experience substantial trading losses, regulatory and compliance actions/fines, and can even go bankrupt due to massive losses.

Strategy complexity limits

As mentioned in the What is FPGA? section, FPGAs are best suited for designing algorithms that maximize the parallel architecture and deterministic nature of FPGAs. Additionally, building and debugging algorithms for the FPGA is an expensive, time-consuming, and complicated process. Both these factors mean a limit to how complex a trading strategy/algorithm can be built for the FPGA to maximize its benefits. So, implementing a very difficult algorithm with a lot of complex statistical signals, machine learning components, and execution behavior on FPGAs is not realistic/practical.

Final words on FPGAs

The fierce competition for speed in HFT has been an ongoing phenomenon since the year 2000 and is unlikely to end anytime soon. HFT firms will need to continue adopting emerging technological innovations to maintain their edge in the market, and failure to do so might lead to losses and extinction.

FPGAs, which we discussed in this section, are an example of these recently emerged technologies. The parallel architecture and deterministic nature allow FPGAs to deliver the lowest possible latencies in processing market data and order executions. Using FPGAs to accelerate HFT engines to nanoseconds provides many business benefits, such as increased trade volumes and higher profits.

In Chapter 6, HFT Optimization – Architecture and Operating System, and Chapter 7, HFT Optimization – Logging, Performance, and Networking, we enounced the main guidelines to optimize hardware and software for HFT. We saw in all the other chapters how to apply these optimizations concretely with C++, Java, and Python. The FPGA finishes this book's quest of making trading systems faster. We will now talk about the opposite in terms of performance: HFT for cryptocurrencies.

Exploring HFT with cryptocurrencies

In this section, we will describe the differences between HFT in cryptocurrencies and HFT in traditional assets. There are many other resources on crypto-assets, such as Packt's Complete Cryptocurrency and Blockchain Course (video) written by Ravinder Deol, Rob Percival, and Thomas Wiesner (https://www.packtpub.com/product/data/9781839211096). We will focus on the HFT in crypto by explaining how transactions work and how the exchange works to build low-latency transactions in this area. Cryptocurrencies have been getting into the trading world since Bitcoin became a major value on the crypto market. More and more companies got attracted by the benefit of trading cryptocurrencies. Like any other assets, hedge funds and trading firms started building HFT systems for digital assets.

What is crypto?

Cryptocurrencies are digital assets that are produced with the use of computer networking software. This computer network is not reliant on any central authority, such as a government or bank, to uphold or maintain it. Bitcoin (BTC) and other cryptocurrencies use blockchain technology, and it keeps track of who owns something and produces a tamper-proof record of transactions. This is a totally decentralized system.

The term cryptocurrency refers to the cryptographic techniques used by developers to combat fraud. These breakthroughs solved a problem that plagued previous attempts to develop totally digital currencies: how to prevent users from replicating their holdings and spending them twice.

Individual units of cryptocurrency are referred to as coins or tokens. Some are exchange units for goods or services, while others are designed to help computer networks that undertake more complex financial transactions function.

The way to produce Bitcoin is through mining. Mining is a time-consuming process. This process involves computers solving difficult puzzles to verify the legitimacy of network transactions. Owners of those computers may be rewarded with newly created Bitcoin. Other cryptocurrencies create and distribute tokens in different methods, with some having a far smaller environmental impact.

How do crypto transactions work?

Even if we can buy crypto assets using decentralized transactions, a centralized exchange is likely the most accessible for new traders. Customers have more trust in centralized exchanges regulating transactions as a third party. These exchanges make money by collecting fees for various services and selling cryptocurrency at market prices.

There are decentralized exchanges for more advanced traders, with cheaper costs than those paid by centralized systems. They are harder to utilize and need more technical expertise, but they may provide some security benefits because no one target for a cyberattack exists. Peer-to-peer transactions are another way to exchange cryptocurrencies. We have defined what digital currencies are, so we will now learn how they are built.

What is a blockchain?

A blockchain is a distributed data ledger. It maintains the transaction history for each crypto unit, showing how asset ownership has changed over time. New blocks are added to the chain's frontend when transactions are recorded in blocks. A blockchain file is always kept on several computers throughout a network rather than in a single location. It is often available to all network users. Because there is no one weak spot vulnerable to hacking, human mistakes, or software mistakes, it is both transparent and difficult to modify.

Cryptography (a combination of advanced mathematics and computer science) connects the blocks. Any attempt to alter data disrupts the cryptographic links between blocks, allowing machines on the network to quickly recognize it as fake.

What is cryptocurrency mining?

Cryptocurrency mining refers to checking recent crypto transactions and adding new blocks to the blockchain. Mining computers choose pending transactions from a pool and verify that the sender has enough money to finish the transaction. This is done by comparing the transaction information to the blockchain's transaction history. A second check verifies that the sender used their private key to authorize the cash transfer.

Mining machines assemble legitimate transactions into a new block and try to discover a solution to the complicated process of building the cryptographic link to the previous block. When a machine successfully generates the link, it saves the block to its copy of the blockchain file and broadcasts the change to the rest of the network.

Similarities between traditional asset trading and cryptocurrency trading

We will first look at the main similarities between these two worlds.

What drives the price of cryptocurrencies?

Like the traditional markets, markets for cryptocurrencies are driven by supply and demand. Due to their decentralized nature, they may sound immune to many economic and political issues plaguing traditional currencies. However, we can still observe some correlation between economic metrics and crypto-asset prices.

By comparing the traditional asset, we can notice that the following variables can have a significant influence on their prices:

  • The total quantity of coins in circulation and the speed they are released and removed will also impact the price.
  • Market capitalization refers to the total worth of all currencies in circulation, as well as how users perceive this value to be changing.
  • The way some crypto-assets are perceived in the media and their popularity.
  • Integration: Easiness of integrating into existing infrastructure.
  • Regulatory events and security issues can impact cryptocurrencies and traditional assets.

All these parameters can also be a part of price movements for regular stocks, bonds, or other derivatives. The factors that are specific to cryptocurrencies are described as follows.

Cost of production

Mining is the process of creating cryptocurrency tokens. The capacity of cryptocurrency to function is thanks to a decentralized network of miners. The protocol creates cryptocurrency tokens and any fees paid to the miners by the trading parties. As mining expenses grow, so must the value of the cryptocurrency. Miners will not mine if the mining money is not worth paying their expenses. Because miners are necessary to operate the blockchain, the price will have to climb as long as demand exists.

Cryptography exchanges

Bitcoin and Ether, two popular cryptocurrencies, are traded on various platforms. The most popular tokens are listed on every exchange. On the other hand, some smaller tokens may only be available on a few exchanges, limiting access to some investors. Some wallet providers will compile quotes for any collection of cryptocurrencies from many exchanges, but they will charge a fee, increasing the cost of investing. In addition, if a cryptocurrency is lightly traded on a tiny exchange, the spread taken by the exchange may be too wide for certain investors. More exchanges listing a cryptocurrency can increase the number of investors ready and able to acquire it, therefore, raising demand. When demand rises, so does the price.

Market participants and competitors

There are dozens of different cryptocurrencies, and new projects and tokens are launched daily. New rivals have a low entrance barrier. However, developing a viable cryptocurrency also involves the creation of a cryptocurrency user network. A useful blockchain application may quickly build a network, particularly if it fixes a defect in a competitor's service. If a new competitor develops traction, it depletes the value of the incumbent, causing the incumbent's price to fall while the new competitor's token's price rises.

Crypto-specific governance

Cryptocurrency networks seldom follow a set of rigid rules. Developers make changes to projects depending on the feedback they receive from the community. Some tokens, known as governance tokens, allow their owners a vote in how a project develops in the future, including how a token is mined and utilized. Stakeholder consensus is required before any modifications to a token's governance can be implemented. Going from a proof-of-work to a proof-of-stake system will render most of the expensive mining equipment in data centers and people's basements obsolete. Cryptocurrency values will surely be affected as a result of this. The long process of updating software to improve protocols, on the other hand, may limit the upside potential of Bitcoin values. It is detrimental to present stakeholders if an update that would unleash value for Bitcoin investors takes months to implement.

Crypto-specific regulations

Cryptocurrencies are securities or commodities. Securities and Exchange Commission (SEC) or Commodity Futures Trading Commission (CFTC) could eventually regulate the crypto assets. There is no clear way of knowing which one of them will apply rules to this type of trading. However, the regulation will help the trading of these assets. Exchange-Traded Funds (ETFs) and futures contracts, for example, provide investors wider access to cryptocurrencies, enhancing their value.

Furthermore, regulation may allow investors to take short positions or gamble against the price of cryptocurrencies via futures or options contracts. This should result in more accurate price discovery and less volatility in Bitcoin pricing. Meanwhile, if a government creates rules against crypto, the crypto value will drop significantly.

What type of orders and in what market can we trade cryptocurrencies?

The same basic trading order types are available on most retail trading platforms:

  • Market order
  • Limit order
  • Stop order

Most decentralized exchanges (DEXs) only provide market orders at the moment, whereas most big, centralized exchanges (CEXs) offer a full range of orders (market, limit, stop, and others). Additional crypto exchanges are expected to include these capabilities as the crypto trading ecosystem grows. While buying and selling cryptocurrencies on platforms designed for easy user experiences may be quite similar, there are numerous key differences when dealing with these two distinct asset classes.

What is the spread in cryptocurrency trading?

The spread is the difference between an asset's advertised on top of the orderbook for buy and sale prices. When you open a position on a crypto market, we observe two prices, much like many other traditional marketplaces. You trade at the purchase price, which is slightly above the market price, to begin a long position. You trade at the selling price, which is somewhat below the market price, if you wish to initiate a short position.

In crypto trading, what is leverage?

Leverage is a method of acquiring many cryptocurrencies without paying the entire worth of our deal upfront. Instead, we make a tiny down payment called a margin. When we terminate a leveraged position, the entire magnitude of the trade determines your profit or loss. This can be similar to trading, except that the leverage in crypto is much higher than traditional asset leverage. Since crypto is very volatile, the risk of loss is very high.

What is the definition of a margin in crypto trading?

In leveraged trading, the margin is a crucial component. It's the term for the initial deposit made to open and maintain a leveraged position. Keep in mind that your margin requirements will vary depending on your broker and the size of your transaction when trading cryptocurrencies on a margin. The margin is expressed as a proportion of the entire position.

Traditional futures contracts versus perpetual futures contracts

Traditional futures contracts have an expiration date that is quite critical when trading to determine the asset value, and the settlement procedure begins when a contract expires. Traditional futures contracts are typically settled every month or quarter, and the contract price converges with the spot price at settlement, and all open positions expire. Crypto-derivative exchanges frequently provide perpetual contracts structured similarly to regular futures contracts.

Perpetual futures contracts have a significant advantage. Traders can retain holdings without an expiration date and do not need to keep track of different delivery months, unlike traditional futures contracts. A trader can keep a short position open indefinitely unless they are liquidated. As a result, perpetual trading contracts and trading pairs on the spot market are extremely similar. Since perpetual futures contracts never settle, exchanges require a system to ensure that futures and index prices regularly converge: a funding rate.

It is possible to short in the future market, but you need to store beta value for the underlying crypto-asset in the spot market. For example, if we want to trade a BTCUSD (Bitcoin/USD) pair with a short position, we need to purchase enough BTC and store it in our account before initializing our trading. This pre-purchased BTC action is our beta. Some exchanges offer lending options to encourage trading more but with some interest rates.

Funding rates

Funding rates are payments made to long or short traders depending on the difference between perpetual contract markets and spot prices regularly. Traders will either pay or get funds depending on open positions. Crypto funding rates avoid long-term price disparity in both markets. It is recalculated numerous times during the day, and depending on the exchanges, it can be calculated more often.

The idea behind the funding rate is to measure how expensive it is to open a position in the futures market.

The two basic components of funding rates are the lending rate (the cost to borrow the coin needed to short) and the premium (difference between futures and spot market). The interest rate on some crypto exchanges is fixed at a small percent every day. In the meanwhile, the premium is determined by the difference in price between the perpetual contract and the market price. The perpetual contract and the market prices may differ during periods of extreme volatility. In such cases, the premium rises or falls under the situation. A wide spread means a big premium. A low premium, on the other hand, shows a limited gap between the two prices. Funding rates may have a significant influence on earnings and losses since funding calculations take into account the level of leverage applied. Even in low-volatility markets, a trader who pays for funding may experience losses and be liquidated due to high leverage.

On the other hand, collecting funds may be quite profitable, especially in range-bound markets. As a result, traders may devise trading methods to profit from funding rates, even in low-volatility markets. Funding rates encourage traders to adopt positions that align perpetual contract prices with spot markets.

To come back to the perpetual contract, if the perpetual price is higher than the spot price, whoever has the long position needs to pay the short position holder. On the other hand, if the perpetual price is lower than the spot price, the funding rate becomes negative, and whoever shorts pays the one in a long position. The funding rate can potentially become a cost or a benefit of the margin. This last part concludes the similarities between traditional trading and crypto trading. We will talk about the main differences next.

Main differences between traditional asset trading and cryptocurrency trading

The following components are the most important differences between traditional and crypto trading.

In crypto trading, what is ownership?

Stock shares are securities that reflect a proportion of ownership (or equity) in a firm, known as the issuer. Owners of stocks often get voting rights or a share of the issuer's earnings in the form of dividends. On the other hand, cryptocurrencies differ a lot in terms of how they're utilized and what they're supposed to stand for.

Many digital assets, such as Ethereum (ETH), Basic Attention Token (BAT), and VeChain Token (VET), are utility tokens designed to be utilized inside a blockchain-based ecosystem and do not reflect a legal interest in the company that issued them. Many cryptocurrencies, such as BTC and stablecoins, do not have clear use cases connected to actual company activities and are meant to store value. Although these assets are best thought of as digital commodities akin to gold, they do not represent an interest in a company or its activities.

What is market access?

Stock trading is often constrained to established business hours for most investors. Crypto markets never close, allowing anyone to take fresh positions and enter—or quit—the market at any time, regardless of where they live. The crypto markets trade actively during the intersection of the Asian time zone and the USA time zone.

What are the limits on issuance?

Publicly-listed firms that issue stock may choose to issue new shares, subject to the company's internal restrictions and any applicable local legislation. The entire supply of a cryptocurrency, on the other hand, is determined by the issuing organization's internal regulations or the blockchain protocol code it was developed with, rather than by-laws or policies. Furthermore, crypto projects may impose demonstrable and unchangeable hard restrictions on their entire coin supply easily and transparently.

What are the trading pairs?

Unlike equities, which are normally acquired and sold with fiat currencies, cryptocurrencies may be purchased and sold using trading pairs, allowing two cryptocurrencies to be directly traded. As BTC and ETH are two of the most widely traded cryptocurrencies, most trading pairings include one of them. If you wish to trade one cryptocurrency for another, you'll almost certainly need to swap the altcoin you want to trade for something more popular, such as BTC. Then, you may swap that BTC for the cryptocurrency you choose.

Suppose you wish to avoid numerous steps while exchanging one low-market-cap currency for another. In that case, you might choose to use one of the many DEXs that can execute these types of trades utilizing automated market makers (AMMs). While most stock brokerages provide fiat on- and off-ramps, not all cryptocurrency exchanges allow users to deposit and withdraw fiat. This means that you won't be able to buy crypto-assets using fiat on some exchanges.

When trading crypto, what does liquidity look like?

When trading low-cap coins and tokens or buying and selling on smaller crypto platforms, investors may confront poor liquidity. In stock trading, liquidity concerns can arise, especially when dealing with micro-cap companies or over-the-counter (OTC) penny stocks.

Is there any transparency in crypto?

Publicly traded companies must maintain transparency, which is typically achieved through quarterly financial updates, annual reports, regular shareholder meetings, and other official means of informing investors about past performance and expected future earnings. While corporations that raise money through a Security Token Offering (STO) may be subject to similar reporting obligations, crypto initiatives are not subject to regulatory scrutiny as publicly traded companies.

Many crypto markets do not compel individual projects to share data regularly, making it difficult for investors and industry analysts to adequately analyze how specific crypto projects are functioning and whether their assets are worth investing in. On the other hand, many crypto projects try to be transparent in terms of community updates and open governance. Transparency is one of the primary concepts of crypto and blockchain, and most high-quality projects strive to adhere to it.

Since this book is about HFT, we will now focus on learning to trade with cryptocurrency exchange.

Trading with cryptocurrency exchange

As we described previously, a digital currency exchange (DCE) is another name for a cryptocurrency exchange. It's a website that allows users to convert their money into cryptocurrency and vice versa. The majority of exchanges are primarily focused on helping us swap a cryptocurrency such as BTC into other digital currencies, such as ETH or other crypto-assets.

Although most exchanges operate online, there are a few physical locations. Traditional payment methods and cryptocurrencies can both be exchanged on these exchanges. These alternatives are comparable to currency exchange kiosks seen in international airports, where you can exchange your home currency for the currency of another country.

The following are the most well-known types of cryptocurrency exchanges.

  • CEXs are comparable to regular stock exchanges in that they are centralized. Traditional stock exchanges are similar to CEXs, and traders are brought together and the exchange acts as a third party. These exchanges often demand a fee to ease transactions between buyers and sellers. Centralization implies to entrust your money to someone else in the crypto industry. HFT crypto trading will mainly work with this kind of exchange.

Examples of CEXs include Binance, Coinbase, and KuCoin.

  • DEXs aspire to keep faithful to the cryptocurrency industry's pure premise. A DEX does not need an intermediary to store coins, and it's an online marketplace where buyers and sellers meet and conduct business directly. DEXs, in other words, make peer-to-peer trading easier.

You may exchange crypto-assets directly with other market players on a DEX. Smart contracts and atomic swaps can be used to make transactions. Atomic swaps allow you to trade one cryptocurrency for another without going via a CEX. A smart contract is a piece of code self-executing the term of a contract. It is the foundation of atomic swaps.

Instead of providing cryptocurrencies to the CEX, we will provide them to an escrow controlled by the network that runs the exchange with the DEX, smart contracts, and atomic swaps. Because transactions can take up to 5 days to clear, the escrow is still in place. As a buyer, your money will be taken out of your account right away, but the funds will not be sent to the seller's account until the crypto transaction has cleared.

Because of the latency involved in any transactions, performing high-performance trading on this kind of exchange will be difficult.

Examples of DEXs include UniSwap, PancakeSwap, and SushiSwap.

  • Hybrid cryptocurrency exchanges are the next-generation cryptocurrency trading platforms. They are a hybrid of CEXs and DEXs. Hybrid exchanges, also known as semi-decentralized exchanges, include on-chain and off-chain parts. Off-chain transactions shift the value of your crypto-asset away from the blockchain. The hybrid approach to cryptocurrency exchanges combines the advantages of both CEXs and DEXs. Hybrids, in particular, aim to combine the functionality and liquidity of a CEX with the anonymity and security of a DEX. Many people believe that such exchanges are the true future of BTC trading.

Hybrid exchanges aim to give institutional users the same speed, simplicity, and liquidity that they expect from regular exchanges. The centralized aspects of a hybrid exchange are linked to a network of decentralized peers. Market participants can access the trading platform as they would on a CEX and then trade with their peers as they would on a DEX. The hybrid then offers blockchain confirmation and records transactions.

Examples of hybrid exchanges include Qurrex and NEXT.

These exchanges cannot be found in a co-location where the trading will happen, and most of the time, they are located in the cloud. In the How to build a trading system in the cloud section, we will describe how to build a trading system in the cloud, unsurprisingly. Therefore, the main advantage we have with traditional trading in terms of latency by being in the same location as the exchange will not work for cryptocurrencies.

It is possible to know in which region the exchange (or the matching engine) is located. Therefore, it is possible to have an edge in speed over the other participants.

More recently, some exchanges have decided to have their matching engine in colocation, inviting participants to join them to perform HFT.

Using cryptocurrency market data

The data offered by a crypto exchange is Kline data, Level 1, and Level 2 data. The K line depicts the daily fluctuations in stock prices; it displays the close, open, high, and low prices for the day and illustrates the difference and magnitude between any two values.

The price quoting per IP is unlimited for VIP clients or some major market participants (depending on the volume they trade). But for regular clients, there are some quoting limits for each IP. Some newer exchanges use snapshots on data distribution, but the bigger exchanges use data streaming, creating some arbitrage opportunities.

For HFT, it is important to record any market data. This is because exchanges previously encountered technical issues pretty frequently, and we observe gaps in the historical data. An exchange typically chooses to interpolate data, which can be inefficient on the execution backtest.

Being aware of exchange fees

Transactions are charged in a variety of ways through exchanges. Customers are charged fees, which is how the exchange generates money to continue the business. The most popular technique is when the exchange takes a commission of the money we trade. Most exchanges charge a percentage of less than 1% to remain competitive.

Unlike traditional trading, there are a lot of trading exchanges in crypto trading. It is difficult to have enough liquidity. Because DEXs are less common than CEXs, matching orders with other orders you buy or sell on a DEX may be more challenging. This is a vicious circle since DEX liquidity will stay low as long as they are less popular, and DEXs may stay unpopular as long as liquidity remains low. That is why, for the time being, CEXs are more popular than DEXs in HFT.

Additionally, a CEX will give rebates or lower their commission if traders add liquidities. As in traditional trading, a market-making strategy using a rebate to make money will work in this type of exchange.

In crypto, the transaction fees are 20 to 30 times higher than in traditional markets. In an exchange-based market such as Binance and Huobi, we pay a transaction fee by quote coins (indicating a lot of arbitrage room); in the non-fungible tokens (NFT) market, we pay a transaction fee called gas, which is in ETH.

Some exchanges, such as Binance and Huobi, have their market-making reward program by issuing rebates to qualified market makers who can successfully trade their assigned coins. This can help the rebate earning trading strategy.

Not being capable of selling (or liquidating) an investment promptly and at an acceptable price is likely to happen on any crypto exchange. For any traded asset, liquidity is critical. The foreign exchange (FX) market is the most liquid in the world, and lack of liquidity may concern any market, including the FX market. If you trade currencies with a small amount of volume, you can conclude your deal since the prices just won't change.

Illiquidity may occur with cryptocurrencies as well. It is one of the issues that contributed to the extreme volatility of BTC and other cryptocurrencies. When liquidity is scarce, there is a greater possibility of price manipulation.

When an initial coin offering (ICO) occurs on a crypto exchange, the exchange and the company doing its ICO will use market makers to help to sell their digital assets. When the assets are on the exchange, the market maker will help facilitate transactions. A crypto exchange will play a big part in the trading aspect of the exchange by increasing liquidities artificially. Some trading strategies such as spoofing can be used, and the best available prices may not be available.

The likelihood of being filled on the top of the book of a crypto exchange will be much lower than the one on a trading exchange. In HFT, we need to compete against the market maker associated with the exchange, which will make the trading a bit more challenging.

We will now talk about the type of trading strategies working in the cryptocurrency world.

HFT strategies in crypto

In Chapter 1, Fundamentals of a High-Frequency Trading System, we explained HFT-specific trading strategies. In this section, we will talk about cryptocurrency-specific strategies.

Market making

One of the most tried-and-true HFT tactics is market-making. It entails the continuous and simultaneous quotation of buy and sell orders. Market-making is a financial instrument that adds liquidity to the market and benefits the high-frequency traders engaged. Market makers are traditionally provided by large companies or HFT firms, which is regarded as a positive practice in the financial markets.

Statistical arbitrage

This is the act of betting on the price difference between two exchanges of the same cryptocurrency. The first trader to identify these inconsistencies generally uses the knowledge. To perform statistical arbitrage, you'll need powerful and quick processing machines and up-to-date HFT software. Balancing prices has the overall effect of equilibrating the market.

Smart router trading

High-frequency traders can access liquidity pools simultaneously, choose the optimum order routing destination, and improve order execution. The best bid and offer bids for a certain order are scanned in a pre-defined or real-time market, resulting in the best price.

Maximizing short-term opportunities

Scalping is a word used to describe leveraging short-term possibilities. HFT uses powerful computers with the processing power to execute several orders in a fraction of a second.

Maximizing the trading volume

Traders use automation to their advantage via HFT, also known as high-speed trading. These high-frequency traders can not only execute large numbers of trades, but they also profit from even small price movements.

Building a high-frequency system for crypto trading

Data storage is a priority in all industries, as computer and mobile users have increased. Today's large and small organizations rely on their data, and they spend a lot of money to keep it up to date. It needs solid IT support as well as a storage hub. Not every company can afford the hefty costs of in-house IT equipment and backup support. Cloud computing is a less expensive option. Cloud computing reduces the user's hardware and software requirements.

Like a lot of other domains, crypto started using cloud services heavily. The HFT system we described in the previous chapters can also be used in the cloud.

Types of cloud

We can use the cloud in different ways:

  • Private cloud: Computing resources are deployed for a single enterprise in a private cloud, where they are managed, owned, and operated by the same company.
  • Community cloud: Computing resources are supplied for a community and organizations in the community cloud.
  • Public cloud: This cloud is often used for business to consumer (B2C) interactions. The computer resource is owned, managed, and administered by the government, academic institutions, or corporations.
  • Hybrid cloud: The computer resources are connected by distinct clouds; this deployment strategy is known as a hybrid cloud.

We saw the different types of cloud solutions; we will now talk about the benefits of using the cloud for trading systems.

Benefits of cloud computing

Most of the crypto exchanges adopted cloud services because of the potential for cost savings and the short time-to-market. Cloud computing allows the flexibility to utilize services as needed and only pay for what's needed. We can run IT operations as an outsourced unit without many in-house resources. Additionally, the cost to get engineers is pretty high, and assembling a technical team can be pretty time-consuming.

The main advantages of cloud computing are as follows:

  • Users' IT infrastructure and computing expenditures are reduced, resulting in better performance.
  • There are fewer maintenance difficulties.
  • Updates to the software are available immediately.
  • Compatibility across operating systems has been improved.
  • Recovery and backup.
  • Scalability and performance.
  • Increased data security due to increased storage capacity.

The three major cloud computing models are described in the following sections.

Software as a service (SaaS)

SaaS is a software distribution model in which vendors or service providers host programs and make them available to clients through the internet. As foundational technology for service-oriented architecture (SOA) or web services, SaaS is becoming a more common delivery paradigm. This service is available to people all around the world via the internet. Traditionally, the software had to be purchased in advance and installed on your computer. SaaS consumers, on the other hand, rather than acquiring software, subscribe to it monthly via the internet. Anyone who requires access to a certain piece of software, whether one or two people or thousands of employees in a company, can register as a user. All internet-enabled devices are compatible with SaaS. Accounting, sales, invoicing, and budgeting are just a few of the critical duties that SaaS can help you with.

Platform as a service (PaaS)

PaaS provides a platform and environment for developers to create applications and services. Users can access this service over the internet because it is housed in the cloud. PaaS services are updated regularly, and new features are added. PaaS can help software developers, web developers, and businesses. It serves as a platform for application development. It covers software support and administration, storage, networking, application deployment, testing, collaboration, hosting, and maintenance.

Infrastructure as a service (IaaS)

IaaS is a cloud computing service model. It gives users online access to computer resources in a virtualized environment known as the cloud. It offers virtual server space, network connections, bandwidth, load balancers, IP addresses, and other computer infrastructure. The group of hardware resources is formed from a range of servers and networks spread across several data centers. IaaS gains redundancy and dependability as a result of this. IaaS is a comprehensive computing solution. It is one of the options for small organizations wanting to save costs on their IT infrastructure. Maintenance and the purchase of new components such as hard drives, network connections, and external storage devices cost a lot of money every year.

We will now talk about the component managing the virtual machines (VMs): the hypervisor.

Hypervisor

A hypervisor is a piece of software, firmware, or hardware that allows the construction and operation of VMs on computers. A host machine is a computer on which a hypervisor runs one or more VMs, and each virtual system is referred to as a guest machine. Resources such as CPU, memory, and storage are treated as a pool by the hypervisor, which may be readily reassigned between current guests or new VMs. Because the guest VMs are independent of the host hardware, hypervisors enable the usage of more of a system's available resources and give more IT mobility. The hypervisor is also known as a virtualization layer since it allows them to be easily transferred across multiple systems. A single physical server can support several VMs.

Figure 11.1 represents two types of hypervisors:

Figure 11.1 – Types of hypervisor

Figure 11.1 – Types of hypervisor

Type-1, native, or bare-metal hypervisors

These hypervisors operate directly on the host's hardware to control the hardware and administer guest operating systems. As a result, they're sometimes referred to as bare-metal hypervisors. This form of hypervisor is most popular in corporate data centers or other server-based environments.

Type-2 or hosted hypervisors

Like other computer applications, these hypervisors run on a standard OS. On the host, a guest operating system runs as a process, and guest operating systems are abstracted from the host operating system by type-2 hypervisors. Individual users who want to run various operating systems on a personal computer should utilize a type 2 hypervisor. The trading system will run on the application level on the type-1 hypervisor. Cloud service providers will provide different hypervisors in different regions and availability zones. The goal will be to have the trading system and the exchange in the same availability zone to perform low latency operations. Figure 11.2 represents how cloud providers organize their availability zones and regions:

Figure 11.2 – Availability zone and regions

Figure 11.2 – Availability zone and regions

In this part, we reviewed the cloud structure. It is critical for HFT in crypto since you will need to be as close as possible to the availability zone where the crypto exchange is when we do HFT with a CEX.

We will now study how to build a trading system in the cloud.

How to build a trading system in the cloud

There are three major cloud service providers (CSPs): Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure.

The choice between providers will depend on the cost and the managed services you are familiar with. It would be difficult to advise one CSP over another one in this section. Their offering is pretty similar in terms of hardware, operating system, and open source software you can use. All of them have professional service teams that can help you to design the trading system. If we could recommend a CSP, we would choose the CSP based on the crypto exchange location you target for your HFT strategies.

Solution 1 – Running our HFT on a CSP

We first need to choose the region where the application will be running. This region should be the closest to the exchange. We will need to create the following components on the CSP of your choice:

  • Computing instance
  • Type of VM
  • Storage instance

A computing server instance such as Amazon's Elastic Compute Cloud (EC2), Google Compute Engine (GCE), or Azure VM is required for running applications on the CSP infrastructure. It may be used to create an almost infinite number of VMs.

It is critical to know what type of VM you will spin up. Choosing the wrong type of hardware will not give you a performant architecture for HFT. You need to consider the number of cores, the memory, the storage, and of course, the type of network card.

We will need to apply the same rules we used during the previous chapters. Always remember that if you want to have a performant system in HFT, having many cores will help you to get better performance if the system you build works with many processes. Once you have selected the type of hardware, you will need to choose the OS you want to use. All the CSPs will give similar types of operating systems. Because in this book, we focus on the Unix-based OS, we would like to recommend the use of any Linux distribution. CSPs can provide their own OS version, such as Amazon Linux distributions.

The advantage of the cloud is to give you a flexible way of storing data. This part is less critical than the computing instance since all the processing will happen in memory. However, we have to collect logs for monitoring and debugging the systems and we need to record all the market data to build models. Amazon S3, Azure Blob storage, and Google cloud storage will provide you the scalability, data availability, and high reliability for your critical data.

Once we choose the hardware features, the OS, and the storage unit, we can use the same code algorithm that we have built in the previous chapters of this book.

Now, we know how to move our software to the cloud on a cloud provider. We can also use the leverage that a CSP offers in terms of software. A CSP provides managed services and open source software to bootstrap quicker to an HFT system. We will now explain how to build a trading system from scratch with managed services.

Solution 2 – Using managed services from a CSP

CSPs provide building blocks to design software. The advantage of using managed services or open source software is to get tested and functioning software. You will just need to connect these building blocks together. We would invite you to contact the CSP for advice in terms of building your solution or to read blogs to see the experience of these CSPs in building trading systems. We would like to suggest one implementation inspired by some work done on the cloud. Let's look at the following figure:

Figure 11.3 – Key components for algorithmic trading and trading systems

Figure 11.3 represents the components we need to build an entire trading system, which completes the information we gave in Chapter 2, The Critical Components of a Trading System, where we focused only on the essential path to send an order triggered by market data:

  • The system's heart is Algorithmic Trading Engine, which allows users to build, test, and run trading strategies utilizing historical and real-time data while also managing relationships with other solution components and offering analytics and reporting capabilities.
  • Market Data Adapter provides a variety of data types to the engine, including real-time market data, historical pricing data, and more.
  • Exchange/Broker Adapter handles interactions with the exchange and/or broker, such as placing and rescinding orders and checking the order status.
  • Data Store, employed by algorithmic trading engines, provides a long-lasting and safe data repository.

CSP offers a diverse set of services that enable the development of a wide range of solutions. The following assessments are proposed for defining the algorithmic trading solution architecture:

  • Trading speed: When we explained how to build a trading system in Chapter 2, The Critical Components of a Trading System, we showed how the speed was important to build an HFT system in the design choice. The managed service selection will be based on the latency speed. You have two types of software on CSP: software processing data in real time and software processing data by batch. Managed services (such as AWS Lambda, Azure Functions Serverless Compute, and Google Firebase Cloud Functions) will be able to provide a quick response to any event (such as market data coming into the system). An event engine capable of calling these functions (such as AWS EventBridge, Azure Event Grid, or Google Eventarc services) will be a good combination. The event engine will call a serverless function to process trading system events.
  • Need for data and analytics: Designing trading strategy models requires market data to be stored in a very efficient way. We need to be able to run backtesting using this market data. The amount of data can rapidly grow and it is important to have a scalable solution. We already talked about the storage instance in the previous section. We will add on top of this storage unit some services capable of helping you to analyze data; AWS Athena, Azure Synapse Analytics, and Google BigQuery will help to query and use data.
  • Extensibility and flexibility: An event-driven approach that connects the algorithmic trading engine to market data adapters and external exchanges/brokers over a common API is preferred to decouple all architecture components.
  • Security: CSPs provide security solutions for anything that is related to identity and authorization. For traditional HFT working in colocation, we don't need to consider security as much as when we have our software in the cloud. That's why we wanted to highlight in this part that the use of security services is important. AWS Identity, Azure Active Directory, or Google Cloud Identity will provide authentication, authorization, encryption, and segregation.

We will now propose a design for a trading system that could be built in a few days on any CSP:

Figure 11.4 – Trading system architecture on a CSP

Figure 11.4 – Trading system architecture on a CSP

Figure 11.4 represents a trading system architecture design using the components that we talked about. We simplify the system by using as a user interface just a Python Jupyter notebook. It provides enough flexibility to start processes and build trading strategies:

  • The Load Data component (1) will help get historical data. Market data is obtained through the market data exchange and stored in a storage unit. Any data feed, such as news or other types of trading data sources, might be used depending on the backtesting approach (that is, data already available or produced in-house).
  • The Data Catalog component (2) enables us to have a reference for all the data we have in the system. It will be able to dynamically update data.
  • Using the Jupyter notebook supplied in this design (3), we train the machine learning (ML) model using the ML DevOps notebook instance (AWS Sagemaker, Azure ML studio, and Google Vertex AI AutoML). This architecture's notebook reads data straight from a data bucket, and the given notebook can be modified or changed as needed.
  • After the ML model has been trained (4), it is utilized for actual backtesting using data from a data bucket, and it may be deployed after the results fit your criteria.
  • The part with the 5, 6, and 7 annotations shows taking care of collecting the data in real time from the exchange.
  • Seeing annotation 8, functions such as task scheduling, monitoring, alerting, and logging are necessary after installing the strategy and communicating automatically with Broker/Market Data. For example, when profit and loss (PnL) exceeds preset levels, near-real-time notifications can be created, and alerts can be visual and audible.

This is how we can build an HFT system in the cloud to trade cryptocurrencies. We will now finish this chapter by summarizing what we have learned.

Summary

This chapter was the final chapter of this book. We discussed how to improve the tick-to-trade latency using FPGA. We studied how crypto trading was different from traditional trading. We learned how to build an HFT system in the cloud.

Since this is the end of this book, we would like to take the opportunity to remind you that technology evolves very fast. In this book, we presented the basics of HFT. However, we need to remember that being among the fastest HFT companies costs a lot in terms of money and time. Engineers, hardware, network, and connections are vital parts of HFT. Even if we don't have the quickest architecture, data analysis can always help build robust HFT strategies capable of performing within the limitation of our system. This book drew the basics of creating an HFT system by considering the HFT optimization technique.

We are getting to the end of this journey together. We would like to thank you for reading this book and invite you to contact us if you would like to discuss HFT.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.102.182