Development of trading systems for FPGA: Pros, cons and analysis of the architecture of the existing library



    Many trading platforms for high-frequency trading often work on equipment with high-performance network adapters. However, the disadvantage of such systems is the relatively high and unpredictable delay - as a result, many traders turned their eyes to hybrid architectures with hardware acceleration.

    Algo-Logic Systems Inc. experts John Lockwood (Jowhn W. Lockwood), Adwait Gupte (Adwait Gupte) and Nishit Mehta (Nishit Mehta) published a work in which they talked about how FPGAs are used in online trading to reduce data transmission delays. We bring to your attention the main points of this publication.

    Why speed matters so much in HFT


    Modern exchanges broadcast financial information through various data streams. Traders monitor these flows, analyze prices and demand for specific financial instruments (stocks, futures, options, etc.) in order to understand when and what transaction to make - when a decision is made, an order to buy or sell the necessary instrument is sent to the exchange.

    With the development of electronic commerce, the so-called high-frequency trading (HFT) has also become more widespread - according to various estimates, already in 2010 on American exchanges more than 70% of transactions were carried out using algorithms.

    HFT traders try to exploit emerging market inefficiencies. Thus, they not only make money, but also make financial markets more efficient. However, due to the growing number of high-frequency traders who are trying to capitalize on the same inefficiencies, only the first few traders can really make money on a certain opportunity. So, they need to get ahead of the competition.

    The second important reason is the concept of slippage - in the case of highly liquid financial instruments (for example, stocks), after sending an order, say, to buy at a given price, the transaction may be less profitable, since until the order reaches the exchange, the price will change. Accordingly, the longer the delay from the time the order was generated to the moment it is executed, the greater the slippage and, as a result, the trader’s lost profit.

    Thirdly, there are trading strategies, such as latency arbitrage, the essence of which is that the trader should be able to get market information and send orders faster than other players. In such a situation, every millisecond won can significantly improve the performance of the strategy.

    Varieties of HFT platforms


    Currently, most traders and brokers are creating their HFT systems using popular software and hardware technologies. This allows us to describe algorithms with the help of many high-level programming languages ​​that are familiar to many (which of them are used in the financial sector, we wrote here ), and you can make changes to them quite quickly if necessary.

    However, the pursuit of speed leads to the fact that unpredictable response time of software systems becomes an obstacle to successful trading. Consider the existing software and hardware approaches to creating HFT-systems.

    High Frequency Software Platforms

    There are a fairly large number of companies offering software for high-frequency trading (for Western exchanges, for example, Mantara, Ulink and QuantHouse). When using them, most of the delays are due to the operation of the operating system on which the software is running, as well as the network stack. To combat this, users can use high-performance network cards (such as those from Solarflare or Myricom) that speed up certain parts of the network stack.

    “Custom” hardware HFT platforms

    The relatively high delays of software trading platforms forced industry representatives to look for alternative approaches to reducing delays using special hardware. Typically, things like ASICs are not considered in HFT trading because they lack the flexibility to subsequently reconfigure or work with new protocols. GPUs also cannot offer significant performance. The FPGA (Field-Programmable Gate Arrays) technology has become a suitable tool for gaining flexibility and achieving the required performance.

    FPGA can be used to speed up financial applications in various ways. One of them is called Hybrid Computing and is used, for example, in risk management models, calculating option prices and portfolio modeling - when it is applied, the speed of the system can increase by three orders of magnitude.

    This approach complements conventional multi-core processors with FPGA coprocessors. Typically, communication with the CPU is via high-speed connectors like FrontSide Bus (FSB), PCI Express, or QPI. The trading modules themselves in this case are written in high-level programming languages.

    Another way to use programmable logic to speed up is to use the so-called Smart NIC. This usually refers to a combination of high-speed network interfaces, host PCI, memory, and FPGA interfaces. Here, the FPGA acts as a NIC controller, acting as a bridge between the host computers and the network and allowing you to integrate program logic directly along the data path. Thus, Smart NIC can operate as a trading platform under the control of the host machine's CPU.



    Pros and Cons of FPGA for High Speed ​​Trading


    Using modern FPGAs, you can implement any aspect of HFT applications. Incoming market data can be entirely processed on the FPGA without the need to send it to and from the processor. The figure below shows a comparison of an FPGA platform with a regular software platform:



    In the latter case, a network adapter is needed to receive network traffic. The necessary part is then transferred to the processor, which is "interrupted" to process the application. After its completion, data is sent back to the network adapter and transmitted over the network. In this situation, an approach involving interruptions, as well as the presence of unpredictable delays during PCIe transfers and caching, increases the network delay and makes it difficult to predict it.

    In contrast, in the case of FPGAs, incoming network data is fed directly to a customized, highly optimized system through the MAC and PHY iron blocks. Moreover, in fact, the necessary information can be extracted even before the packet is completely received. Thus, the use of FPGA can achieve a significant reduction in overall delay.



    Cons of Using FPGA

    The use of FPGA has its drawbacks in comparison with traditional approaches to the development of trading systems. The root of the problem is the higher complexity of the FPGA development thread. A significant part of financial system developers and traders are not familiar with this technology and they lack the knowledge and expertise to implement hardware-oriented development.

    Secondly, the development and testing of new hardware solutions due to the lower level of abstraction is a more complex and lengthy process compared to the usual writing of a trading robot. All this is illustrated in the figure below:



    To avoid this, some FPGA-based HFT platforms have special high-level environments that allow you to create trading systems without the need for hardware description languages ​​(HDL).

    How it works: Algo-Logic Library


    Algo-Logic's low latency library is a gateway tool that is compatible with standard FPGA platforms. This tool processes financial protocols used by exchanges in the USA, Europe and other countries, extracting information from packages while they are passing through FPGA. Library components are used to build high-speed trading applications.

    The library components are divided into two categories - infrastructure components (interfaces for the network, external memory and host software) and financial information processing modules (protocols, parsing processes, etc.) The figure below provides a more detailed description of these blocks:



    Infrastructure Components

    All infrastructure components use a standardized interface with a 64-bit machine word. SRAM provides low latency and high performance storage for small amounts of data.

    The register interface module controls and monitors the status of the registers into which the software running on the host machine writes and reads. It contains various types of registers, including write-only configuration registers, read-only status registers, etc. Configuration and status data is transmitted and received over UDP. Access to the register interface can be obtained through the C ++ API on the host or through the web GUI.

    Financial Information Processing Components

    The Algo-Logic library has IP blocks designed for processing application level messages for high frequency trading. These messages contain orders and orders execution reports sent between clients, brokers and exchanges. Among these components are:

    Parser of financial protocols - receives data from the TCP / IP processing layer and determines the boundaries of the message. The parser then extracts the individual fields and sets the flag when the values ​​of each field are validated. This allows a reduction in extraction delay. Now in this particular library there are parsers for FIX, OUCH, XPRS, AcaDIirect, Native Trading gateway protocols that are used on various exchanges from NASDAQ to London Stock Exchange.

    Consider the work of the parser using the OUCH protocol (NASDAQ) as an example. The received message is passed to the parser, which extracts the fields and sets the necessary flags. For example, a message type field (“O” or “Enter Order”) and a 14-byte order token are retrieved. The buy or sell indicator is “T” (Sell Short), the number of shares is 1002, the stock ticker of a financial instrument is FFHL. The remaining fields indicate the desired transaction price, as well as information that the order cannot be moved to another market.



    Parsing market data and storing price data “on a chip” - financial applications need to know the share price that is used in orders. To track prices, market data is sent to the card using UDP / IP datagrams. The FPGA then retrieves the price updates and stores this data for each stock. The prices of all 8,000 shares traded on US exchanges are placed in the FPGA chip memory.



    Conclusion


    In an effort to reduce possible delays in trading and processing financial information, brokers, traders and exchanges themselves are mastering work with new technologies that will allow building highly efficient platforms.
    One of these technologies is FPGA, however, it is important to remember that this tool is not a silver bullet - in addition to speed advantages, there are also difficulties in developing and maintaining the system when using it.

    However, this tool provides good opportunities to increase the speed of financial applications. And here it is important that the entire infrastructure used by the trader meets the requirements to minimize delays - for this, ITinvest clients, for example, can use direct connection technologyand place their equipment in ITinvest racks in the colocation zone of the Moscow Exchange with a channel width of 10 gb / s.

    Also popular now: