0 votes
by (20.3k points)
Introducing AutoTrade.
This is part one of a three part series about using the Tradovate AutoTrade framework to create auto-trading strategies. This article will outline broader concepts about the framework and is intended as an introduction to using the software. We will go into greater detail about the internal workings of Tradovate AutoTrade later in the series.
Developing a quality trading strategy that works for you can take years of research and trial-and-error. Once you’ve found something that works, you’ll wish that you could automate it. Now that Tradovate offers its API to everyday users, you can do just that.
Many traders take cues from indicators — depending on the complexity of the conditions behind these cues and indicators, it is usually possible to automate them. Automation can be a great way to take the emotional pressure out of day trading, especially if you already have a pre-determined set of cues or ‘rules’ that you already follow. The robot also doesn’t need to eat, sleep or take breaks, giving it a great efficiency advantage compared to a human trader.
Note : I will assume the reader has at least a working knowledge of NodeJS and JavaScript, if not I’d suggest starting with those before you continue with this guide.
To build our futures-trading robot, you will need to get access to the Tradovate API. To access the API you will need to get a few things in order first:
Be a registered Tradovate user with non-social credentials (meaning you didn’t sign up using Google and have a username/password credential pair). Have a LIVE account with at least $1,000 in equity. Generate an API Key.
You can get a detailed guide on how to tackle this task here.
Once you’re setup with your Tradovate API access, go clone the example-api-trading-strategy repository. Once you’ve gotten the repo, open a terminal and navigate to the containing folder. Take care of installing the dependencies with yarn :
yarn install.
I’ll explain how to setup your environment variables as we cover the basics of how the platform works.
General Concepts.
Tradovate AutoTrade is an event-driven auto trading framework. The AutoTrade application catches events sent from the Tradovate API and allows you, the developer, to decide how to process those events. It takes care of managing the real-time subscriptions so that you can focus on responding to the events. The Strategy class can catch any event that the API can produce, from DOM or Chart updates to User Data updates, order modifications, and more. To see the primary event types, look in the strategy template file, yourCustomStratey.js . The main events are listed in next in the switch statement as TdEvent s.
Props type events have additional subtypes, as these consist of the create and update events on entities that your user cares about.
Let’s configure our robot and get a closer look. Open index.js . There are three main sections to this file — the imports, the environment variable declarations, and the main entry point function. The environment variables are right near the top, below the large commented section.
Remember to set your environment variables before trying to run the robot!
You’ll need to supply your own Tradovate credentials, security key and application CID. If you followed along with the gaining access guide from above, you should already have these. Take note that you can also switch from demo to live by changing the URLs to their live equivalents.
Next we declare our strategies. As you create your own strategies, you can add them as options to the configuration step by placing them in the ALL_STRATEGIES object.
The main async entry function is very straightforward. First we acquire our access token by making a request to the Tradovate REST API. We use the acquireAccess utility function to make it as easy as possible. Next, we call configureRobot , passing it the ALL_STRATEGIES object as a parameter. This function runs the configuration routine based on your chosen Strategy class. It then constructs a new strategy, which will begin an event-driven chain of calls defined by the author of the strategy. Now that we know how to configure the index.js file, let’s give the robot a test run.
Running the Example CrossoverStrategy Class.
After you’ve installed your dependencies, you can simply run yarn start from the terminal to start the robot. You’ll be presented with some initial choices and data, such as choosing the account and contract you’d like to trade. Then the configuration routine will run, and the parameters from CrossoverStrategy.params will be requested as user input. Once you are satisfied with your choices, the robot should clear the console and begin showing you live data updates about its status and performance so far.
Hey! Does the configuration part annoy you? I found when testing the robot, running the config each time was a huge pain. If you’re in the same boat, simply comment out the configureRobot call and instantiate your strategy class directly in the main function after acquireAccess . Provide the strategy you are instantiating an object with your chosen parameters hardcoded. The only caveat is that you’ll need to provide every parameter, including the getChart request data, the contract you want to trade, and all the params you define on your strategy subclass, as well. I’d suggest using the askForContract utility to acquire a contract using the console, but dropping the configureRobot part while you’re running many iterations of your strategy.
Extending the Robot.
Extending the AutoTrade platform is as easy as defining your own custom Strategy class. The Strategy base class defines functionality and behavior that is shared across all strategy instances. For example, each strategy instance maintains its own subscription to live data from the contract you choose to trade. Conveniently, you don’t have to worry about opening or maintaining those subscriptions, because it’s done for you in the base Strategy class. Open yourCustomStrategy.js and we’ll take a look at how we can hook into AutoTrade’s Tradovate API events.
The Strategy template file included with the project.
We can declare our initial robot state in the init function. You can see that each type of event that can be emitted by the API can be caught in the next function via switch statement. Catching any event is optional, so you will only have to define what you need for the specific strategy you’re developing. You can pass on all the cases you don’t care about by simply returning the existing state in the switch 's default case.
Note: I’d suggest utilizing the concept of function extraction when designing the responses to events. As an example, imagine you place all your strategy code in the switch statement. This is theoretically fine, but it will be very difficult to change it later, or even read it if your strategy becomes large. Instead, consider calling a function from the switch when an event is received, eg. case TdEvent.Chart: return onChart(state, data); . You could even keep these functions in separate files!
Each event type has a different response object shape . Let’s take a look at each:
Quote.
DOM.
Chart.
For the MinuteBar type:
And the Tick variety:
User Sync.
Props.
Props is an overarching event type for user data updates. Each response is broken into this structure:
This is an example of a cash balance updated Props event. Each Props event has the entityType , eventType , and entity fields. You can import an enum-like object EntityType from the strategy.js file that contains valid entity types for sorting your incoming Props messages. If you ever need a reference to what the entity data for a type looks like, refer back to the User Sync response data.

Please log in or register to answer this question.

...