getting started example #38
Replies: 5 comments 1 reply
-
I've converted this to a disucssion as it's not strictly a problem with xlOil! Have you looked at
|
Beta Was this translation helpful? Give feedback.
-
The above is only a simplified example. The fetch method name might be confusing.
Every time a price is received a complex algo is called. It all happens in the main loop which is supposed to run forever. |
Beta Was this translation helpful? Give feedback.
-
I think this can be a good starting point to integrate xlOil with CCXT ( and my code)without too much changes.
|
Beta Was this translation helpful? Give feedback.
-
I don't think you need to use global prices here (they're a bit un-Excel like as Excel functions generally don't have hidden state). You also don't need to explicitly do the asyncio.gather - xlOil is managing the asyncio event loop, you just need to add tasks to it, so I think the code below is enough. Where you might want globals is to ensure you only have one connection object, i.e. one import xloil as xlo
import asyncio
class fake_ws:
def __init__(self, name, x_sec):
self.__stopped = False
self.name = name
self.x_sec = x_sec
self.binance_pr = 1 # Start binance connection here
self.ccxt_pr = 1 # Start ccxt connection here
async def binance_get_pr(self): # simulating a ws connection
while not self.__stopped:
self.binance_pr += 1
yield self.binance_pr
await asyncio.sleep(self.x_sec)
async def ccxt_get_pr(self):
while not self.__stopped:
self.ccxt_pr += 2
yield self.ccxt_pr
await asyncio.sleep(self.x_sec)
@xlo.func
async def Py_binance_pr(sec=5):
conn = fake_ws('ws_binance', 2)
while True:
yield conn.binance_get_pr()
await asyncio.sleep(sec)
@xlo.func
async def Py_ccxt_pr(sec=5):
conn = fake_ws('ws_ccxt', 2)
while True:
yield ccxt_get_pr()
await asyncio.sleep(sec) |
Beta Was this translation helpful? Give feedback.
-
My mistake, you need to use an @xlo.func
async def Py_binance_pr(sec=5):
conn = fake_ws('ws_binance', 2)
async for price in conn.binance_get_pr():
yield price
await asyncio.sleep(sec) And similarly for Py_ccxt_pr |
Beta Was this translation helpful? Give feedback.
-
@cunnane, tx for helping me getting up and running with xloil
this is my starting point ( a simplified version of ccxt recommended usage ) and my goal is to use xloil to write
binance_pr
andccxt_pr
to excel every 10 seconds.any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions