A Python package for interacting with cTrader FIX API.
This package uses Twisted and it works asynchronously.
- Free software: MIT
- Documentation: https://spotware.github.io/cTraderFixPy/.
Works asynchronously by using Twisted
Allows you to easily interact with cTrader FIX API and it manages everything in background
Generate FIX message by using Python objects
pip install ctrader-fix
Config file sample:
{
"Host": "",
"Port": 0,
"SSL": false,
"Username": "",
"Password": "",
"BeginString": "FIX.4.4",
"SenderCompID": "",
"SenderSubID": "QUOTE",
"TargetCompID": "cServer",
"TargetSubID": "QUOTE",
"HeartBeat": "30"
}fromtwisted.internetimportreactorimportjsonfromctrader_fiximport*# Callback for receiving all messagesdefonMessageReceived(client, responseMessage):
print("Received: ", responseMessage.getMessage().replace("�", "|"))
messageType=responseMessage.getFieldValue(35)
ifmessageType=="A":
print("We are logged in")
# Callback for client disconnectiondefdisconnected(client, reason): print("Disconnected, reason: ", reason)
# Callback for client connectiondefconnected(client):
print("Connected")
logonRequest=LogonRequest(config)
client.send(logonRequest)
# you can use two separate config files for QUOTE and TRADEwithopen("config-trade.json") asconfigFile:
config=json.load(configFile)
client=Client(config["Host"], config["Port"], ssl=config["SSL"])
# Setting client callbacksclient.setConnectedCallback(connected)
client.setDisconnectedCallback(disconnected)
client.setMessageReceivedCallback(onMessageReceived)
# Starting the client serviceclient.startService()
reactor.run()Please check documentation or samples for a complete example.