status code of opening handshake is not '101 Switching Protocols'. Status line is 403/Forbidden

jimmyabhinav28
I am trying to get ticks for a stock. I do a login, get an access token
When i query to get all Holdings, i get the response, (so access token is valid)
but when i try to subscribe to all ticks of a stock, say SBIN, i get the above error.
I bought the Connect credits (500 credits for a month)

Here is my code:

public void subscribeScrip(String exchange, String tradingSymbol) {
if (exchange == null || exchange.isEmpty()) {
log.error("Exchange not provided while subscribing to scrip");
throw new IllegalArgumentException("Exchange is required");
}
if (tradingSymbol != null && !tradingSymbol.isEmpty()) {


KiteTicker ticker = new KiteTicker(kiteConnect.getApiKey(), kiteConnect.getAccessToken());
kiteTickers.add(ticker);

ticker.setOnConnectedListener(() -> {
System.out.println("Connected to Live market data feed");
try {
Long token = EquityInstrumentUtility.getInstrumentToken(exchange, tradingSymbol); //gets the instrument token
ArrayList tokenList = (ArrayList) List.of(token);
ticker.subscribe(tokenList);
ticker.setMode(tokenList, KiteTicker.modeFull);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (CsvException e) {
throw new RuntimeException(e);
}
// Example: NSE NIFTY 50

});

ticker.setOnDisconnectedListener(() -> log.warn("Disconnected from Live market data feed for scrip {} on exchange {}", tradingSymbol, exchange));

//
ticker.setOnTickerArrivalListener((ArrayList ticks) -> {
for (Tick tick : ticks) {
//scripDataHelper.onTick(tick); //custom logic here
}
});
try {
ticker.connect();
}
catch(Exception e)
{
log.error("Error connecting to KiteTicker: {} Exception is {}", e.getMessage(),e);
throw e;
}



log.info("Subscribed to tick data for scrip: {} on exchange {}", tradingSymbol, exchange);
} else {
log.warn("Attempted to subscribe to an empty or null scrip name.");
}
}
  • jimmyabhinav28
    public void subscribeScrip(String exchange, String tradingSymbol) {

    if (exchange == null || exchange.isEmpty()) {
    log.error("Exchange not provided while subscribing to scrip");
    throw new IllegalArgumentException("Exchange is required");
    }

    if (tradingSymbol != null && !tradingSymbol.isEmpty()) {
    KiteTicker ticker = new KiteTicker(kiteConnect.getApiKey(), kiteConnect.getAccessToken());
    kiteTickers.add(ticker);

    ticker.setOnConnectedListener(() -> {
    System.out.println("Connected to Live market data feed");
    });

    ticker.setOnDisconnectedListener(() -> log.warn("Disconnected from Live market data feed for scrip {} on change {}", tradingSymbol, exchange));

    //
    ticker.setOnTickerArrivalListener((ArrayList ticks) -> {
    for (Tick tick : ticks) {
    //scripDataHelper.onTick(tick); //custom logic here
    }
    });

    try {
    Long token = EquityInstrumentUtility.getInstrumentToken(exchange, tradingSymbol); //gets the instrument token
    ArrayList tokenList = new ArrayList(List.of(token));
    ticker.subscribe(tokenList);
    ticker.setMode(tokenList, KiteTicker.modeFull);
    ticker.connect();
    }
    catch(Exception e)
    {
    log.error("Error connecting to KiteTicker: {} Exception is {}", e.getMessage(),e);
    throw e;
    }
    log.info("Subscribed to tick data for scrip: {} on exchange {}", tradingSymbol, exchange);
    } else {
    log.warn("Attempted to subscribe to an empty or null scrip name.");
    }
    }
Sign In or Register to comment.