web socket giving 1Bit data only

gautam_s60
Hi,
for me if i send request like
var message = {"a": "subscribe", "v": [53703431]};
i am getting 48Bits
but is i am send request
var message = {"a": "mode", "v": ["full", [53703431]]};
only getting 1Bit only with no data.
please help.
Tagged:
  • raminde
    use both.
  • gautam_s60
    Nah, not working
  • sujith
    Are you sure you are doing this after getting connected?
    If you send a message before connecting then it won't reach server right?
    You need to listen to on_connected callback and then subscribe after that you can set mode. If you directly set mode it won't automatically subscribe.
  • gautam_s60
    Same code and sending requests by one request in comment and one as code works and now reversing comment not working!
  • sujith
    Can you paste your complete code here?
  • gautam_s60
    gautam_s60 edited May 2018
    @sujith here is my test code
    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">
    c();
    function c () {
    var tok3="wss://ws.kite.trade?api_key=xxxxxx&access_token=xxxxxxxxx";
    var ws = new WebSocket(tok3);
    ws.binaryType = 'arraybuffer';
    ws.onopen = function(evt)
    {
    //var message = {"a": "subscribe", "v": [10154498]};
    var message = {"a": "mode", "v": ["full", [10154498]]};
    ws.send(JSON.stringify(message));
    };
    ws.onclose = function () {
    setTimeout(function () {
    // Connection has closed so try to reconnect every 10 seconds.
    c();
    }, 10*1000);

    };

    ws.onerror = function(evt)
    {
    document.write("error");
    };
    ws.onmessage = function(evt)
    {
    var received_msg = evt.data;
    document.getElementById('FOR').innerHTML="CRUDEOILM16AUGFUT"
    var buffer1 = received_msg;
    var buffer2 = buffer1.slice(0,168);
    var dataview = new DataView(buffer2);
    var ints = buffer2.byteLength / 4;
    document.getElementById('INSTRUMENT').innerHTML=dataview.getInt32(1 * 4)
    document.getElementById('LTP').innerHTML=dataview.getInt32(2 * 4)/100
    document.getElementById('LTQ').innerHTML=dataview.getInt32(3 * 4)
    document.getElementById('ATP').innerHTML=dataview.getInt32(4 * 4)/100
    document.getElementById('VOLUME').innerHTML=dataview.getInt32(5 * 4)
    document.getElementById('TBQ').innerHTML=dataview.getInt32(6 * 4)
    document.getElementById('TSQ').innerHTML=dataview.getInt32(7 * 4)
    document.getElementById('OPEN').innerHTML=dataview.getInt32(8 * 4)/100
    document.getElementById('HIGH').innerHTML=dataview.getInt32(9 * 4)/100
    document.getElementById('LOW').innerHTML=dataview.getInt32(10 * 4)/100
    document.getElementById('CLOSE').innerHTML=dataview.getInt32(11 * 4)/100
    document.getElementById('BQ1').innerHTML=dataview.getInt32(12 * 4)
    document.getElementById('BP1').innerHTML=dataview.getInt32(13 * 4)/100
    document.getElementById('BQ2').innerHTML=dataview.getInt32(15 * 4)
    document.getElementById('BP2').innerHTML=dataview.getInt32(16 * 4)/100
    document.getElementById('BQ3').innerHTML=dataview.getInt32(18 * 4)
    document.getElementById('BP3').innerHTML=dataview.getInt32(19 * 4)/100
    document.getElementById('BQ4').innerHTML=dataview.getInt32(21 * 4)
    document.getElementById('BP4').innerHTML=dataview.getInt32(22 * 4)/100
    document.getElementById('BQ5').innerHTML=dataview.getInt32(24 * 4)
    document.getElementById('BP5').innerHTML=dataview.getInt32(25 * 4)/100
    document.getElementById('OQ1').innerHTML=dataview.getInt32(27 * 4)
    document.getElementById('OP1').innerHTML=dataview.getInt32(28 * 4)/100
    document.getElementById('OQ2').innerHTML=dataview.getInt32(30 * 4)
    document.getElementById('OP2').innerHTML=dataview.getInt32(31 * 4)/100
    document.getElementById('OQ3').innerHTML=dataview.getInt32(33 * 4)
    document.getElementById('OP3').innerHTML=dataview.getInt32(34 * 4)/100
    document.getElementById('OQ4').innerHTML=dataview.getInt32(36 * 4)
    document.getElementById('OP4').innerHTML=dataview.getInt32(37 * 4)/100
    document.getElementById('OQ5').innerHTML=dataview.getInt32(39 * 4)
    document.getElementById('OP5').innerHTML=dataview.getInt32(40 * 4)/100
    };
    };
    </script>
    </head>
    <body>
    <div ID="FOR" ></div>
    <table>
    <tr>
    <th>INSTRUMENT</th>
    <th>LTP</th>
    <th>LTQ</th>
    <th>ATP</th>
    <th>VOLUME</th>
    <th>TBQ</th>
    <th>TSQ</th>
    <th>OPEN</th>
    <th>HIGH</th>
    <th>LOW</th>
    <th>CLOSE</th>
    </tr>
    <tr>
    <td><div id="INSTRUMENT" ></div></td>
    <td><div id="LTP" ></div></td>
    <td><div id="LTQ" ></div></td>
    <td><div id="ATP" ></div></td>
    <td><div id="VOLUME" ></div></td>
    <td><div id="TBQ" ></div></td>
    <td><div id="TSQ" ></div></td>
    <td><div id="OPEN" ></div></td>
    <td><div id="HIGH" ></div></td>
    <td><div id="LOW" ></div></td>
    <td><div id="CLOSE" ></div></td>
    </tr>
    </table>

    <table>
    <tr>
    <th>BID_PRICE</th>
    <th>BID_QTY</th>
    <th>OFR_PRICE</th>
    <th>OFR_QTY</th>


    </tr>
    <tr>
    <td><div id="BP1" ></div></td>
    <td><div id="BQ1" ></div></td>
    <td><div id="OP1" ></div></td>
    <td><div id="OQ1" ></div></td>
    </tr>
    <tr>
    <td><div id="BP2" ></div></td>
    <td><div id="BQ2" ></div></td>
    <td><div id="OP2" ></div></td>
    <td><div id="OQ2" ></div></td>
    </tr>
    <tr>
    <td><div id="BP3" ></div></td>
    <td><div id="BQ3" ></div></td>
    <td><div id="OP3" ></div></td>
    <td><div id="OQ3" ></div></td>
    </tr>
    <tr>
    <td><div id="BP4" ></div></td>
    <td><div id="BQ4" ></div></td>
    <td><div id="OP4" ></div></td>
    <td><div id="OQ4" ></div></td>
    </tr>
    <tr>
    <td><div id="BP5" ></div></td>
    <td><div id="BQ5" ></div></td>
    <td><div id="OP5" ></div></td>
    <td><div id="OQ5" ></div></td>
    </tr>
    </table>
    </body>
    </html>">
  • tonystark
    tonystark edited May 2018
    @gautam_s60 I'm getting ticks if I do:
    var message = {"a": "subscribe", "v": [10154498]};
    ws.send(JSON.stringify(message));
    message = {"a": "mode", "v": ["full", [10154498]]};
    ws.send(JSON.stringify(message));
    Also, your tick parsing is wrong. You are not considering first two fields in the tick - packet count and packet length. Refer the documentation to understand this in detail.

    Or you can use the JS library which has implemented all this along with reconnection mechanisms.
  • gautam_s60
    but why it is not returning data if i put only
    message = {"a": "mode", "v": ["full", [10154498]]};
    ws.send(JSON.stringify(message));
  • sujith
    sujith edited June 2018
    You can't set mode without subscribing for the data.
This discussion has been closed.