It looks like you're new here. If you want to get involved, click one of these buttons!
import xlwings as xw
wb = xw.Book('tick data threaded.xlsx')
sht = wb.sheets('Sheet1')
sht.range('A1').value="Instrument Token"
sht.range('B1').value="LTP"
def on_ticks(ws, ticks):
logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response):
ws.subscribe([738561, 5633])
ws.set_mode(ws.MODE_FULL, [738561, 5633])
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect(threaded=True)
while True:
def on_ticks(ws, ticks):
thread_data(ticks)
def thread_data(ticks):
row = 2
for data in ticks:
sht.range('A'+str(row)).value=data['instrument_token']
sht.range('B'+str(row)).value=data['last_price']
row = row + 1
kws.on_ticks=on_ticks
Please point out where I'm going wrong.
win32com.client
anywhere?If yes, you need to call
CoInitialize()
. Have a look at this article.I am facing below errors.
pywintypes.com_error: (-2147417842, 'The application called an interface that was marshalled for a different thread.', None, None)
builtins.AttributeError: 'NoneType' object has no attribute 'append'
from pprint import pprint
import pdb
import pandas as pd
import logging
from kiteconnect import KiteTicker
import time
import datetime
import pythoncom
import win32com.client as client
wb = xw.Book('option.xlsx')
sht = wb.sheets['sheet1']
row=1
logging.basicConfig(level=logging.DEBUG)
kws = KiteTicker()
def on_ticks(ws, ticks):
logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response):
ws.subscribe([55962887])
ws.set_mode(ws.MODE_FULL, [55962887])
def on_close(ws, code, reason):
ws.stop()
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.connect(threaded=True)
while True:
def on_ticks(ws, ticks):
pythoncom.CoInitialize()
helper_method(ticks)
def helper_method(ticks):
pythoncom.CoInitialize()
global row
try:
for company_data in ticks:
sht.range('G4').value=company_data['last_price']
print(row)
row=row+1
except Exception as e:
raise e
kws.on_ticks=on_ticks
def on_ticks(ws, ticks):
_thread.start_new_thread(store_ticks, (ticks,))
def store_ticks(ticks):
# do Data store activity without endless loop
pls post code it is not working for me
if(timecheck.during_NSEExchangetime() == True):
#logging.info('New ticks received %s', ticks)
logging.info('New ticks received')
try:
_thread.start_new_thread(store_ticks, (ticks,))
except:
logging.info('Exception while creating new thread...')
else:
logging.info('Not during non trading hours...')
......
def store_ticks(ticks):
#logging.info('New ticks received inside store_ticks function %s', ticks)
for tick in ticks:
# while loop followed.... for storing the ticks