ProtoHeartbeatEvent giving an error
ProtoHeartbeatEvent giving an error
21 Jun 2023, 13:36
Hi, I will show the code that i'm using and the error that i get. Why is this error coming and is the code i'm using properly written?
My goal with the heartbeat is to keep my connection alive.
def sendProtoHeartbeatEvent():
print('Sending heartbeat...')
request = ProtoHeartbeatEvent()
request.payloadType = 51
deferred = client.send(request)
deferred.addErrback(onError)
def accountAuthResponseCallback(result):
sendProtoHeartbeatEvent()
def applicationAuthResponseCallback(result):
print("\nApplication authenticated")
request = ProtoOAAccountAuthReq()
request.ctidTraderAccountId = credentials["AccountId_ctrader"]
request.accessToken = credentials["AccessToken_ctrader"]
deferred = client.send(request)
deferred.addCallbacks(accountAuthResponseCallback, onError)
def onError(client, failure): # Call back for errors
print("\nMessage Error: ", failure)
def disconnected(client, reason): # Callback for client disconnection
print("\nDisconnected at ", str(datetime.datetime.now()),": ", reason)
def onMessageReceived(client, message): # Callback for receiving all messages
if message.payloadType in [ProtoHeartbeatEvent().payloadType, ProtoOAAccountAuthRes().payloadType, ProtoOAApplicationAuthRes().payloadType, ProtoOASymbolsListRes().payloadType, ProtoOAGetTrendbarsRes().payloadType]:
return
m = str(Protobuf.extract(message))
print('message proto:', m)
def connected(client): # Callback for client connection
print("\nConnected", str(datetime.datetime.now()))
request = ProtoOAApplicationAuthReq()
request.clientId = credentials["ClientId_ctrader"]
request.clientSecret = credentials["Secret_ctrader"]
deferred = client.send(request)
deferred.addCallbacks(applicationAuthResponseCallback, onError)
# Setting optional client callbacks
client.setConnectedCallback(connected)
client.setDisconnectedCallback(disconnected)
client.setMessageReceivedCallback(onMessageReceived)
# Starting the client service
client.startService()
# Run Twisted reactor, we imported it earlier
reactor.run()
And the error i get is this one
Sending heartbeat...
Unhandled error in Deferred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/twisted/internet/defer.py", line 586, in timeItOut
self.cancel()
File "/usr/local/lib/python3.10/dist-packages/twisted/internet/defer.py", line 742, in cancel
self.errback(Failure(CancelledError()))
File "/usr/local/lib/python3.10/dist-packages/twisted/internet/defer.py", line 701, in errback
self._startRunCallbacks(fail)
File "/usr/local/lib/python3.10/dist-packages/twisted/internet/defer.py", line 764, in _startRunCallbacks
self._runCallbacks()
--- <exception caught here> ---
File "/usr/local/lib/python3.10/dist-packages/twisted/internet/defer.py", line 858, in _runCallbacks
current.result = callback( # type: ignore[misc]
builtins.TypeError: onError() missing 1 required positional argument: 'failure'