Navigation

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

    making websocket callbacks as async

    Python SDK
    python websocket async asynchronous
    2
    3
    70
    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.
    • N
      namanviz last edited by

      Hello,
      so below is the code posted on github for accessing real time data.
      Can anyone please help me in converting this to a async code

      from smartapi import SmartWebSocket

      feed_token=092017047

      FEED_TOKEN="YOUR_FEED_TOKEN"
      CLIENT_CODE="YOUR_CLIENT_CODE"

      token="mcx_fo|224395"

      token="EXCHANGE|TOKEN_SYMBOL" #SAMPLE: nse_cm|2885&nse_cm|1594&nse_cm|11536&nse_cm|3045

      token="mcx_fo|226745&mcx_fo|220822&mcx_fo|227182&mcx_fo|221599"

      task="mw" # mw|sfi|dp

      ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)

      def on_message(ws, message):
      print("Ticks: {}".format(message))

      def on_open(ws):
      print("on open")
      ss.subscribe(task,token)

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

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

      Assign the callbacks.

      ss._on_open = on_open
      ss._on_message = on_message
      ss._on_error = on_error
      ss._on_close = on_close

      ss.connect()

      so i am trying to do something like this:

      async with smartapi_websocket(client_id, api_id, etc....) as ws:
      here I perform other async calls, and probably do not disturb the main thread*

      S 1 Reply Last reply Reply Quote 1
      • S
        Sukhwant280 @namanviz last edited by

        @namanviz Hi Mate, do you have a running code to store the data from websocket mw or dp into a csv or dataframe using python, as i am struggling from last 3 weeks

        thanks in advance
        Sukhwant

        FYi - sorry i don't have a solution for your question

        N 1 Reply Last reply Reply Quote 0
        • N
          namanviz @Sukhwant280 last edited by

          @Sukhwant280 Hi Sukhwant, actually I am just using tick data and previous day data to trade programmatically so I am not storing any thing, what is your requirement exactly? I'll try to assist.

          Best regards.

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