modeFull is not working in websocket

krtrader
Hi,

I am using Java websocket API to fetch live LTP and other info. I have set the ticker mode to 'modeFull'. But I always get ticks object as 'modeQuote'. Depth variable of ticks object is always null.
Below is my code:
    ArrayList tokens = new ArrayList();
        tokens.add(53287175);
        KiteTicker tickerProvider = new KiteTicker(kiteconnect);
        tickerProvider.setOnConnectedListener(new OnConnect() {
            @Override
            public void onConnected() {
                try {
                    tickerProvider.subscribe(tokens);
                } catch (IOException e) {
                    e.printStackTrace();
}
                } catch (WebSocketException e) {
                    e.printStackTrace();
                }
            }
        });

        tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
            @Override
            public void onDisconnected() {
            }
        });

        tickerProvider.setOnTickerArrivalListener(new OnTick() {
            @Override
            public void onTick(ArrayList ticks) {
                System.out.println(ticks.size());
            }
        });
               tickerProvider.setMode(tokens, KiteTicker.modeFull);
        tickerProvider.connect();

Please let me know if anything wrong in above code. I want ticks as 'modeFull' with full depth.
  • sujith
    Hi @krtrader,
    You need to set mode after subscribing for ticks.
    In the above scenario, you are setting mode before starting the connection.
  • krtrader
    Hi,

    I have changed my code as you suggested but still facing the same error. See the below updated code. Please let me know any change required:

    public void tickerUsage(KiteConnect kiteconnect) throws IOException, WebSocketException {
    try
    {

    ArrayList tokens = new ArrayList();
    tokens.add(53401863L);
    KiteTicker tickerProvider = new KiteTicker(kiteconnect);
    tickerProvider.setOnConnectedListener(new OnConnect() {
    @Override
    public void onConnected() {
    try {
    try {
    tickerProvider.subscribe(tokens);
    } catch (KiteException e) {
    //e.printStackTrace();
    }
    } catch (IOException e) {
    //e.printStackTrace();
    } catch (WebSocketException e) {
    //e.printStackTrace();
    }
    }
    });

    tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
    @Override
    public void onDisconnected() {
    }
    });

    tickerProvider.setOnTickerArrivalListener(new OnTick() {
    @Override
    public void onTick(ArrayList ticks) {
    try {
    if(!ticks.isEmpty())
    System.out.println(ticks.get(0).getMode());
    } catch (Exception e) {
    }
    }
    });

    tickerProvider.connect();
    tickerProvider.setMode(tokens, KiteTicker.modeFull);
    }
    catch(Exception e)
    { }
    }

    PFB the screenshot link of debugging above code:
    https://drive.google.com/open?id=0B6BD7AYy5UwXQWpMME1MMndIRlU
  • sujith
    Hi @krtrader,
    You need to set mode inside onConnected after subscribe.
  • krtrader
    that's working. thanks
  • krtrader
    Hi,
    the above issue is solved but sometime I get below error while connecting to websocket:
    com.neovisionaries.ws.client.WebSocketException: Failed to send an opening handshake request to the server.
    at com.neovisionaries.ws.client.WebSocket.writeHandshake(WebSocket.java:1604)
    at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:1510)
    at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:824)
    at com.rainmatter.ticker.KiteTicker.connect(KiteTicker.java:210)
    at main.java.com.algotrading.api.zerodha.test.GetLiveTicks.tickerUsage(GetLiveTicks.java:175)
    at main.java.com.algotrading.main.MainClassSilverTrading.main(MainClassSilverTrading.java:81)
    Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source)
    at sun.security.ssl.AppOutputStream.write(Unknown Source)
    at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
    at java.io.BufferedOutputStream.flush(Unknown Source)
    at java.io.FilterOutputStream.flush(Unknown Source)
    at com.neovisionaries.ws.client.WebSocket.writeHandshake(WebSocket.java:1599)
    ... 5 more
    Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(Unknown Source)
    ... 13 more


    What could be the reason? I am using the same code pasted in above comment.
Sign In or Register to comment.