Skip to content

Repository files navigation

cTraderFixPy

PyPI versionversionsGitHub license

A Python package for interacting with cTrader FIX API.

This package uses Twisted and it works asynchronously.

Features

  • 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

Insallation

pip install ctrader-fix

Config

Config file sample:

{
"Host": "",
"Port": 0,
"SSL": false,
"Username": "",
"Password": "",
"BeginString": "FIX.4.4",
"SenderCompID": "",
"SenderSubID": "QUOTE",
"TargetCompID": "cServer",
"TargetSubID": "QUOTE",
"HeartBeat": "30"
}

Usage

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.

Dependencies

About

A Python package for interacting with cTrader FIX API.

Topics

Resources

Contributing

Stars

61 stars

Watchers

3 watching

Forks

Releases

Used by

Contributors

Languages