import itchat
import requests
#获取价格
def get_price(symbol):
request = requests.get("https://api.hbdm.com/api/v1/contract_index?symbol="+symbol).json()
price = request["data"]
for item in price:
return (item['index_price']) # 获取列表中字典的值
#获取并发送消息
@itchat.msg_register(itchat.content.TEXT)
def print_content(msg):
price = get_price(msg['Text'])
return "火币合约 " + msg['Text'] + "/USDT 价格为:" + str(price) + " 美元" # 直接将消息返回给发送者
itchat.auto_login(hotReload=True)
itchat.run(True)