Saving Tick Data in MongoDB

Trying to save tick data in mongo db. I am new to websockets.
from pymongo import MongoClient
client = MongoClient()
db=client.market_data #market_data is my db name
kws = KiteTicker("4515kn****", "pOYgD0hvSfofC********")
db.tick.insertMany(kws.connect()); #tick is my mongo collection name
This does not save my websocket data in my mongo collection. Please note that I have all the websocket callbacks(on_ticks, on_connect, on_close...) defined in my code and I am seeing tick data in my Python console in real time.

Any help from community will be greatly appreciated.

  • sujith
    The connect method doesn't return anything.
    You start receiving ticks in on_tick callback.
    You can go through the API documentation and the client library documentation here.
  • mlearner
    @sujith Thanks for your quick response. Like I mentioned, I have below methods defined already in my code and kws.connect() is returning tick data in Python console for me.

    Just that I am not able to save this tick data in my mongodb collection. It will be great if I can get some help there.
        def on_ticks(ws, ticks):
    logging.debug("Ticks: {}".format(ticks))

    def on_connect(ws, response):

    def on_close(ws, code, reason):

    # Assign the callbacks.
    kws.on_ticks = on_ticks
    kws.on_connect = on_connect
    kws.on_close = on_close
  • sujith
    I am afraid this is outside the scope of the forum. We don't provide coding support. Kite Connect is purely an execution platform.
  • mlearner
    @sujith - Sure, I understand.

    Just updating that I could make db save work successfully. Was not using proper tick data variable to store data.

    We can close this thread.

This discussion has been closed.