Python 如何在达到条件时退出web套接字并返回到代码
我试图在满足条件时退出WebSocket。我找不到办法来做这件事。我尝试过表格,但我没有得到它们。在这些情况下可以做些什么?一旦它符合我的条件,我想继续代码 当它满足条件时,我喜欢去我放print123的地方Python 如何在达到条件时退出web套接字并返回到代码,python,websocket,binance,Python,Websocket,Binance,我试图在满足条件时退出WebSocket。我找不到办法来做这件事。我尝试过表格,但我没有得到它们。在这些情况下可以做些什么?一旦它符合我的条件,我想继续代码 当它满足条件时,我喜欢去我放print123的地方 #!/usr/bin/env python # -*- coding: utf-8 -*- # # Versión: python-binance==0.7.9 # https://python-binance.readthedocs.io/en/latest/index.html # i
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Versión: python-binance==0.7.9
# https://python-binance.readthedocs.io/en/latest/index.html
#
import sys
sys.path.insert(1, '/home/developer/cryptocontrol_venv/scripts/python')
import config
from binance.client import Client #pip install python-binance
from binance.websockets import BinanceSocketManager
client = Client(config.API_KEY, config.API_SECRET, tld='com')
def fuctiontest():
bm = BinanceSocketManager(client)
def handle_message(msg):
print("message: {}".format(msg['p']))
value = round(float(msg['p']),2) #Valor Actual de la cripto.
if float(value) >= 1:
print(str(msg['p'])+" is > 1")
else:
print(str(msg['p'])+" is < 1")
print("Condition done!")
bm.stop_socket(conn_key)
# When done go to print123
# Start trade socket with 'ETHBTC' and use handle_message to.. handle the message.
conn_key = bm.start_trade_socket('ETHBTC', handle_message)
# then start the socket manager
bm.start()
# stop the socket manager
#bm.stop_socket(conn_key)
fuctiontest()
print("test123:")
#/usr/bin/env python
#-*-编码:utf-8-*-
#
#version:python二进制==0.7.9
# https://python-binance.readthedocs.io/en/latest/index.html
#
导入系统
sys.path.insert(1,“/home/developer/cryptocontrol\u venv/scripts/python”)
导入配置
从binance.client导入客户端#pip安装python binance
从binance.websockets导入BinanceSocketManager
client=client(config.API\u KEY,config.API\u SECRET,tld='com')
def fuctiontest():
bm=BinanceSocketManager(客户端)
def句柄_消息(消息):
打印(“消息:{}”。格式(msg['p']))
值=四舍五入(浮动,2)#实际值。
如果浮动(值)>=1:
打印(str(msg['p'])+“is>1”)
其他:
打印(str(msg['p'])+“is<1”)
打印(“条件完成!”)
bm.停止插座(连接键)
#完成后,转到print123
#使用“ETHBTC”启动交易套接字并使用handle_消息。。处理消息。
conn\u key=bm.start\u trade\u socket('ETHBTC',handle\u消息)
#然后启动套接字管理器
bm.start()
#停止套接字管理器
#bm.停止插座(连接键)
功能测试()
打印(“test123:”)