Kyu*_*Lee -1 python websocket binance
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")
Run Code Online (Sandbox Code Playgroud)
这些是我的代码,当我尝试运行这些代码时,出现如下错误。
-----错误文本-----
线程 Thread-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) # 类型: 忽略[返回值] # noqa 文件 "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio /base_events.py”,第1089行,在create_connection传输中,协议=等待self._create_connection_transport(文件“/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py”,第1119行,在_create_connection_transport等待服务员文件“/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py”,第534行,在data_received ssldata中,appdata = self._sslpipe.feed_ssldata(data)文件“/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 = wait AsyncClient.create(loop=self._loop, **self._client_params) 文件“/Library/Frameworks/Python.framework /Versions/3.10/lib/python3.10/site-packages/binance/client.py”,第 7258 行,在创建等待 self.ping() 文件“/Library/Frameworks/Python.framework/Versions/3.10/lib/ python3.10/site-packages/binance/client.py”,第 7379 行,在 ping 返回中等待 self._get('ping', version=self.PRIVATE_API_VERSION) 文件“/Library/Frameworks/Python.framework/Versions/3.10 /lib/python3.10/site-packages/binance/client.py”,第 7344 行,在 _get return wait self._request_api('get', path,signed, version, **kwargs) 文件“/Library/Frameworks/ Python.framework/Versions/3.10/lib/python3.10/site-packages/binance/client.py”,第 7307 行,在 _request_api 返回等待 self._request(method, uri,signed, **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 行,位于aenter中 self._resp =等待self._coro文件“/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/client.py”,第535行,在_request conn =等待self。 _connector.connect(文件“/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py”,第542行,在连接原型=等待self._create_connection(req,跟踪,超时)文件“/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py”,第907行,在_create_connection _中,proto =等待self._create_direct_connection(请求,跟踪,超时)文件“/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py”,第1206行,在_create_direct_connection中引发last_exc文件“/Library/ Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py",第 1175 行,在 _create_direct_connection transp 中,proto = wait self._wrap_create_connection( File "/Library/Frameworks/Python. Framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py”,第 988 行,在 _wrap_create_connection 中引发 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)')]
我不明白为什么这不起作用。你可以帮帮我吗!?谢谢你!
小智 5
我遇到了这个问题,最近在 Mac 上更新到了 python 3.10。
您需要进入Applications/WhateverPythonYouAreUsing文件夹并单击“Install Certificates.command”。
它将打开一个终端并安装证书。
这为我解决了。
| 归档时间: |
|
| 查看次数: |
1288 次 |
| 最近记录: |