from binance.client import Client
from binance import ThreadedWebsocketManager
import pandas as pd
my_api = ""
my_secret = ""
client = Client(api_key=my_api, api_secret=my_secret, tld="com", testnet=True)
twm = ThreadedWebsocketManager(api_key=my_api, api_secret=my_secret)
twm.start()
def simple_bot(msg):
''' define how to process incoming WebSocket messages '''
time = pd.to_datetime(msg["E"], unit="ms")
price = float(msg["c"])
print("Time: {} | Price: {}".format(time, price))
if int(price) % 10 == 0:
order = client.create_order(symbol="BTCUSDT", side="BUY", type="MARKET", quantity=0.1)
print("\n" + 50 * "-")
print("Buy {} BTC for {} USDT".format(order["executedQty"], order["cummulativeQuoteQty"]))
print(50 * "-" + "\n")
twm.stop()
twm.start_symbol_ticker_socket(callback=simple_bot, symbol="BTCUSDT")
这些是我的代码,当我试图运行这些代码时,我得到了如下错误。
线程线程-1中的异常:回溯(最近一次调用):文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py",第986行,在_wrap_create_connection返回等待self._loop.create_connection(*args,**kwargs) # type: create_connection传输中协议=等待"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py",(文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py",第1119行,在_create_connection_transport中等待服务员文件第534行,在data_received ssldata中)appdata =文件(数据) "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py",第188行,在feed_ssldata self._sslobj.do_handshake()文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py",行974中在do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: SSL: CERTIFICATE_VERIFY_FAILED证书验证失败:证书链中的自签名证书(_ssl.c:997)
上述异常是导致以下异常的直接原因:
追溯(最近一次调用):文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py",第1009行,在_bootstrap_inner self.run()文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/binance/threaded_stream.py",第56行中在运行self._loop.run_until_complete(self.socket_listener())文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py",第646行,在run_until_complete返回future.result()文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/binance/threaded_stream.py",第35行,在socket_listener self._client =等待AsyncClient.create(loop=self._loop,文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/binance/client.py",( **self._client_params)第7258行,在创建等待self.ping()文件self.ping第7379行,在ping返回等待self._get('ping',文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/binance/client.py",第7344行,在_get返回等待self._request_api('get',path,签名,版本,**kwargs)文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/binance/client.py",第7307行,在_request_api返回等待self._request(方法,uri,签名,**kwargs)文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/binance/client.py",行7288,在_request异步中使用getattr(self.session,方法)(uri,**kwargs)作为响应:文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/client.py",行1138,在“等待文件”( "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/client.py", self._resp )中,“等待self._coro文件”(self._resp)行535,在“等待”( _request conn )中,在“等待”(_request self._connector.connect)中(文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py",行542 ),“连接proto =等待”(req,跟踪,文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py",行907,在_create_connection _中,proto = self._create_direct_connection(req,跟踪,超时)文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py",行1206,在“"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py",文件”第1175行中,在“_create_direct_connection transp”中,proto =等待“self._wrap_create_connection”(文件"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py",行988,在_wrap_create_connection raise ClientConnectorCertificateError(req.connection_key,中)exc)从exc aiohttp.client_exceptions.ClientConnectorCertificateError:无法连接到主机api.binance.com:443 ssl:True [SSLCertVerificationError:(1,'SSL: CERTIFICATE_VERIFY_FAILED证书验证失败:证书链中的自签名证书(_ssl.c:997)')]
我不明白为什么这不管用。你能帮帮我吗?谢谢你!
发布于 2022-06-10 18:47:21
我遇到了这个问题,最近在Mac上更新为python 3.10。
您需要进入应用程序/WhateverPythonYouAreUsing文件夹,并单击“InstallCertificates.command”。
它将打开一个终端并安装证书。
帮我修好了。
https://stackoverflow.com/questions/72540934
复制相似问题