Navigation

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

    User Feedback - WebSocket 2.0 Beta Rollout – Python Language

    Python SDK
    0
    45
    2246
    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.
    • W
      whemant @smitshahfo last edited by

      Hi @vrkhyd,

      I am getting data in below format:

      {'subscription_mode': 3, 'exchange_type': 5, 'token': '246083', 'sequence_number': 2414112, 'exchange_timestamp': 1674818721000, 'last_traded_price': 672400, 'subscription_mode_val': 'SNAP_QUOTE', 'last_traded_quantity': 1, 'average_traded_price': 667360, 'volume_trade_for_the_day': 8589, 'total_buy_quantity': 644.0, 'total_sell_quantity': 384.0, 'open_price_of_the_day': 661700, 'high_price_of_the_day': 672700, 'low_price_of_the_day': 661700, 'closed_price': 653300, 'last_traded_timestamp': 1674818717, 'open_interest': 535600, 'open_interest_change_percentage': -4627489742054556454, 'upper_circuit_limit': 679400, 'lower_circuit_limit': 627200, '52_week_high_price': 678100, '52_week_low_price': 599400, 'best_5_buy_data': [{'flag': 0, 'quantity': 7, 'price': 672600, 'no of orders': 6}, {'flag': 0, 'quantity': 14, 'price': 672700, 'no of orders': 12}, {'flag': 0, 'quantity': 10, 'price': 672800, 'no of orders': 10}, {'flag': 0, 'quantity': 7, 'price': 672900, 'no of orders': 6}, {'flag': 0, 'quantity': 29, 'price': 673000, 'no of orders': 21}], 'best_5_sell_data': [{'flag': 1, 'quantity': 35, 'price': 672400, 'no of orders': 11}, {'flag': 1, 'quantity': 23, 'price': 672300, 'no of orders': 3}, {'flag': 1, 'quantity': 1, 'price': 672200, 'no of orders': 1}, {'flag': 1, 'quantity': 2, 'price': 672100, 'no of orders': 2}, {'flag': 1, 'quantity': 12, 'price': 672000, 'no of orders': 4}]}

      Please could explain how you are converting this data in to get 1 min candlestick data? If you could share your code that will be of great help. Thanks.

      W S 2 Replies Last reply Reply Quote 0
      • W
        whemant @whemant last edited by

        Hi @asho and @vrkhyd if anyone of you can provide any help on this? Thanks.

        1 Reply Last reply Reply Quote 0
        • M
          markoma404 @smitshahfo last edited by

          @vrkhyd https://github.com/markov404/AngelOneOptionChainSmartApi
          You can user this script it is getting data about OPTIDX every 3 min then saving and updating. You can change the way of saving , it describes in readme.

          1 Reply Last reply Reply Quote 0
          • J
            Javajp last edited by

            @admin, the instructions for websocket2.0 seems to be too lengthy, Kindly consider to simplify & add sample like we have it in https://github.com/angel-one/smartapi-python🙏

            1 Reply Last reply Reply Quote 0
            • K
              krunal96 last edited by

              Is websocket 2.0 working? As i am getting only ping data(subscribing to Options). @admin @rajanprabu @StocksDeveloper @rjbanna

              A 1 Reply Last reply Reply Quote 1
              • A
                abhinay.j last edited by

                @admin and team and forum members

                Request you to post a final working working Websocket 2.0 code as i am still not able to get any ticks even after doing all the changes discussed above.

                Thank you.

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

                  How to handle ws disconnection?
                  Do we need to Initialize ws again or it handles reconnection?
                  I am getting the following error sometimes

                  ERROR - Handshake status 429 Too Many Requests - goodbye
                  ERROR - error from callback <bound method SmartWebSocketV2._on_close of <SmartWebsocketv2.SmartWebSocketV2 object at 0x000001D5D1637750>>: SmartWebSocketV2._on_close() takes 2 positional arguments but 4 were given
                  ERROR - [WinError 10054] An existing connection was forcibly closed by the remote host - goodbye
                  ERROR - error from callback <bound method SmartWebSocketV2._on_close of <SmartWebsocketv2.SmartWebSocketV2 object at 0x000001D5D1637750>>: SmartWebSocketV2._on_close() takes 2 positional arguments but 4 were given

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

                    @admin
                    This script i not working. No error, nothing happens, It times out. Why ?
                    I have tried many a times today.

                    Code below:

                    from SmartApi.smartWebSocketV2 import SmartWebSocketV2
                    from smartapi import SmartConnect
                    import pyotp

                    obj=SmartConnect(api_key="") # feed app API key.
                    #optional
                    #access_token = "your access token",
                    #refresh_token = "your refresh_token")
                    #login api call
                    token='
                    '

                    Login needs to be done through MPIN now.

                    data = obj.generateSession("","",pyotp.TOTP(token).now())
                    print(data)
                    refreshToken= data['data']['refreshToken']
                    jwt_token = data['data']['jwtToken']

                    	#fetch the feedtoken
                    

                    feedToken=obj.getfeedToken()

                    AUTH_TOKEN = jwt_token
                    API_KEY = ******* #feed app API key
                    CLIENT_CODE = '*******'
                    FEED_TOKEN = feedToken

                    correlation_id = "Testing"
                    action = 1
                    mode = 3

                    token_list = [{"exchangeType": 1, "tokens": ["26009","11536","1594","2885"]}]

                    sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)

                    def on_data(wsapp, message):
                    print("Ticks: {}".format(message))

                    def on_open(wsapp):
                    print("on open")

                    sws.subscribe(correlation_id, mode, token_list)
                    

                    def on_error(wsapp, error):
                    print(error)

                    def on_close(wsapp):
                    print("Close")

                    Assign the callbacks.

                    sws.on_open = on_open
                    sws.on_data = on_data
                    sws.on_error = on_error
                    sws.on_close = on_close

                    sws.connect()


                    Rsult:

                    on open

                    J 1 Reply Last reply Reply Quote 0
                    • D
                      DIYD57519 @J88913 last edited by

                      @J88913 dont install SmartApi. download and keep it in the same folder as program

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

                        Hi @Javajp @vishant @whemant @Kiran @Narendra_Javvadi @vrkhyd @zubuco @N399438

                        We are excited to announce the release of updated SmartAPI libraries that now fully support WebSocket 2.0, further enhancing your trading experience. The latest versions of the SmartAPI Python SDK (1.3.4), SmartAPI Java SDK (2.1.0) and the SmartAPI Node.js Library (1.0.15) incorporate WebSocket 2.0 implementation, ensuring faster market data updates, reduced latency, and improved overall performance.

                        https://smartapi.angelbroking.com/topic/3660/upgraded-smartapi-libraries-to-support-websocket-2-0-python-java-sdk-and-node-js-library

                        1 Reply Last reply Reply Quote 0
                        • D
                          dharm @smitshahfo last edited by

                          @vrkhyd how can you get the live data?
                          I am facing the same issue

                          1 Reply Last reply Reply Quote 1
                          • S
                            smitshahfo @whemant last edited by

                            @whemant Hi,
                            send a mail to vemula.ramkishore@gmail.com

                            1 Reply Last reply Reply Quote 0
                            • D
                              dharm @Ankita last edited by

                              @Ankita do you get any solution on this issue?
                              If Yes so help me

                              L 1 Reply Last reply Reply Quote 0
                              • L
                                Linux Smiths @dharm last edited by

                                @dharm change the function as following

                                @staticmethod
                                def _parse_token_value(binary_packet):
                                    token = ""
                                    binary_packet = binary_packet.decode("UTF-8")
                                    for i in range(len(binary_packet)):
                                        if binary_packet[i] == '\x00':
                                            return token
                                        token += str(binary_packet[i])
                                    return token
                                
                                1 Reply Last reply Reply Quote 0
                                • L
                                  Linux Smiths last edited by

                                  What is total_buy_quantity and total_sell_quantity?
                                  When are they different? I mean whatever is bought is sold as well. Thanks.

                                  L 1 Reply Last reply Reply Quote 0
                                  • L
                                    Linux Smiths @Linux Smiths last edited by

                                    nvm, I gather that this is the amount of pending buy and sell orders at the Exchange.

                                    1 Reply Last reply Reply Quote 0
                                    • A
                                      ashigro @sathyaraj last edited by

                                      @sathyaraj
                                      We can fix this error by updating _on_close method with additional arguments in SmartWebSocketV2.py file.

                                      def _on_close(self, wsapp**, close_status_code, close_msg**):

                                      <Error: SmartWebSocketV2._on_close() takes 2 positional arguments but 4 were given>
                                      This error is thrown because on_close method of websocket class takes multiple arguments which are missing in SmartWebSocket library. Example code:
                                      https://websocket-client.readthedocs.io/en/latest/examples.html

                                      1 Reply Last reply Reply Quote 0
                                      • J
                                        jaideep siddula @DIYD57519 last edited by

                                        @DIYD57519 Im no getting on open. Instead, I'm getting "attempting to resubscibe/reconnect". Any help is appreciated.
                                        Thanks in advance

                                        D 2 Replies Last reply Reply Quote 1
                                        • D
                                          DiljotSingh11 @jaideep siddula last edited by

                                          Hi @jaideep-siddula , I'm also having the same issue, have you found the solution?

                                          1 Reply Last reply Reply Quote 1
                                          • D
                                            DiljotSingh11 @jaideep siddula last edited by

                                            @jaideep-siddula @DIYD57519, I'm also getting "attempting to resubscibe/reconnect", is there any solution, as I've drilled a bit and got Handshake status 404 not found.

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