It looks like you're new here. If you want to get involved, click one of these buttons!
//This is a class OrderUpdateListenerService implements OnOrderUpdate
@Override
public void onOrderUpdate(Order order) {
int pendingQuantity = Integer.parseInt(order.pendingQuantity);
boolean partialFill = pendingQuantity > 0;
if (partialFill) {
handlePartialFill(order);
}
if (order.status.equals(ORDER_STATUS_COMPLETE)) {
handleOrderCompletion(order);
}
}
public User generateZerodhaSession(String requestToken) {
User user = null;
try {
user = createZerodhaClientAndStoreSecrets(requestToken);
setUpWebSocketConnection(user);
} catch (Throwable t) {
mainExceptionHandler.handleNonInteractiveException("Failed to generate Zerodha session at login.", t);
}
return user;
}
private void setUpWebSocketConnection(User user) throws KiteException {
ticker = new KiteTicker(user.accessToken, user.apiKey);
ticker.setOnOrderUpdateListener(orderUpdateSvc);
// Make sure this is called before calling connect.
ticker.setTryReconnection(true);
//maximum retries and should be greater than 0
ticker.setMaximumRetries(10);
//set maximum retry interval in seconds
ticker.setMaximumRetryInterval(30);
/** connects to com.zerodhatech.com.zerodhatech.ticker server for getting live quotes*/
ticker.connect();
/** You can check, if websocket connection is open or not using the following method.*/
boolean isConnected = ticker.isConnectionOpen();
log.info("Kite WEb socket is connect: {}", isConnected);
}
My code calls setup websocket only on login. However, when i Restart the app, i dont do a login. Login is needed only once a day. I need to ensure that the setup Web socket is called on every restart irrespective of the login.