is this correct ?

ayyaz
ayyaz edited February 2018 in API clients
kws = WebSocket(currentAcctTrader.apikey, currentAcctTrader.acess_token,currentAcctTrader.userid)


def on_ticks(ws, ticks):
# Callback to receive ticks.
logging.debug("Ticks: {}".format(ticks))


def on_connect(ws):
# Callback on successful connect.
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
print ("on_connect")
ws.subscribe([738561, 5633])

# Set RELIANCE to tick in `full` mode.
# ws.set_mode(ws.MODE_FULL, [738561])

def set_pid_file(stockName):
pidfilepath = "/var/run/juststocks/price/"+stockName+".pid"
if os.path.exists(pidfilepath):
print("Cant start please run stop")
sys.exit(1)
pid = str(os.getpid())
f = open(pidfilepath, 'w+')
f.write(pid)
f.close()


set_pid_file("pricer")
# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
I was not able to import ticker , so i changed it to webSockets
Sign In or Register to comment.