Jan-15-2019, 02:41 PM
i am working on this article so that i can add a socket to excel. the demo works perfectly, now i want to add to it.
so this opens up ws-feed.pro.coinbase.com so that it can display the attributes for the feed selected (the demo uses BTC-Bitcoin). Now i want to add another moth_ws.py module (called moth_wsL.py)
when i make the changes to moth_wsL.py, nothing appears to happen. can someone give me some tips on how to do this?
here are the changes to moth_wsL.py:
well, somehow i got this running as per the modules with no changes. all i had to do was reload pyxll.
so this opens up ws-feed.pro.coinbase.com so that it can display the attributes for the feed selected (the demo uses BTC-Bitcoin). Now i want to add another moth_ws.py module (called moth_wsL.py)
when i make the changes to moth_wsL.py, nothing appears to happen. can someone give me some tips on how to do this?
here are the changes to moth_wsL.py:
""" PyXLL Examples: Real time data As well as returning static values from functions, PyXLL functions can return special 'RTD' instances that can notify Excel of updates to their value. This could be used for any real time data feed, such as live prices or the status of a service. """ from pyxll import RTD, xl_func, xl_app import threading import logging import json import websocket ws = websocket.create_connection("wss://ws-feed.pro.coinbase.com") ws.send(json.dumps({ "type": "subscribe", "channels": [ { "name": "ticker", "product_ids": ["LTC-USD"] } ] })) #Check contents of result to see if subscription has succeeded result = ws.recv() _log = logging.getLogger(__name__) class GDAXRTDL(RTD): def __init__(self): initial_value = "" super(GDAXRTDL, self).__init__(value=initial_value) self.__running = True self.__thread = threading.Thread(target=self.__thread_func) self.__thread.start() def connect(self): # Called when Excel connects to this RTD instance, which occurs # shortly after an Excel function has returned an RTD object. _log.info("GDAXRTDL Connected") def disconnect(self): # Called when Excel no longer needs the RTD instance. This is # usually because there are no longer any cells that need it # or because Excel is shutting down. self.__running = False _log.info("GDAXRTDL Disconnected") def __thread_func(self): while self.__running: # Setting 'value' on an RTD instance triggers an update in Excel try: result = ws.recv() print(result) except Exception as e: result = e self.value = result @xl_func(": rtd") def gdax_rtdL(): return GDAXRTDL()the original moth_ws.py looks like this:
""" PyXLL Examples: Real time data As well as returning static values from functions, PyXLL functions can return special 'RTD' instances that can notify Excel of updates to their value. This could be used for any real time data feed, such as live prices or the status of a service. """ from pyxll import RTD, xl_func, xl_app import threading import logging import json import websocket ws = websocket.create_connection("wss://ws-feed.gdax.com") ws.send(json.dumps({ "type": "subscribe", "channels": [ { "name": "ticker", "product_ids": ["LTC-USD"] } ] })) #Check contents of result to see if subscription has succeeded result = ws.recv() _log = logging.getLogger(__name__) class GDAXRTDL(RTD): def __init__(self): initial_value = "" super(GDAXRTDL, self).__init__(value=initial_value) self.__running = True self.__thread = threading.Thread(target=self.__thread_func) self.__thread.start() def connect(self): # Called when Excel connects to this RTD instance, which occurs # shortly after an Excel function has returned an RTD object. _log.info("GDAXRTDL Connected") def disconnect(self): # Called when Excel no longer needs the RTD instance. This is # usually because there are no longer any cells that need it # or because Excel is shutting down. self.__running = False _log.info("GDAXRTDL Disconnected") def __thread_func(self): while self.__running: # Setting 'value' on an RTD instance triggers an update in Excel try: result = ws.recv() print(result) except Exception as e: result = e self.value = result @xl_func(": rtd") def gdax_rtdL(): return GDAXRTDL()note that this works perfectly, but when i make changes to pyxll.cfg to add moth_wsL.py, nothing appears to happen. when i am in excel and i type in a cell, i use "=gdax_rtdL()", but i get a #NAME? in the cell which tells me the socket is not working. what am i doing wrong?
well, somehow i got this running as per the modules with no changes. all i had to do was reload pyxll.