Reader small image

You're reading from  Getting Started with Forex Trading Using Python

Product typeBook
Published inMar 2023
PublisherPackt
ISBN-139781804616857
Edition1st Edition
Right arrow
Author (1)
Alex Krishtop
Alex Krishtop
author image
Alex Krishtop

Alexey Krishtop is a quantitative trader and researcher with 20 years of experience in developing automated trading solutions. He is currently the head of trading and research at Edgesense Technologies and CTO at ForexVox Ltd. He develops market models and trading algorithms for FX, commodities, and crypto. He was one of the first traders who started using Python as the ultimate environment for quantitative trading and suggested a few approaches to developing trading apps that, today, have become standard among many quant traders. He has worked as a director of education with the Algorithmic Traders Association, where he developed an exhaustive course in systematic and algo trading, which covers the worlds of both quantitative models and discretionary approaches.
Read more about Alex Krishtop

Right arrow

Retrieving and Handling Market Data with Python

If you look at the general logical diagram of a trading application’s architecture, which we devised in Chapter 1, Developing Trading Strategies – Why They Are Different, you can see that now we’re moving from the very first module named Receive data to the second one, Cleanup and filter, which features the Store and Retrieve functionality.

In previous chapters, we mentioned many times that any algo trading application is based on market data, and success in algo trading (that is, the ability to make money and not lose it) depends on the quality of the data and its consistency. So, let’s proceed to determine which data we really need to collect and how to make sure the collected data is consistent, then decide about the internal format for the trading app, and the way to store, update, retrieve, and delete data (if necessary).

Upon finishing this chapter, you will have a clear understanding of the most...

Data compression – keeping the amounts to a reasonable minimum

In the previous section, we already considered one of the most popular data compression techniques used by data providers: snapshots. The difference is that a tick represents a single event (such as a new trade or a change in bid or ask) and a single price value, but a snapshot instead discards information about individual ticks and replaces it with the following prices per period:

  • Price of the first tick of the period (or open)
  • Maximum price for the period (or high)
  • Minimum price for the period (or low)
  • Price of the last tick of the period (or close)

For example, if the period is 1 minute and during this minute 100 trades were placed, then the snapshot will replace 100 ticks (or 100 prices) with just 4 prices.

The resulting snapshots are called bars when plotted on charts. Very frequently, traders and developers use bars instead of snapshots. Graphically, a bar is typically presented...

Working with saved and live data – keeping your app universal

In the previous chapter, we quickly observed various methods to get market data from LMAX, one of the most important ECNs in the FX market. Without going into too much technical detail, we can assume that most other brokers, trading venues, and data vendors use more or less the same protocols and APIs based on socket connections. So, it should not be a problem to re-adapt your code to start retrieving data from a new source.

However, from the previous chapter, I hope you also remember that despite similarities in the transport layer of the connection, almost every data source has its own features that can only be found in its documentation (and sometimes, unfortunately, only in direct talks with its technical support).

This means that even if you implemented—for example—Financial Information eXchange (FIX) protocol version 4.4 with one broker, it is quite possible that you will have to modify something...

Summary

In this chapter, we learned how to process both live and historical market data and, most importantly, how to do it in an efficient way. We are now familiar with time-based bars, which are most heavily used in trading strategies. We also learned about the solution that helps keep our trading applications flexible and quickly switch from one data source to another, which will help when switching from testing to production in the future.

Now, we are ready to move on to using the processed market data in our trading strategies. Let’s see how we can do this in the next chapter.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Getting Started with Forex Trading Using Python
Published in: Mar 2023Publisher: PacktISBN-13: 9781804616857
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Alex Krishtop

Alexey Krishtop is a quantitative trader and researcher with 20 years of experience in developing automated trading solutions. He is currently the head of trading and research at Edgesense Technologies and CTO at ForexVox Ltd. He develops market models and trading algorithms for FX, commodities, and crypto. He was one of the first traders who started using Python as the ultimate environment for quantitative trading and suggested a few approaches to developing trading apps that, today, have become standard among many quant traders. He has worked as a director of education with the Algorithmic Traders Association, where he developed an exhaustive course in systematic and algo trading, which covers the worlds of both quantitative models and discretionary approaches.
Read more about Alex Krishtop