User Feedback - WebSocket 2.0 Beta Rollout – Python Language


  • We are excited to announce that WebSocket 2.0 functionality is now available on Python in public beta.

    Endpoint URL: ws://smartapisocket.angelone.in/smart-stream

    Features:

    1. Simplified and consistent request (JSON) and response (binary) structure.
    2. Simplified heartbeat message and response.
    3. Each client code (Angel One trading account id) can have up to three concurrent WebSocket connection
    4. No need to kill the connection and reconnect for subscribing and unsubscribing. The existing open connection can be used to subs and
    5. unsubs in real-time.
    6. Any failure in subscription requests will not impact existing subscriptions and the client will continue to get the feed.
    7. If the client sends an unsubs request for the tokens which are not subscribed then the system will gracefully ignore the request without impacting the feed for currently subscribed tokens.
    8. The total limit/quota of token subscriptions is 1000 per WebSocket session.
      a. For example: If the client subscribes to Infosys NSE with LTP, Quote, and SnapQuote mode then this will be counted as 3 subscriptions.
      b. Duplicate subscriptions to the same token and mode will be gracefully ignored and will not be counted towards the quota.
    9. The client will receive one tick per token_mode combination.
      a. For example: If the client subscribes to Infosys NSE with LTP, Quote, and SnapQuote mode then 1 tick will be published for each mode, containing respective fields.
      b. The recommendation is to subscribe to one mode as a time of a token.

    Thanks everyone for patiently waiting for this.

    Steps to use Python Library for WebSocket Feed:

    1. Clone the following repository -> https://github.com/angel-one/smartapi-python/tree/AMX-3393-Smart-Api-Python-Library
    2. Open the project in your favourite Terminal
    3. git checkout AMX-3393-Smart-Api-Python-Library
    4. Create a virtual environment
    5. Activate the virtual environment
    6. pip install -r requirements.txt
    7. Open the example/smartWebSocketv2Example.py file and change the value of AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN
    8. Subscribe to tokens by changing the value of token_list variable
    9. Run the file example/smartWebSocketv2Example.py
    10. You will get the ticks

    Data fields include OHLC, LTP, Volume, Open interest, 52 week high/low, Upper circuit/Lower circuit, Best 5 bid / ask etc

    last_traded_price
    last_traded_quantity
    average_traded_price
    volume_trade_for_the_day
    total_buy_quantity
    total_sell_quantity
    open_price_of_the_day
    high_price_of_the_day
    low_price_of_the_day
    closed_price
    last_traded_timestamp
    open_interest
    open_interest_change_percentage
    upper_circuit_limit
    lower_circuit_limit
    52_week_high_price
    52_week_low_price
    best_5_buy_data (quantity, price, no of orders)
    best_5_sell_data (quantity, price, no of orders)

    Websocket 2.0 Documentation https://smartapi.angelbroking.com/docs/WebSocket2

    Note: This is still in beta and our goal is to gather any feedback you have on the feature. We’ll be iterating based on your feedback to ensure that we’re heading the right way as we move towards the next steps in supporting WebSockets in other programming languages. With the launch of Websocket 2.0 we have officially withdrawn the support for Websocket 1.0 and any future updates to SmartAPI will not be rolled out for websocket 1.0.


  • @admin
    I am getting ticks in bytes like below. how to decode. not able to decode this anyway

    b'\x02\x05236771\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x001W"\x00\x00\x00\x00\x00\xc8\xea\xb0j\x80\x01\x00\x00\x80\xd4\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x16\xd3\x00\x00\x00\x00\x00\x00\x9dc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x90@\x00\x00\x00\x00\x00(\x89@F\xd2\x00\x00\x00\x00\x00\x00f\xd5\x00\x00\x00\x00\x00\x00\x1a\xd1\x00\x00\x00\x00\x00\x00\xb2\xd4\x00\x00\x00\x00\x00\x00'


  • @admin said in User Feedback - WebSocket 2.0 Beta Rollout – Python Language:

    ws://smartapisocket.angelone.in/smart-stream

    How do I unsub a script and add another


  • @admin
    How do I unsub a script and add another


  • How do I unsub a script and add another


  • Can anyone tell me what modules I have to install. When I run the codes following message occurred from "SmartApi.smartWebSocketV2 import SmartWebSocketV2
    ModuleNotFoundError: No module named 'SmartApi'". And when trying to install SmartApi module following error occurred " ERROR: Command errored out with exit status 1: 'c:\python39\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\JP\AppData\Lo
    cal\Temp\pip-install-bmd4tanj\pycrypto_3cd0936adc594488ab991db614b3c888\setup.py'"'"'; file='"'"'C:\Users\JP\AppData\Local\Temp\pip-install-bmd4tanj\py
    crypto_3cd0936adc594488ab991db614b3c888\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from se
    tuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record '
    C:\Users\JP\AppData\Local\Temp\pip-record-h0mix75_\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\python39\Include\PyCrypto' Check the logs for full command output. "


  • Hi @admin,
    In general, Even if hearbeat issue occurs, pls provide a way to clean up websocket & create new websocket OR some kind of self healing stuff.


  • @admin I am getting following error in smartWebSocketv2Example.py on open
    In on pong function==> b'ping'
    In on pong function==> b'ping'

    Not able to fetch any data.


  • Hi @admin,
    I am also getting the same msg "In on pong function==> b'ping'".
    Any reason why I am not able to fetch data ?


  • @azkhan
    same here,any solution.

    on open
    In on pong function==> b'\x00'
    In on pong function==> b'\x00'
    In on pong function==> b'\x00'
    Attempting to resubscribe/reconnect...
    Close
    Close


  • @zubuco said in User Feedback - WebSocket 2.0 Beta Rollout – Python Language:

    @azkhan
    same here,any solution.

    on open
    In on pong function==> b'\x00'
    In on pong function==> b'\x00'
    In on pong function==> b'\x00'
    Attempting to resubscribe/reconnect...
    Close
    Close
    sometimes its saying NO module as SmartApi


  • @admin @administrators getting error "sent 1011 (unexpected error) keepalive ping timeout; no close frame received" in async websockets python module.

    error while send ping. because websockets module by default send Ping with Random Binary 4 Bytes and we have to send "ping" as ping Payload. so help me to resolve the issue.


  • HI @Ankita @J88913 @azkhan @zubuco The ping pong issue is resolved by one of the early adopter and a loyal SmartAPI client @rajanprabu here - https://smartapi.angelbroking.com/topic/2570/websocket-2-0?_=1667760289934. Thank you @rajanprabu


  • @admin
    still not working


  • @admin
    still not wroking


  • @zubuco Still struck ?


  • @Ashok now wroking


  • Hi @admin,
    I am running websocket V2.0. for every 30 sec's its landing in pong function. I have subscribed only one token while running the below.

    its consistent even with other token. Please look into this.

    27d823f6-c769-4662-a45a-9057695a97b1-image.png


  • @vrkhyd It looks like heartbeat message. you can ignore it.


  • @Ashok ok Thank you.

    Sometimes its printing the same message. multiple times. does it mean no response from server.