taapi

A wrapper and a client for the TAAPI.IO API

Usage no npm install needed!

<script type="module">
  import taapi from 'https://cdn.skypack.dev/taapi';
</script>

README

TAAPI.IO

TAAPI.IO is an API that calculates Technical Analysis Indicator values.

This NPM package is a wrapper and a client for communicating with the TAAPI.IO API

Using this service requires registration. Please check TAAPI.IO. We offer free and paid plans.

Using this client supports all exchanges / markets / timeframes. This client will take care of fetching candles from the exchanges and passing them on to https://api.taapi.io for indicator calculation. This means that you yourself are responsible for staying under the exchanges rate-limits! A list of exchangeId's can be found at TAAPI.IO Client Documentation.

Note on exchanges and limits

The different exchanges has different limits as to how many candles one can fetch in one go. Therefore, a default of 100 is set here. We're updating our documentation to reflect each exchanges individual limits. But for now, you need to double check that the amount of candles that you expect are returned, and that the last one has the expected timestamp. Candles are always returned with the oldest first and newest last.

Getting started

  • Sign up for a free/paid API key at TAAPI.IO
  • Create a new node project: npm init
  • Install this package: npm i taapi --save

Using this NPM package as a wrapper

Get started quickly with NodeJS and calculate indicator values with few lines of code.

  • Create your entry js file (index.js for instance) containing:
// Require taapi
const taapi = require("taapi");

// Setup client with authentication
const client = taapi.client("MY_SECRET");

// The client params
// client.getIndicator(indicator, exchangeId, symbol, interval, additionalParams, backtrack, candlesCount);

// Get the BTC/USDT RSI value on the 1 minute timeframe from binance
client.getIndicator("rsi", "binance", "BTC/USDT", "1m").then(function(result) {
    console.log("Result: ", result);
}).catch(function(error){
    console.error(error);
});

// CMF 10 minutes ago from kucoin
client.getIndicator("cmf", "kucoin", "BTC/USDT", "1m", null, 10).then(function(result) {
    console.log("Result: ", result);
}).catch(function(error){
    console.error(error);
});

// Current 200 Moving Average. Note here that binance supports fetching 500 candles making the 200 MA posible.
client.getIndicator("ma", "binance", "BTC/USDT", "1m", {optInTimePeriod: 200}, 0, 300).then(function(result) {
    console.log("Result: ", result);
}).catch(function(error){
    console.error(error);
});

// 50 Moving Average 10 minutes ago, Bitmex supports fetching only 100 candles
client.getIndicator("ma", "bitmex", "BTC/USD", "1m", {optInTimePeriod: 50}, 10).then(function(result) {
    console.log("Result: ", result);
}).catch(function(error){
    console.error(error);
});

Using this NPM package as a server with other programming languages

You can use this package as a server, which will take care of fetching candle data from the exchanges and passing it on TAAPI.IO for calculation. Then use your favorite programming language to build your robot. Starting the server will setup a local REST API, that you can then query.

// Require taapi
const taapi = require("taapi");

// Setup client with authentication
const server = taapi.server("MY_SECRET");

// Define port - Optional and defaults to 4101
// server.setServerPort(3000);

// Start the server
server.start();

Fetching data from a PHP script:

// Define query
$query = http_build_query(array(
  'indicator' => 'rsi',
  'exchange' => 'binance',
  'symbol' => 'BTC/USDT',
  'interval' => '1h',
  'candlesCount' => 200, // Default 100
));

// Define endpoint. Change the port if you changed it when setting up the server
$url = "http://localhost:4101/indicator?{$query}";

// create curl resource 
$ch = curl_init(); 

// set url 
curl_setopt($ch, CURLOPT_URL, $url); 

//return the transfer as a string 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

// $output contains the output string 
$output = curl_exec($ch); 

// close curl resource to free up system resources 
curl_close($ch);

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

Using this NPM package to fetch candle data from exchanges

// Require taapi
const taapi = require("taapi");

// Init
const exchangeData = taapi.exchangeData();

// The exchangeData params
// exchangeData.getCandles(exchangeId, symbol, interval, backtrack, candlesCount)

// Get the last 100 candles from Binance for the BTC/USDT 1m
exchangeData.getCandles("binance", "BTC/USDT", "1m", 0, 100).then(function(result) {
    console.log("Result: ", result);
}).catch(function(error){
    console.error(error);
});

// Get last candle from Binance for the BTC/USDT 1m
exchangeData.getCandles("binance", "BTC/USDT", "1m", 0, 1).then(function(result) {
    console.log("Result: ", result);
}).catch(function(error){
    console.error(error);
});

// Get 1 candle 10 minutes ago from Kucoin for the BTC/USDT 1m
exchangeData.getCandles("kucoin", "BTC/USDT", "1m", 10).then(function(result) {
    console.log("Result: ", result[result.length - 1]);
}).catch(function(error){
    console.error(error);
});

// Note: This will return 180 candles, this is not a bug
exchangeData.getCandles("binance", "BTC/USDT", "1h", 20, 200).then(function(result) {
    console.log("Result: ", result.length);
}).catch(function(error){
    console.error(error);
});

Calling multiple indicators in Bulk

// Require taapi: npm i taapi --save
const taapi = require("taapi");
 
// Setup client with authentication
const client = taapi.client("MY_SECRET");

// Init bulk queries. This resets all previously added queries
client.initBulkQueries();
 
// Get the BTC/USDT rsi, ao, adx, cmf, macd, atr, rsi 5 hours ago, 50 MA values on the 1 hour time frame from binance
client.addBulkQuery("rsi", "binance", "BTC/USDT", "1h");
client.addBulkQuery("ao", "binance", "BTC/USDT", "1h");
client.addBulkQuery("adx", "binance", "BTC/USDT", "1h");
client.addBulkQuery("cmf", "binance", "BTC/USDT", "1h");
client.addBulkQuery("macd", "binance", "BTC/USDT", "1h");
client.addBulkQuery("atr", "binance", "BTC/USDT", "1h", null, 0, "my_custom_id"); // Override id
client.addBulkQuery("rsi", "binance", "BTC/USDT", "1h", null, 5); // RSI 5 hours ago
client.addBulkQuery("ma", "binance", "BTC/USDT", "1h", {optInTimePeriod: 50}); // 50 MA

client.executeBulkQueries().then(result => {
    console.log(result);
}).catch(error => {
    console.log(error);
});

Calling multiple indicators in Bulk (Other programming languages)

The server part of this client can also query in bulk, to do this, please visit the TAAPI.IO Client Documentation

v1.2.6 Updates

Bulk queries added to the local server. 3 new endpoints added:

  • /init-bulk-queries
  • /add-bulk-query
  • /execute-bulk-queries

For a full documentation, please visit the: TAAPI.IO Client Documentation

  • candlesCount added to the addBulkQuery() method as the last parameter
  • added method: getExchangeStructure(exchangeId:String, print:boolean)
  • added method: getExchangeTimeframes(exchangeId:String, print:boolean)
  • bumped CCXT version to: 1.26.44