我是 Pyxll 和 Asyncio 的新手,无法运行以下代码。我一直在电子表格上得到初始值 = 0 并且它没有刷新。你能帮忙让我知道我做错了什么吗?我在这里遵循了 Pyxll 教程中的示例:https ://www.pyxll.com/docs/userguide/rtd.html#using-the-asyncio-event-loop
from pyxll import RTD, xl_func, xl_app
from xbbg import blp
import asyncio
class AsyncRTDExample(RTD):
def __init__(self, ticker):
super().__init__(value=0)
self.__stopped = False
self.__ticker = ticker
async def connect(self):
while not self.__stopped:
# Yield to the event loop for 1s
await asyncio.sleep(1)
# Update value (which notifies Excel)
async for t in blp.live(self.__ticker, flds = ['LAST_PRICE'], info=['LAST_PRICE']):
self.value = t["LAST_PRICE"]
async def disconnect(self):
self.__stopped = True
@xl_func("string ticker: rtd<float>", recalc_on_open=True)
def async_rtd_price(ticker):
return AsyncRTDExample(ticker)
真的很感激!