Issue with tick data when large number of tokens are subscribed


  • Hi Team,
    I am subscribing to all strike price of bank nifty which tallies to 198 tokens in one websocket connection. I am observing an issue where I am not receiving intermediate ticks for the each strike price because of which there is a discrepancy in the candle data that I am creating at my end. Please find the websocket request for 198 tokens for the current expiry.
    {
    correlationID: "abcde12345",
    action: 1,
    mode: 2,
    exchangeType: 2,
    tokens: [
    "53955",
    "39011",
    "54061",
    "53867",
    "54132",
    "54320",
    "53925",
    "54029",
    "54108",
    "54191",
    "47787",
    "48448",
    "49231",
    "54069",
    "54030",
    "53816",
    "53949",
    "53847",
    "54059",
    "39013",
    "54135",
    "39010",
    "53822",
    "53982",
    "53812",
    "53887",
    "54065",
    "53967",
    "48446",
    "54060",
    "54031",
    "54323",
    "53948",
    "54106",
    "53869",
    "53898",
    "53995",
    "53831",
    "54087",
    "47772",
    "47785",
    "53950",
    "53863",
    "39012",
    "53823",
    "54002",
    "53921",
    "54063",
    "54289",
    "54109",
    "53944",
    "53934",
    "54033",
    "53985",
    "53952",
    "53896",
    "53854",
    "48451",
    "54159",
    "53941",
    "54151",
    "54287",
    "54011",
    "53951",
    "54016",
    "47786",
    "54009",
    "54051",
    "53888",
    "53923",
    "54175",
    "54221",
    "54064",
    "53912",
    "48447",
    "53963",
    "47784",
    "54092",
    "54150",
    "39008",
    "54077",
    "53832",
    "54164",
    "53926",
    "54298",
    "54163",
    "53840",
    "54167",
    "45999",
    "53984",
    "54321",
    "54134",
    "39028",
    "53806",
    "53821",
    "49223",
    "54112",
    "54111",
    "54160",
    "47758",
    "54076",
    "53924",
    "54257",
    "39799",
    "53833",
    "39027",
    "53834",
    "54123",
    "54062",
    "39009",
    "54007",
    "54176",
    "54146",
    "53820",
    "54070",
    "47771",
    "49232",
    "53983",
    "53922",
    "54003",
    "39800",
    "53852",
    "53870",
    "54006",
    "54179",
    "54130",
    "53932",
    "54068",
    "54299",
    "54169",
    "54027",
    "53803",
    "53864",
    "53897",
    "53902",
    "54045",
    "53935",
    "54131",
    "53865",
    "54220",
    "54066",
    "53876",
    "54168",
    "47759",
    "53853",
    "54322",
    "54067",
    "54094",
    "53866",
    "54017",
    "53956",
    "53958",
    "53962",
    "54129",
    "54177",
    "39029",
    "54192",
    "54288",
    "48444",
    "53964",
    "53851",
    "54128",
    "54028",
    "53877",
    "53807",
    "48445",
    "54309",
    "53859",
    "53868",
    "53813",
    "53965",
    "54161",
    "54162",
    "53805",
    "53804",
    "53947",
    "53848",
    "54071",
    "53966",
    "54004",
    "39014",
    "53994",
    "53961",
    "54052",
    "54310",
    "45996",
    "54010",
    "54319",
    "54136",
    "54258",
    "54093",
    "54026",
    "49228",
    "54032",
    "54133",
    "54046",
    "53913",
    "53957",
    ],
    }

    Please note that tick data is working perfectly fine when I subscribe only to Nifty and Bank nifty index tokens.


  • Hello @DevPatel

    There is a limit like @chetansuri as mentioned.
    For each client code maximum 3 parallel sessions are allowed and 1000 token as well.

    Regards,
    SamrtAPI Team


  • @Ananth said in Issue with tick data when large number of tokens are subscribed:

    @Moderator_1

    @Ananth said in Issue with tick data when large number of tokens are subscribed:

    I'm also facing similar issue with feed data, In my case I subscribe to around 200 tokens (Nifty Option Script) and able to get tick data properly.

    But the problem is when I try to create candles out of that data, it dosen't match with angelone candles, There was a slight difference.

    Also there're two timestamps in websocket 2.0. exchange_timestamp & last_traded_timestamp I'm not sure which one to considered while creating candles.

    Though I tried both and none of them was matching with angelone candles

    Note:

    I've already tried Historical API (getCandleData) which is even worse.

    It gives accurate data for older candles Which means if I request for last ten 5 minutes candles the first 9 candles were good but the last candle (latest) was not matching with angelone.

    I absorbed that even angelone takes some time to settle down the candle data.

    F.e
    If the time is 12:00 and you request for 11:55 candle (Nifty Option Script), The received data was inappropriate, But if you request the same at 12:05, 11.55 candle should settled but 12:00 candle will be inappropriate.

    @admin @admin123 @Moderator_1 @Moderator_2 @Moderator_3



  • I'm also facing similar issue with feed data, In my case I subscribe to around 200 tokens (Nifty Option Script) and able to get tick data properly.

    But the problem is when I try to create candles out of that data, it dosen't match with angelone candles, There was a slight difference.

    Also there're two timestamps in websocket 2.0. exchange_timestamp & last_traded_timestamp I'm not sure which one to considered while creating candles.

    Though I tried both and none of them was matching with angelone candles

    Note:

    I've already tried Historical API (getCandleData) which is even worse.

    It gives accurate data for older candles Which means if I request for last ten 5 minutes candles the first 9 candles were good but the last candle (latest) was not matching with angelone.

    I absorbed that even angelone takes some time to settle down the candle data.

    F.e
    If the time is 12:00 and you request for 11:55 candle (Nifty Option Script), The received data was inappropriate, But if you request the same at 12:05, 11.55 candle should settled but 12:00 candle will be inappropriate.


  • @Moderator_1 @Moderator_2 @admin123 Any update on the issue? I am not able to launch my strategy because of this


  • @robin Iam facing same issue daily


  • @nitish-bane sir i am also developing a strategy where I need to select a strike price based on a premium price category. How can i do that ? any idea. Please help…..


  • @DevPatel You need to use historical data or use getCandleData method from sdk.
    getCandleData({
    "exchange": exchange,
    "symboltoken": symboltoken,
    "interval": interval,
    "fromdate": fromdate,
    "todate": todate
    })


  • Iam also facing same issue when i subscribe to 20 + tokens.
    @admin please help.


  • @Moderator_2 I am just using the tick data to create candles. It is working fine for index tokens i.e for Nifty and Bank Nifty candles are matching with angel candles. However when I subscribe to large number of tokens there is delay observed in getting the ticks. I am getting one tick as part of one websocket response. I think websocket should contain data as an array of tokens subscribed.


  • @nitish-bane sir how can i get OHLC data of any timeframe ( i am using ltp request but i think in response i got OHLC of 1 day timeframe) . How can i send request of OHLC dara for any particular timeframe.

    Is there any parameter for timeframe in lpt request ??

    Please help


  • hi @nitish-bane

    Apologies for the delayed response.
    We are trying to reproduce the issue from our end, but we are getting the Websocket response in ms. Will update you asap for the same. Meanwhile kindly reverify on the business logic if any applied at your end is causing th delay.

    Regards,
    SmartAPI Team


  • @nitish-bane @chetansuri @Moderator_1
    Screenshot 2024-04-03 165203.png
    I found this on the forum, and this was like 15 days before from the present day i.e., 3rd April, 2024.


  • @nitish-bane

    Hi, Nitish Bane!
    I really appreciate for sharing this knowledge. This would help me in developing a strategy on my own with this idea.
    Thank you.
     
    Regards,
    Jaideep Siddula


  • Hi @Moderator_1 @Moderator_2 Can you please look into this issue? I beleive websocket only works if we subscribe to less number of tokens. There are delays observed in ticks if we subscribe to more tokens. Please correct me if I am wrong


  • @DevPatel Feed type should be the feed token you receive from authentication response


  • @nitish-bane I tried this code and i got this error
    8fff9ed6-1df0-4d97-bd66-90b50e20d756.jpeg

    Code:

    let { WebSocketV2 } = require('smartapi-javascript');
    var axios = require('axios');

    const speakeasy = require('speakeasy');
    const secretKey = '';

    // Generate TOTP code
    const totpCode = speakeasy.totp({
    secret: secretKey,
    encoding: 'base32',
    });

    var axios = require('axios');
    var data = JSON.stringify({
    "clientcode":"K55544670",
    "password":"3123",
    "totp":${totpCode}
    });

    var config = {
    method: 'post',
    url: 'https://apiconnect.angelbroking.com//rest/auth/angelbroking/user/v1/loginByPassword',

    headers : {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-UserType': 'USER',
    'X-SourceID': 'WEB',
    'X-ClientLocalIP': '192.168.43.238',
    'X-ClientPublicIP': '106.193.147.98',
    'X-MACAddress': ' fe80::87f:98ff:fe5a:f5cb',
    'X-PrivateKey': 'xL9TyAO8'
    },
    data : data
    };

    axios(config)
    .then(function (response) {
    let a=response.data;
    console.log(a.data.feedToken+"\n\n\n")

    console.log(a.data.jwtToken);
    const jwt=a.data.jwtToken
    
    let web_socket = new WebSocketV2({
        jwttoken: jwt, // replace this with your own credentials
        apikey: 'hjdhdhdg',
        clientcode: 'K55544670',
        feedtype: 'order_feed',
    });
    web_socket.connect().then((res) => {
        let json_req = {
            correlationID: 'abcde12345',
            action: 1,
            mode: 2,
            exchangeType: 1,
            tokens: ["99926009", "99926000"]// token for nifty and bank nifty
        };
    
        web_socket.fetchData(json_req);
        web_socket.on('tick', receiveTick);
        function receiveTick(data) { // your code to process tick data
        }
    }
    )
    

    })
    .catch(function (error) {
    console.log(error);
    });


  • @DevPatel Please find the cide below
    let {WebSocketV2} = require('smartapi-javascript');
    let web_socket = new WebSocketV2({
    jwttoken:jwtToken, // replace this with your own credentials
    apikey: apiKey,
    clientcode: clientId,
    feedtype: feedToken,
    });
    web_socket.connect().then((res) => {
    let json_req = {
    correlationID: 'abcde12345',
    action: 1,
    mode: 2,
    exchangeType: 1,
    tokens: ["99926009","99926000"]// token for nifty and bank nifty
    };

        web_socket.fetchData(json_req);
        web_socket.on('tick', receiveTick);
    

    function receiveTick(data) { // your code to process tick data
    }


  • @jaideep-siddula I am developing a strategy where I need to select a strike price based on a premium criteria. There are two ways of doing it. Subscribe to all strike prices of an index to get premum prices or use market data api. I am trying the first way out so that I can develop any strategy in the future that may work on premium chart