我正在学习如何构建 Python 交易机器人,我正处于编程的第一步,我需要一些帮助。我在尝试使用 API 连接器从基本 URL 和来自 bitmex.com 的 Websocket 获取信息时遇到了这个错误。
这是连接到主机的代码:
BitmexClient 类:
def __init__(self, public_key: str, secret_key: str, testnet: bool):
if testnet:
self._base_url = "https://testnet.bitmex.com"
self._wss_url = "wss://testnet.bitmex.com/realtime"
else:
self._base_url = "https://www.bitmex.com"
self._wss_url = "wss://www.bitmex.com/realtime"
self._public_key = public_key
self._secret_key = secret_key
self._ws = None
self.contracts = self.get_contracts()
self.balances = self.get_balances()
self.prices = dict()
t = threading.Thread(target=self._start_ws)
t.start()
logger.info("Bitmex Client successfully initialized")
与错误相关的代码段:
def get_contracts(self) -> typing.Dict[str, Contract]:
instruments = self._make_request("GET", "api/v1/instrument/active", dict())
contracts = dict()
if instruments is not None:
for s in instruments:
contracts[s['symbol']] = Contract(s, "bitmex")
return contracts
def get_balances(self) -> typing.Dict[str, Balance]:
data = dict()
data['currency'] = "all"
margin_data = self._make_request("GET", "api/v1/user/margin", data)
balances = dict()
if margin_data is not None:
for a in margin_data:
balances[a['currency']] = Balance(a, "bitmex")
return balances
这是错误:
2021-04-30 22:38:45,969 ERROR :: Connection error while making GET request to api/v1/instrument/active: HTTPSConnectionPool(host='testnet.bitmex.comapi', port=443): Max retries exceeded with url: /v1/instrument/active (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002065A061520>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
2021-04-30 22:38:45,972 ERROR :: Connection error while making GET request to api/v1/user/margin: HTTPSConnectionPool(host='testnet.bitmex.comapi', port=443): Max retries exceeded with url: /v1/user/margin?currency=all (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002065A061760>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))