如何检测更改的字典值?
这本词典有 3 个键。关键是价格、尺寸、侧面。数据来自websocket。如何检测相同价格同面但尺寸改变的情况? 如果价格和侧面相同,我想要改变尺寸。 我该怎么办?
from BybitWebsocket import BybitWebsocket
from time import sleep
if __name__ == "__main__":
ws = BybitWebsocket(wsURL="wss://stream.bybit.com/realtime",
api_key="", api_secret=""
)
ws.subscribe_orderBookL2("XRPUSD")
while(1):
orders = ws.get_data("orderBookL2_25.XRPUSD")
if orders != []:
orders2 = orders["update"]
data = {'price':[],'size':[],'side':[]}
for i,val in enumerate(orders2):
data["price"].append(val["price"])
data["size"].append(val["size"])
data["side"].append(val["side"])
print(data)
sleep(0.1)
{'price': ['0.7779'], 'size': [31804], 'side': ['Buy']}
{'price': ['0.7779', '0.7782'], 'size': [31766, 33014], 'side': ['Buy', 'Sell']}
{'price': ['0.7773', '0.7770'], 'size': [27029, 83875], 'side': ['Buy', 'Buy']}
{'price': ['0.7779', '0.7778'], 'size': [71, 148372], 'side': ['Sell', 'Sell']}
{'price': ['0.7777', '0.7770'], 'size': [1515, 85432], 'side': ['Buy', 'Buy']}
{'price': ['0.7778', '0.7765', '0.7782'], 'size': [141913, 1290, 5842], 'side': ['Sell', 'Buy', 'Sell']}
{'price': ['0.7777'], 'size': [24794], 'side': ['Buy']}
for that outcome price 0.7779 size changed 31804 to 33014 , price 0.7777 size changed 1515 to 24794 and so on.
The dictionary has 3 keys . The keys are price,size,side . The data comes from websocket. How can I detect same price same side but changed size ?
if price and side is same I want size changes.
how can I do that ?
from BybitWebsocket import BybitWebsocket
from time import sleep
if __name__ == "__main__":
ws = BybitWebsocket(wsURL="wss://stream.bybit.com/realtime",
api_key="", api_secret=""
)
ws.subscribe_orderBookL2("XRPUSD")
while(1):
orders = ws.get_data("orderBookL2_25.XRPUSD")
if orders != []:
orders2 = orders["update"]
data = {'price':[],'size':[],'side':[]}
for i,val in enumerate(orders2):
data["price"].append(val["price"])
data["size"].append(val["size"])
data["side"].append(val["side"])
print(data)
sleep(0.1)
{'price': ['0.7779'], 'size': [31804], 'side': ['Buy']}
{'price': ['0.7779', '0.7782'], 'size': [31766, 33014], 'side': ['Buy', 'Sell']}
{'price': ['0.7773', '0.7770'], 'size': [27029, 83875], 'side': ['Buy', 'Buy']}
{'price': ['0.7779', '0.7778'], 'size': [71, 148372], 'side': ['Sell', 'Sell']}
{'price': ['0.7777', '0.7770'], 'size': [1515, 85432], 'side': ['Buy', 'Buy']}
{'price': ['0.7778', '0.7765', '0.7782'], 'size': [141913, 1290, 5842], 'side': ['Sell', 'Buy', 'Sell']}
{'price': ['0.7777'], 'size': [24794], 'side': ['Buy']}
for that outcome price 0.7779 size changed 31804 to 33014 , price 0.7777 size changed 1515 to 24794 and so on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不能 100% 确定我理解你的问题,但如果是这样,这可能会有所帮助。我希望我使用的样本数据足够。我使用内联注释来解释:
这会产生:
这里的
StopIteration
刚刚到达生成器的末尾。使用您的代码代替示例数据,这将是:
I not 100% sure I understand your question, but if so this may help. I hope the sample data I used is sufficient. I use comments in-line to explain:
This yields:
The
StopIteration
here is just getting to the end of the generator.With your code in place of sample data, this would be: