I can't get market data in websocket response

BaiMaoLi
From websocket, I am getting the order history.
But I can't get market data like as quote, price, ...
Only getting order history.
  • sujith
    Can you elaborate on your issue, setup and paste the complete stack trace here?
  • sujith
    It is a heartbeat tick from the server to check if the connection to client is intact or not. You need to send a subscribe message in order to get ticks.
  • BaiMaoLi
    Hello,
    I am using laravel.
    Let me share my code here.
    I am already sending subscribe request.
    I have one question.
    I think, once I send subscribe requet to socket server, then from next, I will get real time update via websocket. right?


    var api_key="{{$api_key}}";
    var access_token="{{$access_token}}"
    var ws = new WebSocket(`wss://ws.kite.trade?api_key=${api_key}&access_token=${access_token}`);
    var instrument_tokens=JSON.parse(`<?php echo json_encode($instrument_tokens); ?>`);
    for(let i=0;i<instrument_tokens.length;i++)
    instrument_tokens[i]=parseInt(instrument_tokens[i]);
    // var message = {"a": "mode", "v": ["full", instrument_tokens]};
    var message = {"a": "subscribe", "v": instrument_tokens};

    ws.addEventListener('open', function (event) {
    ws.send(JSON.stringify(message))
    });

    ws.addEventListener('message', function (event) {
    var data=event.data;
    // if(data.type!="")
    console.log('Message from server ', data);
    });


  • BaiMaoLi
    I just getting order status from socket

    Message from server {"type":"order","id":"","data":{"placed_by":"ZT8813","order_id":"200313002588328","exchange_order_id":"1300000005114990","parent_order_id":null,"status":"COMPLETE","status_message":null,"status_message_raw":null,"order_timestamp":"2020-03-13 12:31:57","exchange_update_timestamp":"2020-03-13 12:31:57","exchange_timestamp":"2020-03-13 11:05:39","variety":"regular","exchange":"NSE","tradingsymbol":"RELIANCE","instrument_token":738561,"order_type":"LIMIT","transaction_type":"SELL","validity":"DAY","product":"MIS","quantity":50,"disclosed_quantity":0,"price":1065,"trigger_price":0,"average_price":1065,"filled_quantity":50,"pending_quantity":0,"cancelled_quantity":0,"market_protection":0,"meta_raw":null,"meta":{},"tag":null,"guid":"01XbVWgX3D7BLCS","account_id":"ZT8813","unfilled_quantity":0,"app_id":1,"checksum":""}}

    That is all I can get via websocket.
  • rakeshr
    @BaiMaoLi
    instrument_tokens[i]=parseInt(instrument_tokens[i]);
    You might not be subscribing instrument_token in correct format.
    Can you echo sent instrument_token and it's data type and paste the response here?
  • BaiMaoLi
    Sure, I will share here.
  • BaiMaoLi
    [121345, 5633, 3350017, 6599681, 5436929, 1793, 1378561, 4583169, 1552897, 912129, 3861249, 4451329, 2615553, 5533185, 7707649, 4617985, 10241, NaN, 2079745, 375553, 6483969, 2995969, 3456257, 25601, 303361, 325121, 40193, 41729, 2332417, 1376769, 54273, 5166593, 60417, 386049, 1436161, 3691009, 67329, 70401, 2031617, NaN, 1510401, 94209, 101121, 5013761, 4267265, 4999937, 3848705, 81153, 4268801, 78081, 85761, 86529, 87297, 579329, 1195009, 1214721, 2912513, 94977, 4589313, 103425, 548865, 98049, 108033, 112129, 134657, 2714625, 7458561, 2911489, 122881, 1790465, 4931841, 126721, 2127617, 97281, 131329, 558337, 3887105, 140033, 7452929, 2931713, 160769, 193793, 2029825, 149249, 2763265, 999937, 5204225, 152321, 320001, 3905025, 3812865, 5420545, 3406081, 3849985, 2187777, 163073, 524545, 5565441, 175361, 177665, …]

    These are instrument tokens.
  • BaiMaoLi
    {a: "subscribe"
    v: [121345, 5633, 3350017, 6599681, 5436, ...]}

    These are message for subscribe request.
  • rakeshr
    @BaiMaoLi
    How many instruments are you subscribing in a single connection?
    Also, can check it's data type?
  • BaiMaoLi
    I am subscribing 500 instruments in single connection
  • BaiMaoLi
    I think datatype is string.
  • sujith
    You need to send as number while subscribing for ticks.
  • BaiMaoLi
    This is from kite api documentation
    message = {"a": "mode", "v": ["ltp", [884737]]};
    ws.send(JSON.stringify(message))

    They are converting array into string.

    var instrument_tokens=JSON.parse(`<?php echo json_encode($instrument_tokens); ?>`);
    for(let i=0;i<instrument_tokens.length;i++)
    instrument_tokens[i]=parseInt(instrument_tokens[i]);

    and I am already making int.
Sign In or Register to comment.