Tradovate Futures Trading Blog

AutoTrade Deep Dive

Posted by Tradovate Technologies on September 24, 2021 at 11:09 AM
Find me on:

pt2-displayPrice-autotradeAdding Your Own Extensions to Tradovate AutoTrade

This is part two of a three part article series. In the first article, Introducing Tradovate AutoTrade, we discussed how to acquire the necessary resources to run the AutoTrade framework, we reviewed the basic layout of the platform, and we learned how to run the example project. In this article we will go into detail about extending the robot.

 

The Tradovate REST API has an enormous amount of functionality and flexibility — however this affects the rate at which one can learn and master the API. AutoTrade is intended to flatten the learning curve a bit, offering boilerplate code for communicating with the API as well as a high-level interface for writing your own automated strategies.


We’ve already gone over the basics of catching events from the Tradovate API using the Strategy class’ next function, using function extraction to separate our logic into readable units. I also hinted at the functional-paradigmatic nature of the next function’s implementation. Let’s talk more about that.


If we were to look at the pre-built CrossoverStrategy implementation, we’d see that each of the extracted event handler functions (that is onChart, onProps, etc.) each return an object with at least a state field, but optionally an effects field as well. Below is CrossoverStrategy's onUserSync handler, it catches TdEvent.UserSync events and produces a new state based on the data and props parameters. Typically UserSync happens once — right after the socket connects to the server. We can use it to find our existing positions, or other data related to your particular user. Pay close attention to the return object, which utilizes both the state and optional effects fields:

 

AutoTrade - State & Effects Code

 

All this code really says is that if you already have a position in the chosen contract at startup, add it and its product data as the position and product fields of the state object, respectively. 

 

Continue Reading the "AutoTrade Deep Dive" Article

 

If you missed part one of this three-part series which outlines broader concepts about the framework and is intended as an introduction to using the software, read the first article "Introducing AutoTrade".

The official blog of Tradovate, exploring futures trading from issues to innovations.

 

Subscribe to this blog


Recent Posts