Historical data Get method : Result 5 Candle , Node.js method kc.getHistoricalData() 4 Candles

nimesh301
There is difference in result of historical data for minute candle for GET method and kc.getHistoricalData() in node.js library.
The Kite Connect API Javascript client - v3

Get method : Result 5 Candle , Node.js method kc.getHistoricalData() : Result 4 Candle
Date: 11-10-2018
From Time: 15:10:01
To Time: 15:15:00

GET Method: https://api.kite.trade/instruments/historical/12661506/minute?from=2018-10-11+15:10:01&to=2018-10-11+15:15:00

Result: 5 candles
{
"status": "success",
"data": {
"candles": [
[
"2018-10-11T15:10:00+0530",
1090,
1090.15,
1088.55,
1089,
77000
],
[
"2018-10-11T15:11:00+0530",
1089,
1089.2,
1087.1,
1089.2,
98000
],
[
"2018-10-11T15:12:00+0530",
1089.35,
1089.35,
1088.2,
1089.3,
49000
],
[
"2018-10-11T15:13:00+0530",
1089.3,
1090.4,
1088.7,
1090.4,
40000
],
[
"2018-10-11T15:14:00+0530",
1090.4,
1090.4,
1089,
1090,
46000
]
]
}
}


kc.getHistoricalData('12661506', 'minute', '2018-10-11 15:10:01', '2018-10-11 15:15:00').then(function (historicalData) {
debug('historicalData: ', historicalData);
}).catch(function (err) {
debug('err: ',err);
});

Result: 4 Candles (Last candle is missing)

historicalData: [ { date: 2018-10-11T09:40:00.000Z,
open: 1090,
high: 1090.15,
low: 1088.55,
close: 1089,
volume: 77000 },
{ date: 2018-10-11T09:41:00.000Z,
open: 1089,
high: 1089.2,
low: 1087.1,
close: 1089.2,
volume: 98000 },
{ date: 2018-10-11T09:42:00.000Z,
open: 1089.35,
high: 1089.35,
low: 1088.2,
close: 1089.3,
volume: 49000 },
{ date: 2018-10-11T09:43:00.000Z,
open: 1089.3,
high: 1090.4,
low: 1088.7,
close: 1090.4,
volume: 40000 } ]
  • nimesh301
    getHistoricalData() returns incorrect candle data. Problem is in parseHistorical() function on line number 1032.
    function parseHistorical(jsonData, headers) {
    // Return if its an error
    if (jsonData.error_type) return jsonData;

    var results = [];
    for(var i=0; i<jsonData.data.candles.length - 1; i++) { //should not be length-1
    // for(var i=0; i<jsonData.data.candles.length ; i++) { Correct one
    var d = jsonData.data.candles[i];
    results.push({
    "date": new Date(d[0]),
    "open": d[1],
    "high": d[2],
    "low": d[3],
    "close": d[4],
    "volume": d[5]
    });
    }

    return { "data": results };
    }
Sign In or Register to comment.