在 python 中将 blp.live 与 Pyxll Asyncio RTD 结合使用
我是 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)
非常感谢!
I am new to Pyxll and Asyncio and having trouble get the following code going. I kept getting the initial value = 0 on the spreadsheet and it's not refreshing. Could you help and let me know what I did wrong? I followed the example from Pyxll's tutorial here: 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)
Really appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现 xbbg blp.bdp 函数可以做类似的事情。如果你有一个巨大的 bbg 函数来拉动 RT 价格,那么这是一个很好的替代品。 PyXLL 允许您输入股票代码数组,这可以节省大量时间。我希望这可以节省某人一些时间:)
I figured out with xbbg blp.bdp function which does similar thing. This is a good substitute if you have a massive bbg function pulling RT price. PyXLL allows you to input an array of tickers which saves a lot of time. I hope this could save someone some time :)