Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Websocket order status in JavaScript

    General Discussion
    0
    2
    17
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jayesh_sapkale last edited by

      Dear Smart-API team,

      Thanks for all your effort in providing this API service. Unfortunately, I am facing some difficulties regarding the "smart-order-websocket". I am trying to connect to the order status websocket in JavaScript using a WebSocket with a JWT token. My Smart-Stream WebSocket is already connected, but when I attempt to connect to the "smart-order-websocket", it throws an error.

      I have tried several approaches to connect to the WebSocket using JavaScript, but all of them result in an error. Please guide me on the correct way to connect to the WebSocket with JavaScript.

      Trial-Error method

      new WebSocket("wss://tns.angelone.in/smart-order-update?Authorization=Bearer "+encodeURIComponent("JWT-Token-after-login-via-totp"));
      
      new WebSocket("wss://tns.angelone.in/smart-order-update?Authorization=Bearer JWT-Token-after-login-via-totp");
      
      new WebSocket("wss://tns.angelone.in/smart-order-update?Authorization=JWT-Token-after-login-via-totp");
      
      new WebSocket("wss://tns.angelone.in/smart-order-updateJWT-Token-after-login-via-totp");
      

      Is there any other way to connect "smart-order-websocket", or do I need to pass any extra parameters other than jwt-token?

      charlotteemma4 1 Reply Last reply Reply Quote 1
      • charlotteemma4
        charlotteemma4 @jayesh_sapkale last edited by

        @jayesh_sapkale
        /* Order Websocket */
        String userClientId = "<clientId>";
        User userGenerateSession = smartConnect.generateSession("<clientId>", "<password>", "<totp>");
        smartConnect.setAccessToken(userGenerateSession.getAccessToken());
        smartConnect.setUserId(userGenerateSession.getUserId());
        String accessToken = userGenerateSession.getAccessToken();

        examples.orderUpdateUsage(accessToken);
        
        /**
         * Order update websocket
         *
         * To retrieve order update websocket data
         * @param accessToken
         */
        public void orderUpdateUsage(String accessToken){
                OrderUpdateWebsocket orderUpdateWebsocket = new OrderUpdateWebsocket(accessToken, new OrderUpdateListner() {
        /**
         * Check if the websocket is connected or not
         */
        @Override
        public void onConnected() {
            
            log.info("order update websocket connected");
            
        }
        
        /**
         * Handle the onDisconnected event
         */
        @Override
        public void onDisconnected() {
            
            log.info("order update websocket disconnected");
            
        }
        
        /**
         * Handle the onError event
         * @param error
         */
        @Override
        public void onError(SmartStreamError error) {
            
            log.info("on error event");
            
        }
        
        /**
         * Handle the onPong event
         */
        @Override
        public void onPong() {
            
            log.info("or pong event");
            
        }
        
        /**
         * Handle the onOrderUpdate event
         * @param data
         */
        @Override
        public void onOrderUpdate(String data) {
            
            log.info("order update data {} ",data);
                
         }});
                
        }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post