微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python Bitmex 交易机器人 - .向 api/v1/instrument/active 和 api/v1/user/margin 发出获取请求时出现连接错误

如何解决Python Bitmex 交易机器人 - .向 api/v1/instrument/active 和 api/v1/user/margin 发出获取请求时出现连接错误

我正在学习如何构建 Python 交易机器人,我正处于编程的第一步,我需要一些帮助。我在尝试使用 API 连接器从 bitmex.com 的 Base URL 和 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'))

解决方法

问题似乎在于您正在尝试连接到“testnet.bitmex.comapi”的主机。

主机应该是“testnet.bitmex.com”。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?