0

Tradetron API Integration – Amibroker | TradingView | Python

As you would know, Tradetron is a SaaS based application that has simplified automated trading up to a great extent. Using Tradetron you can create your strategies, backtest them and finally deploy them live using your broker’s interface. However, many of us who are practicing algorithmic trading since before the advent of Tradetron might already have our strategies defined elsewhere (Amibroker, TradingView, Python, etc). If you want to reuse those strategies and leverage the Tradetron platform to automate them, you’ll need to learn Tradetron API Integration.

Tradetron API Integration

Also Read: How to find the Best Strategies from Tradetron Marketplace?

How do Tradetron APIs work?

Tradetron has a very simple API interface. Every strategy in Tradetron has an API OAuth token associated with it. This token can be used to access the strategy programmatically from 3rd party applications like Amibroker.

The Oauth token can be generated from the strategies page

Tradetron API Integration1

Tradetron API Integration2

A typical API link looks like this:

https://api.tradetron.tech/api?auth-token=a1a76057-bfd8-4922-96d2-0b6e0c3ee195&key=position&value=1

The key and value at the end of the URL play an important role here. In the above URL, key is “position” and its value is “1”.

Whenever you fire this API from outside, the ‘key’ gets stored as a runtime variable of that strategy. And this runtime variable can be used in the condition builder for taking positions.

The below strategy logic buys current month Nifty futures when the value of runtime variable “position” is set to 1

Tradetron API Integration3

Tradetron API Integration4

So essentially, using the Tradetron API Integration, the strategy rules can be coded outside, and only the signals can be sent to Tradetron in the form of runtime variables.

Also Read: Amibroker vs Tradetron – A Comprehensive Comparison

How to fire Tradetron APIs?

Every application would have its own way of firing Tradetron APIs. 

In Amibroker, you can use InternetOpenURL() function to call any API. 

ih = InternetOpenURL( "https://api.tradetron.tech/api?auth-token=a1a76057-bfd8-4922-96d2-0b6e0c3ee195&key=position&value=1" );

printf( "API Response: " );

if( ih )

{

     while( ( str = InternetReadString( ih ) ) != "" )

  {

         printf( "%s", str );

  }

     InternetClose( ih );

}

 

The value of the ‘Position’ variable can be calculated in the AFL code based on strategy logic.

If your strategy logic is built in Python, you may use the below sample code to invoke Tradetron API

import requests

import json

url = "https://api.tradetron.tech/api?auth-token=45eaad8f-6506-4559-8276-beba0720d4fe&key=position&value=1"

payload = ""

headers = {

  'Authorization': 'Bearer 9436e843-e5d9-42b1-b24a-2a4592320103',

  'Content-Type': 'application/json'

}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

From TradingView, you can invoke API from alerts via webhook, these webhooks send an HTTP post request to Tradetron. Example below:

Tradetron API Integration5

You can read more about these integrations at the below links:

Tradetron TradingView Integration

Tradetron Amibroker Integration

Pros and Cons of Tradetron API Integration

API Integration with Tradetron is a very powerful feature, but still, it should be used judiciously considering all the pros and cons.

Pros:

  1. You can build complex strategy rules using Amibroker, Python, etc, and integrate them with Tradetron through APIs. Sometimes it’s not possible to code complex strategies in Tradetron directly.
  2. Any 3rd party application can be integrated with Tradetron using these lightweight REST APIs

Cons:

  1. API integration may add up to a few milliseconds of latency, the time it takes to execute these APIs and instantiate runtime variables.

Final Thoughts

The Tradetron platform has opened up endless possibilities for retail traders to build their own algorithmic trading systems. With features such as API integration, we can leverage the powerful execution features of Tradetron and yet can have the strategy logic defined elsewhere. This can have many use cases, more than what you can think of!

If you haven’t already, start your Tradetron journey today.

Related Posts

Leave a Reply

Your email address will not be published.