Tick data using KiteTicker on Flask app

harshtock
Hi,

I am able to get tick data in my python scripts. But, i am trying to get some data displayed on a webpage using Flask for which i require tick data. Cannot understand how to use websocket connection and flask app together.

I tried below, but obviously it doesn't work as it is already mentioned that - it works only on the main thread.

@app.route("/tickpage", methods = ['POST', 'GET'])
def displayOnWeb():

############################ ticker ###########################
kws= KiteTicker(api_key, access_token)
flaskkite = FlaskKiteConnect(app)


def on_ticks(ws, ticks):
fig = getData(ticks)
figJson = json.dumps(fig)
return render_template('index.html', figJson)

def on_connect(ws, response):
# Callback on successful connect.
# Subscribe to a list of instrument_tokens (Reliance EQ).
ws.subscribe(intru_token)

# Set Reliance to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, intru_token)

# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
# kws.on_close = on_close

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
########################### end ticker ########################
This discussion has been closed.