Nifty exchange timestamp

wtdmarketing
Hi,

I am using node.js client library and normally for every other symbol I am getting "timestamp" data properly but for NIFTY (Instrument = 256265), It gives me 1970 date.

{ tradable: false,
mode: 'full',
instrument_token: 256265,
last_price: 12099.3,
ohlc: { high: 12132.45, low: 12063, open: 12110.2, close: 12073.75 },
change: 0.21161610932808178,
timestamp: 1970-01-19T05:25:52.669Z }

Can you please advise how Can I get actual exchange tick time?
  • wtdmarketing
    Can anyone from Zerodha answer my query here?
  • rakeshr
    @wtdmarketing
    Can you let us know, which API call you are making?Are youmaking OHLC API call?
  • wtdmarketing
    Here is my code, I am using Node.js client library.

    function Setup_Ticker()
    {
    ticker = new KiteTicker({
    "api_key": api_key,
    "access_token": access_token
    });

    ticker.autoReconnect(true, 20, 5);
    ticker.connect();
    ticker.on("ticks", onTicks);
    ticker.on("connect", subscribe);
    ticker.on("noreconnect", noReconnect);
    }

    function subscribe()
    {
    ticker.subscribe([256265]);
    ticker.setMode(ticker.modeFull, [256265]);
    }

    function onTicks(ticks)
    {
    console.log(ticks);
    }
    And this gives me output as stated in post #1 here. I am not getting exchange timestamp for the tick.
  • wtdmarketing
    Hi,

    I found the issue, It's in the Ticker library (node.js version).

    https://github.com/zerodhatech/kiteconnectjs/blob/kite3/lib/ticker.js

    Line #545
    if (timestamp) tick.timestamp = new Date(timestamp);
    Javascript Date object requires milliseconds as input, so it should be:
    if (timestamp) tick.timestamp = new Date(timestamp * 1000);
    Hope this helps. Looking forward for updated library.
  • sujith
    I think you are using kite3 branch. You need to use the master branch or refer to the release page.
  • wtdmarketing
    Not sure which brach it uses but I installed it using
    npm install kiteconnect

    The github link I posted above, I got from your documentation page:
    https://kite.trade/docs/connect/v3/#libraries-and-resources
  • rakeshr
    @wtdmarketing
    We just installed fresh kiteconnect node.js client using npm install kiteconnect and tested your above code, timestamp returned to us is current_timestamp.Check below response:
    [ { tradable: false,
    mode: 'full',
    instrument_token: 256265,
    last_price: 12033.5,
    ohlc: { high: 12081.2, low: 11998.75, open: 12071.25, close: 12043.2 },
    change: -0.08054337717550757,
    timestamp: 2019-12-05T09:45:07.000Z } ]
    You might be using older version of client.Can you do npm show kiteconnect version and let us know the version, you are using?
  • wtdmarketing
    Hi,

    Is there any change from your side since around 26th Jan 2020? I think there is something wrong with the exchange timestamp that I receive in nifty quote around that date. Can you please confirm?
  • wtdmarketing
    Please check attached screenshot, it's using node.js library. Please check/compare the data (specially timestamp) with actual candles at https://kite.zerodha.com/chart/ext/tvc/INDICES/NIFTY 50/256265





  • wtdmarketing
    Hello !!

    Any updates? This is causing me lots of issue and loss as well.
  • rakeshr
    @wtdmarketing
    We didn't get your query clearly. Are you using Websocket streaming to generate a minute candle at your end?
    We relay WebSocket data as we get from exchange.
  • wtdmarketing
    Yes, I am using websocket data to generate minute candle at myend (runtime) using node.js client library provided by zerodha.

    It looks like "timestamp" field is not representing exchange timestamp, may be it's using your server's timestamp instead of exchanges? possible?
  • sujith
    We just relay whatever we get from the exchange.
  • sujith
    We don't modify any of the fields.
  • wtdmarketing
    Then how come data I am seeing in websocket is different then chart at https://kite.zerodha.com/chart/ext/tvc/INDICES/NIFTY 50/256265

    Please refer to my earlier post with screenshot.

    Is there anyway we can talk over the phone so I can explain it better?
  • sujith
    The candle data generated using the live market data provided via the internet will not match when the same data is dumped on two machines. It will be near but not the same. You can refer to this thread.

    We use the system time while creating candles and not the tick timestamp.
    You can know more here.
  • wtdmarketing
    The candle data generated using the live market data provided via the internet will not match when the same data is dumped on two machines.
    --> I don't think this is true statement. If you use source timestamp, candles generated anywhere in the world.. any different machines will be the always same.

    We use the system time while creating candles and not the tick timestamp.
    --> Again, I don't think this is true. If you guys are using your server's system time to generate candles then how come LIVE chart on your site (when market is open) is exactly matching with NSE website data? Do you think there is no (not even microseconds) delay between NSE servers and yours?

    And moreover, this problem started only since last few days, it was perfect before then.

    Is there any way I can talk to your technical team over the phone? This is really critical for me.
  • nikhilR
    Hi wtdmarketing,

    The ticks broadcasted from us for API clients as well as the kite frontend sends the latest tick for an instrument in a broadcast cycle (sub-second). You can think of it as a snapshot for that cycle.

    It is not possible to recreate the same candles on charts as the charts consume the raw stream from the exchange. Do note that exchanges themselves don't stream all ticks to everyone and packet losses are to be expected over the internet even if one is using tick-by-tick stream. So, the charts themselves are mostly correct, not absolutely correct. This is one the reasons why charts across different platforms mostly match but not exactly.
    Nithin wrote about this here.

    Regarding the timestamp used for forming charts, we use the exchange timestamp and if needed (same timestamp cases) we maintain ordering using system time.

    A way to generate more accurate candles using the API would be to aggregate the candles using OHLC data from the tick. This could still miss open and close as the aggregates depend on ordering in the internal stream not the one that is broadcasted, but the high and low will always match.

    Hope things are clear. Let us know if anything isn't.
  • ramyasri
    I think you are using kite3 branch. You need to use the master branch or refer to the release page.
  • Shivu999
    @ramyasri,

    Could you please help to explain the difference between kite3 branch and master branch.

    Are you able to build candles at your end accurately, I mean Open and Close are exactly matching with Kite?

    Thanks in advance for your quick response.
  • wtdmarketing
    @ramyasri - I have installed kite client library using "npm install kiteconnect", I don't know where it's pulling source from.
  • sujith
    You need to check the version of the library. All the releases are listed here. Every release is pushed to npm repo.
  • wtdmarketing
    npm show kiteconnect version
    - 3.1.0
  • sujith
    This is the new version of kiteconnectjs. I have asked the concerned team to update the releases page on GitHub as well.
Sign In or Register to comment.