Navigation

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

    Websocket to obtain Order Status

    Python SDK
    6
    23
    347
    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.
    • A
      Ayush Kumar last edited by

      As I understand from the documentation, we can use WebSockets to get information about any orders that get placed on my account (correct me if I'm wrong). If yes, can somewhere share how we can do this using Python SDK? I was able to obtain code only for Websocket streaming and couldn't find Python specific documentation

      A 1 Reply Last reply Reply Quote 0
      • A
        admin @Ayush Kumar last edited by

        Hi @Ayush-Kumar You can use python SDK for the development Kindly go through the below link.
        https://smartapi.angelbroking.com/docs/WebSocketOrderStatus
        https://github.com/angelbroking-github/smartapi-python

        A T W 3 Replies Last reply Reply Quote 0
        • A
          Ayush Kumar @admin last edited by

          @admin I did try it, but I'm not able to obtain any order feed using the python websockets.
          Will it be possible for you to share some working code snippets?

          1 Reply Last reply Reply Quote 0
          • S
            SmartAPI_Angel last edited by

            @Ayush-Kumar said in Websocket to obtain Order Status:

            I'm not able to obtain any order feed using the python websockets.

            @admin
            I am not able to get order status update or not even heartbeat response message for Order status streaming from wss://smartapisocket.angelbroking.com/websocket

            @Ayush-Kumar Are you able to get Order updates streaming from above websocket ?

            T 1 Reply Last reply Reply Quote 0
            • T
              techs @SmartAPI_Angel last edited by

              @SmartAPI_Angel Dear @admin , can you please provide an working example of Order Status python websocket by passing an order id or similar. I see multiple people requesting for the same but you guys don't have proper documentation for the same. Please help everyone by sharing proper working code samples.
              Please don't share any generic link of your https://github.com/angelbroking-github/smartapi-python page.

              A 1 Reply Last reply Reply Quote 0
              • A
                admin @techs last edited by

                HI @techs We will report this to our team.

                S 1 Reply Last reply Reply Quote 0
                • S
                  Surya 1 @admin last edited by

                  @admin

                  Yes some working example would be useful to have. I wanted to spend sometime on this.. but never managed..

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    admin @Surya 1 last edited by

                    Hi @rajanprabu please go through below doc
                    https://smartapi.angelbroking.com/docs/WebSocketOrderStatus

                    S 1 Reply Last reply Reply Quote 0
                    • S
                      Surya 1 @admin last edited by

                      @admin said in Websocket to obtain Order Status:

                      https://smartapi.angelbroking.com/docs/WebSocketOrderStatus

                      Im aware that documentation exist for a long time.. but what we are asking is a working example..

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        Surya 1 @Surya 1 last edited by

                        @techs @Ayush-Kumar @SmartAPI_Angel @admin @Ashok

                        here is what I have quickly tried

                        Try1: using asyncio

                        import websockets 
                        import asyncio 
                        import json
                        
                        with open('/Users/prabu/Angel_Broking/ab.json') as f:
                            data = json.load(f)
                        client_code = data['client_code']
                        api_key = data['api_key']
                        
                        with open('/Users/prabu/Angel_Broking/ab_tokens.json') as f:
                            data = json.load(f)
                        feed_token = str(data['feedToken'])
                        access_token = data['jwtToken']
                        refreshToken = data['refreshToken']
                        
                        ws_request = {
                             "actiontype" : "subscribe",
                             "feedtype" : "order_feed",
                             "jwttoken" : access_token,
                             "clientcode" : client_code,
                             "apikey" : api_key
                        }
                        
                        async def listen(jwttoken, client_id, api_key,ws_request ) :
                            
                            url = "wss://smartapisocket.angelbroking.com/websocket?jwttoken=" + jwttoken + "&&clientcode=" + client_id + "&&apikey=" + api_key
                            async with websockets.connect(url) as ws:
                                # await ws.send(ws_request)
                                
                                msg = await ws.recv()
                                print (msg)
                        
                        asyncio.get_event_loop().run_until_complete(listen(access_token, client_code, api_key, ws_request))
                        

                        Try 2 : using websocket package

                        import websocket 
                        import json
                        
                        
                        with open('/Users/prabu/Angel_Broking/ab.json') as f:
                            data = json.load(f)
                        client_code = data['client_code']
                        api_key = data['api_key']
                        
                        with open('/Users/prabu/Angel_Broking/ab_tokens.json') as f:
                            data = json.load(f)
                        feed_token = str(data['feedToken'])
                        access_token = data['jwtToken']
                        refreshToken = data['refreshToken']
                        
                        ws_request = {
                             "actiontype": "heartbeat",
                             "feedtype": "order_feed",
                             "jwttoken": access_token,
                             "clientcode": client_code,
                             "apikey": api_key
                        }
                        
                        def on_msg(ws, msg):
                            print(msg)
                           
                        def on_connect(ws, response,request=ws_request):
                            print ( response)
                            ws.send(request)
                            
                        def on_close(ws, code, reason):
                            ws.stop()
                        
                        url = "wss://smartapisocket.angelbroking.com/websocket?jwttoken=" + access_token + "&&clientcode=" + client_code + "&&apikey=" + api_key
                        # print (url)
                        
                        ws = websocket.WebSocketApp(url, on_open = on_connect, on_message= on_msg, on_close= on_close)
                        ws.run_forever()
                        

                        But Im not getting any response.. Could you please talk to your team and modify this to be a working example @admin ?

                        I know its not perfect and im missing something.. my aim is to provide some base for other users to try out and improve.

                        S S 2 Replies Last reply Reply Quote 0
                        • S
                          Surya 1 @Surya 1 last edited by

                          @admin

                          why can't you provide order updates via the data websocket like other API providers do. that will make our life so simple..

                          just add one more function like

                          on_order(ws, msg)
                             print ( msg) 
                          

                          this would be the easiest for anyone rather than fiddling with establishing another websocket connects and send heart beat every minute.. pretty inefficient..

                          A 1 Reply Last reply Reply Quote 0
                          • A
                            admin @Surya 1 last edited by

                            HI @rajanprabu ok we report this to the team and update you.

                            S 1 Reply Last reply Reply Quote 0
                            • T
                              techs @admin last edited by

                              Hi @admin and @SmartAPI_Angel ,
                              Sample code should be correct and concise code that your readers can quickly understand and easily reuse with minimal side effects.
                              The link you have shared is just a Websocket Order Status API documentation which doesn't have any working example code.

                              Please share working python code which uses Websocket Order Status API

                              A 1 Reply Last reply Reply Quote 0
                              • A
                                admin @techs last edited by

                                HI @techs @rajanprabu we have passed the requirement to the team to add the working example we will soon make it available to you.

                                S 1 Reply Last reply Reply Quote 0
                                • S
                                  Surya 1 @admin last edited by

                                  @admin

                                  Thanks for the prompt response.. This would be of big help.

                                  1 Reply Last reply Reply Quote 0
                                  • S
                                    Surya 1 @admin last edited by

                                    @admin

                                    Any update on this ? Any example code or ordering updates via data sockets ?

                                    A 1 Reply Last reply Reply Quote 0
                                    • A
                                      admin @Surya 1 last edited by

                                      Hi @rajanprabu As coordinated with the team the example in doc seems to be explanatory to use it. We can connect with you to discuss on this.

                                      S 1 Reply Last reply Reply Quote 0
                                      • S
                                        Surya 1 @admin last edited by

                                        @admin Thanks of the update..

                                        A 1 Reply Last reply Reply Quote 0
                                        • A
                                          admin @Surya 1 last edited by

                                          HI @rajanprabu Let us know when can we connect with you so that we can brief you on the requirement.

                                          S 1 Reply Last reply Reply Quote 0
                                          • S
                                            Surya 1 @admin last edited by

                                            @admin I fixed it myself. Thanks.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post