Integration – Manually

You can calculate TA off of any candle set you have. Using this method requires sending a simple post including the candle data for which to calculate an indicator value.

Pros

  • Calculate TA for any market / exchange / symbol / time frame, stock-market, crypto-market, OTC, etc… 
  • Run backtesting on your strategy if you have the historical data.

Cons

  • You need to have / get the candle data ready yourself.

Getting started

Using this manual method requires invoking a POST on the API:

[POST] https://ta.taapi.io/rsi

Submit a post with parameter ‘params’ to the above endpoint which includes your ‘secret’ and a ‘candles’ parameter containing the candles in JSON. The candles must be sent as objects with the below keys in an array:

  • open: A float, containing the open price of the candle
  • high: A float, containing the high price of the candle
  • low: A float, containing the low price of the candle
  • close: A float, containing the close price of the candle
  • volume: A float, containing the volume of the candle

Candles must be submitted in ascending order, being the latest / newest candle last.

Example:


[
   {
      'timestamp': 1571320286000, // In milliseconds, optional
      'open': 238.32,
      'high': 343.12,
      'low': 125.94,
      'close': 243.48,
      'volume': 84342.84823
   },
   {
      'timestamp': 1571320286000, // In milliseconds, optional
      'open': 238.32,
      'high': 343.12,
      'low': 125.94,
      'close': 243.48,
      'volume': 84342.84823
   },
   ... n candles
]

The amount of candles depends on which indicator is used. If not sure, then send 300 candles. This amount will work for more or less all indicators.

Mandatory Parameters

Below a list of mandatory post parameters, needed to query the API “manually”:

ParameterTypeDescription
secretStringThe secret which is emailed to you when you Request an API key.
candlesJSON (array with candle objects)A JSON encoded array of objects containing candle information, ascending order (as described above)

Note: The parameters must be wrapped in an object named ‘params’, see examples below.

Optional Parameters

There are no optional paramters for this integration method, other than the ones stated for each indicator on the Indicator endpoints page.

Note: You cannot use the ‘backtrack’ option with this method. If you need to calculate back in time, then remove candles from your dataset yourself.

Examples

NodeJS

// Require axios: npm i axios
const axios = require('axios');

const indicator = 'rsi';

axios.post(`https://ta.taapi.io/${indicator}`, {
  params: {
    secret: MY_SECRET,
    candles: [{...}]
  }
})
.then(function (response) {
  console.log(response.data);
})
.catch(function (error) {
  console.log(error);
});

PHP

<?php

$indicator = 'rsi';

$parameters = json_encode(array('params' => array(
  "secret" => 'MY_SECRET',
  'candles' => [{...}] // Candles in json
)));
 
// Prepare new cURL resource
$ch = curl_init("https://ta.taapi.io/{$indicator}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
 
// Set HTTP Header for POST request 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($canldes))
);
 
// Submit the POST request
$result = curl_exec($ch);
 
// Close cURL session handle
curl_close($ch);

// View result
print_r(json_decode($result));

Python

# import the requests library
import requests

# Get candles from your own source
candles = [{...}]; # Candles in json

# Define indicator
indicator = "rsi"

# Define endpoint
endpoint = f"https://ta.taapi.io/{indicator}"

# Parameters to be sent to API
parameters = {
    'secret': 'MY_SECRET',
    'candles': candles
}

# Send post request and save response as response object
response = requests.post(url = endpoint, json = {
    'params': parameters # Note the 'extra' params key here
})

# Extract data in json format
result = response.json()

# Print result
print(result)