You are currently viewing #2: Getting Data from Broker – LearnMLTrading Series

#2: Getting Data from Broker – LearnMLTrading Series

Welcome back to the LearnMLTrading Series.

This week we are looking at getting price data from broker, as well as some initial components, system and deployment ideas.

Components

Some of the classes we will need to implement are:

  • Broker: Handles order execution, prices and order fulfillment.
  • Strategy: Generates positions to be relayed to broker based on prices.
  • Backtester: Performs backtest of strategy on historic data.
  • Indicator/Model: Given a set of features (last K prices), decides on buy / sell.

Backtesting

For backtesting, we can make use of a package called Backtesting.py

We are leveraging a lightweight package like this rather than building our own, because the package comes with a lot of plotting features and metrics that would take a lot of time to implement from scratch. Here is an image from Backtesting.py that shows of some of these plotting features:

Initial System Design Ideas

An event-driven architecture is going to be useful for us.

Deployment Ideas

My initial idea for deploying the model is quite simple:

  • AWS EC2 instance running a Python script in the background (using screen or nohup)
  • Maybe use Docker for a consistent deployment across time / machines
  • Set up notifications to alert us for trades, errors, warnings etc.

Of course I am open to ideas if anyone has other ideas of how we could deploy the system!

Getting Price Data from the Broker

We are going to be using OANDA as the brokerage for this project, but getting price from other brokers will be similar. The official OANDA API docs can be found here: https://developer.oanda.com/rest-live-v20/introduction/. In particular, we will be focusing on getting price data for now, so we are interested in the Instrument/Candles endpoint: https://developer.oanda.com/rest-live-v20/instrument-ep/.

The code for getting the price data can be found here: https://github.com/WianStipp/LearnMLTrading/blob/master/learnmltrading/broker/broker.py

If you want to learn more about interacting with the OANDA API, we have a detailed video here: https://www.youtube.com/watch?v=bqGanqATx6Q&ab_channel=LearnML 

Next Time

  • Improving the get_historic_prices method to get more data at once
  • Integrating our prices with the Backtesting.py package
  • Practice executing trades.

 

This Post Has 3 Comments

  1. tkescorts.com

    Hello! I simply wish to give you a big thumbs up for your excellent information you have right here on this post. I will be returning to your web site for more soon.

  2. Richard

    why only 2 videos…? you are a very good course. just as good as than the switzerland guy. https://quantnomad.com/ your course info from your videos is up there with probably top 5 i have ever seen on youtube. EXCELLENT!

Leave a Reply