Replies

ahmdee
27 Dec 2024, 12:27 ( Updated at: 30 Dec 2024, 07:15 )

Here is the actual code that I'm running and the results of running it
from ctrader_open_api import Client, Protobuf, TcpProtocol, Auth, EndPoints
from ctrader_open_api.messages.OpenApiCommonMessages_pb2 import *
from ctrader_open_api.messages.OpenApiMessages_pb2 import *
from ctrader_open_api.messages.OpenApiModelMessages_pb2 import *
from twisted.internet import reactor
import json

credentialsFile = open('credentials.json')
credentials = json.load(credentialsFile)

client = Client('live.ctraderapi.com', 5035, TcpProtocol)

def onMessageReceived(client, message):
	print('msg', message)
def applicationAuthResponseCallback(result):
	print('app authenticated')
def onError(failure):
	print('err msg: ', repr(failure.value))
def disconnected(client, reason):
	print('Disconnected: ', reason.getErrorMessage())

def connected(client):
	print('Connected')
	request = ProtoOAApplicationAuthReq()
	request.clientId = credentials['ClientId']
	request.clientSecret = credentials['ClientSecret']
	deferred = client.send(request, responseTimeoutInSeconds=30)
	print('Sent request:  ProtoOAApplicationAuthReq')
	deferred.addCallbacks(applicationAuthResponseCallback, onError)

client.setConnectedCallback(connected)
client.setDisconnectedCallback(disconnected)
client.setMessageReceivedCallback(onMessageReceived)
client.startService()
reactor.run()


@ahmdee