okxapi/python-okx

websocket 发送消息时 错误

Closed this issue · 9 comments

调用 ws.subscribe(args, callback=privateCallback) 函数时
127.0.0.1 - - [08/Jun/2023 09:26:01] "POST /app/signal HTTP/1.1" 200 -
Unhandled Error
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/Users/home-pc/Documents/python/pythonObject/tvProjict/venv/lib/python3.11/site-packages/okx/websocket/WsConnectManager.py", line 124, in run
reactor.run(installSignalHandlers=False)
File "/Users/home-pc/Documents/python/pythonObject/tvProjict/venv/lib/python3.11/site-packages/twisted/internet/base.py", line 1318, in run
self.mainLoop()
File "/Users/home-pc/Documents/python/pythonObject/tvProjict/venv/lib/python3.11/site-packages/twisted/internet/base.py", line 1328, in mainLoop
reactorBaseSelf.runUntilCurrent()
--- ---
File "/Users/home-pc/Documents/python/pythonObject/tvProjict/venv/lib/python3.11/site-packages/twisted/internet/base.py", line 967, in runUntilCurrent
f(*a, **kw)
File "/Users/home-pc/Documents/python/pythonObject/tvProjict/venv/lib/python3.11/site-packages/okx/websocket/WsConnectManager.py", line 114, in resetConnection
raise ValueError("instance must not none")
builtins.ValueError: instance must not none

WsClientFactory execute clientConnectionLost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
],retried 2 times
WsClientFactory execute clientConnectionLost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
],retried 3 times
WsClientFactory execute clientConnectionLost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
],retried 4 times
WsClientFactory execute clientConnectionLost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
],retried 5 times
loginSocket callback: {'e': 'error', 'm': 'reached max connect retries'}
WsClientFactory execute clientConnectionLost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
],retried 6 times

Facing the same issue. Is this error from SDK?

同问

okxapi commented

We are working on this issue and will update soon. Thanks!

Pborz commented

We are working on this issue and will update soon. Thanks!

大家好,经过我对autobahn和Twisted两大基础库的issue周旋,目前基本锁定问题了,希望能帮okxapi大哥一同working on
首先,在

    def subscribeSocket(self, args: list, callback):
        channelArgs = {}
        channelParamMap = {}
        WsUtils.checkSocketParams(args, channelArgs, channelParamMap)
        if len(channelArgs) < 1:
            return False
        for channel in channelArgs:
            subSet = channelParamMap.get(channel, set())
            if self.isPrivate:
                privateKey = self.getPrivateKey(channel)
                if privateKey not in self.factories:
                    reactor.callFromThread(self.loginSocket, channel)
                    time.sleep(2)
                    newFactory = self.initSubscribeFactory(args=channelArgs[channel], subSet=subSet, callback=callback)
                    reactor.callFromThread(self.resetConnection, newFactory, channel)
                    continue
            factory = self.initSubscribeFactory(args=channelArgs[channel], subSet=subSet, callback=callback)
            self.factories[channel] = factory
            reactor.callFromThread(self.addConnection, channel)

    def addConnection(self, channel):
        self.conns[channel] = connectWS(self.factories[channel])

这个connectWS有问题,这个内核是Twisted的reactor调用connectSSL
但是诡异的是,我偶然发现这个connectSSL可以连接okex但不能连接okx
于是我在Twisted找到相关人问了下,他们表示要大改,就是使用endpoint,我粗略试了下,不太有把握,而且我进一步问能不能尽量基于IConnector类,还没答复。
https://github.com/twisted/twisted/issues/11928

但是现在基本锁定了问题,就是市面上的import websockets连接okx okex都没问题,但目前okxapi大哥基于的autobahn和Twisted对于okx这个新版wssk可能有些点没通,现在想听听okxapi大哥目前是打算怎样进行下去,我们网友能帮忙的一定会帮忙code 共勉奋斗! @okxapi

@Pborz okxapi 应该是OKX的人。https://pypi.org/project/python-okx/ 这里的联系作者邮箱填的是OK集团的邮箱。okg.com。不过这个问题到底有多大,为什么至少三周过去了还没有时间修复,你们这些技术大牛,这么忙的吗?jane-cloud的版本貌似能用,何不参考下那个版本是如何解决的?反正python-okx 的websocket是用不了的,而且这个问题从6月份有人反馈到现在还没解决????技术问题?时间问题?还是啥问题?我甚至到OK官方API电报群提意见,客服也是各种说会反馈上去,又一周过去了,这点东西对交易所的程序员技术来说,根本不是啥,为啥支持那么差。交易所自己维护一个python wrapper也花不了多少资源阿. 大牛能帮我们弄个wrapper,咱们就省时间,省精力,我们自己折腾,费时费力,毕竟咱的主要重心是策略的实现。

583 commented

@Pborz @CryptoTraderJason 我也栽在这里了,目前你们解决了吗?我看官方依旧没有更新这个问题

We are working on this issue and will update soon. Thanks!

@okxapi man, I noticed that you updated README.md a few hours ago, welcome back from a long vacation, can we get this websocket issue fixed? It's been a couple of months since the issue occured.

自己用js实现了=。=

okxapi commented

hi, guys, you may refer to the new websocket example
大家可以参考下最新的websocket例子
https://github.com/okxapi/python-okx/blob/master/test/WsPrivateAsyncTest.py
https://github.com/okxapi/python-okx/blob/master/test/WsPublicAsyncTest.py