Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "taapi", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A wrapper and a client for the TAAPI.IO API", | ||
@@ -22,4 +22,5 @@ "main": "index.js", | ||
"express": "^4.17.1", | ||
"lodash": "^4.17.15" | ||
"lodash": "^4.17.15", | ||
"moment": "^2.24.0" | ||
} | ||
} |
@@ -11,2 +11,5 @@ # TAAPI.IO | ||
### Note on exchanges and limits | ||
<i>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.</i> | ||
### Getting started | ||
@@ -31,2 +34,5 @@ | ||
// 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 | ||
@@ -46,4 +52,4 @@ client.getIndicator("rsi", "binance", "BTC/USDT", "1m").then(function(result) { | ||
// Current 200 Moving Average | ||
client.getIndicator("ma", "binance", "BTC/USDT", "1m", {optInTimePeriod: 200}).then(function(result) { | ||
// 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); | ||
@@ -54,4 +60,4 @@ }).catch(function(error){ | ||
// 50 Moving Average 20 minutes ago | ||
client.getIndicator("ma", "bitmex", "BTC/USDT", "1m", {optInTimePeriod: 50}, 20).then(function(result) { | ||
// 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); | ||
@@ -90,3 +96,4 @@ }).catch(function(error){ | ||
'symbol' => 'BTC/USDT', | ||
'interval' => '1h' | ||
'interval' => '1h', | ||
'candlesCount' => 200, // Default 100 | ||
)); | ||
@@ -125,4 +132,7 @@ | ||
// 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", 100).then(function(result) { | ||
exchangeData.getCandles("binance", "BTC/USDT", "1m", 0, 100).then(function(result) { | ||
console.log("Result: ", result); | ||
@@ -134,3 +144,3 @@ }).catch(function(error){ | ||
// Get last candle from Binance for the BTC/USDT 1m | ||
exchangeData.getCandles("binance", "BTC/USDT", "1m", 1).then(function(result) { | ||
exchangeData.getCandles("binance", "BTC/USDT", "1m", 0, 1).then(function(result) { | ||
console.log("Result: ", result); | ||
@@ -142,4 +152,4 @@ }).catch(function(error){ | ||
// Get 1 candle 10 minutes ago from Kucoin for the BTC/USDT 1m | ||
exchangeData.getCandles("kucoin", "BTC/USDT", "1m", 1, 10).then(function(result) { | ||
console.log("Result: ", result); | ||
exchangeData.getCandles("kucoin", "BTC/USDT", "1m", 10).then(function(result) { | ||
console.log("Result: ", result[result.length - 1]); | ||
}).catch(function(error){ | ||
@@ -149,2 +159,9 @@ 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); | ||
}); | ||
``` |
@@ -35,7 +35,11 @@ const chalk = require("chalk"); | ||
*/ | ||
async getIndicator(indicator, exchangeId, symbol, interval, params, backtrack) { | ||
async getIndicator(indicator, exchangeId, symbol, interval, params, backtrack, candlesCount) { | ||
let result = {}; | ||
if(!candlesCount) { | ||
candlesCount = 100; | ||
} | ||
let taapiResult = await this.taapi.getIndicator(indicator, exchangeId, symbol, interval, params, backtrack); | ||
let taapiResult = await this.taapi.getIndicator(indicator, exchangeId, symbol, interval, params, backtrack, candlesCount); | ||
@@ -42,0 +46,0 @@ if(taapiResult && taapiResult.statusCode === 200) { |
const chalk = require("chalk"); | ||
const ccxt = require("ccxt"); | ||
const moment = require("moment"); | ||
const _ = require("lodash"); | ||
@@ -19,4 +20,4 @@ | ||
*/ | ||
async getCandles(exchangeId, symbol, interval, backtrack) { | ||
async getCandles(exchangeId, symbol, interval, backtrack, candlesCount) { | ||
// Default backtracking | ||
@@ -29,2 +30,9 @@ if(backtrack) { | ||
// Default candle count | ||
if(candlesCount) { | ||
candlesCount = parseInt(candlesCount); | ||
} else { | ||
candlesCount = 100; | ||
} | ||
// Setup the integration to the exchange | ||
@@ -35,3 +43,3 @@ const exchangeClass = ccxt[exchangeId]; | ||
// Fetch the candles from the exchange | ||
let candles = await exchange.fetchOHLCV(symbol, interval); | ||
let candles = await exchange.fetchOHLCV(symbol, interval, this.getSince(interval, candlesCount)); | ||
@@ -48,4 +56,5 @@ // Zip up the candle fields in the format that TAAPI.IO takes | ||
//candles = candles.map(candle => _.zipObject(candleFields, candle)); | ||
candles = candles.map(candle => _.zipObject(candleFields, candle)); | ||
// Remove candles from the data set to match the backtrack | ||
@@ -60,2 +69,32 @@ let candlesBacktracked = [].concat(candles); | ||
} | ||
getSince(interval, candlesCount) { | ||
let since = moment().subtract(1 * candlesCount, "days").unix(); | ||
switch(interval) { | ||
case "1m": since = moment().subtract(1 * candlesCount, "minutes").unix(); break; | ||
case "3m": since = moment().subtract(3 * candlesCount, "minutes").unix(); break; | ||
case "5m": since = moment().subtract(5 * candlesCount, "minutes").unix(); break; | ||
case "10m": since = moment().subtract(10 * candlesCount, "minutes").unix(); break; | ||
case "15m": since = moment().subtract(15 * candlesCount, "minutes").unix(); break; | ||
case "30m": since = moment().subtract(30 * candlesCount, "minutes").unix(); break; | ||
case "45m": since = moment().subtract(45 * candlesCount, "minutes").unix(); break; | ||
case "1h": since = moment().subtract(1 * candlesCount, "hours").unix(); break; | ||
case "2h": since = moment().subtract(2 * candlesCount, "hours").unix(); break; | ||
case "3h": since = moment().subtract(3 * candlesCount, "hours").unix(); break; | ||
case "4h": since = moment().subtract(4 * candlesCount, "hours").unix(); break; | ||
case "6h": since = moment().subtract(6 * candlesCount, "hours").unix(); break; | ||
case "8h": since = moment().subtract(8 * candlesCount, "hours").unix(); break; | ||
case "12h": since = moment().subtract(12 * candlesCount, "hours").unix(); break; | ||
case "1d": since = moment().subtract(1 * candlesCount, "days").unix(); break; | ||
case "2d": since = moment().subtract(2 * candlesCount, "days").unix(); break; | ||
case "3d": since = moment().subtract(3 * candlesCount, "days").unix(); break; | ||
case "4d": since = moment().subtract(4 * candlesCount, "days").unix(); break; | ||
case "1w": since = moment().subtract(1 * candlesCount, "weeks").unix(); break; | ||
default: since = moment().subtract(1 * candlesCount, "days").unix(); | ||
} | ||
return since * 1000; | ||
} | ||
} | ||
@@ -62,0 +101,0 @@ |
@@ -66,2 +66,11 @@ const axios = require("axios"); | ||
// Fetch candles count | ||
let candlesCount = 100; | ||
if(args["candlesCount"] && args["candlesCount"] !== "") { | ||
candlesCount = parseInt(args["candlesCount"]); | ||
delete args.candlesCount; | ||
} | ||
// Any remaining args are passed on as optional params | ||
@@ -82,3 +91,3 @@ let params = args; | ||
let response = await taapi.getIndicator(indicator, exchange, symbol, interval, params, backtrack); | ||
let response = await taapi.getIndicator(indicator, exchange, symbol, interval, params, backtrack, candlesCount); | ||
@@ -85,0 +94,0 @@ statusCode = response.statusCode; |
@@ -36,7 +36,7 @@ const chalk = require("chalk"); | ||
*/ | ||
async getCandles(exchangeId, symbol, interval, backtrack) { | ||
async getCandles(exchangeId, symbol, interval, backtrack, candlesCount) { | ||
const exchangeData = new ExchangeData(); | ||
return exchangeData.getCandles(exchangeId, symbol, interval, backtrack); | ||
return exchangeData.getCandles(exchangeId, symbol, interval, backtrack, candlesCount); | ||
} | ||
@@ -54,6 +54,6 @@ | ||
*/ | ||
async getIndicator(indicator, exchangeId, symbol, interval, params, backtrack) { | ||
async getIndicator(indicator, exchangeId, symbol, interval, params, backtrack, candlesCount) { | ||
// Fetch the actual candles from the exchange | ||
let candles = await this.getCandles(exchangeId, symbol, interval, backtrack); | ||
let candles = await this.getCandles(exchangeId, symbol, interval, backtrack, candlesCount); | ||
@@ -79,7 +79,24 @@ // Init extra params if not already done | ||
}).catch(function (error) { | ||
// Something went wrong | ||
if(error.response) { | ||
// Something went wrong | ||
result.statusCode = error.response.status; | ||
result.data = error.response.data; | ||
if(error.response.status) { | ||
result.statusCode = error.response.status; | ||
} else { | ||
result.statusCode = 500; | ||
} | ||
if(error.response.data) { | ||
result.data = error.response.data; | ||
} else { | ||
result.data = { error: { message: "Unknown exchange or server error. If you're running a local server, make sure that's actually running!" }}; | ||
} | ||
} else { | ||
result.statusCode = 500; | ||
result.data = { error: { message: "Unknown exchange or server error. If you're running a local server, make sure that's actually running!" }}; | ||
} | ||
}); | ||
@@ -86,0 +103,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21457
404
159
6
+ Addedmoment@^2.24.0
+ Addedmoment@2.30.1(transitive)