@@ -27,11 +27,64 @@ This package uses Twisted and it works asynchronously.
2727pip install ctrader-fix
2828```
2929
30+ # Config
31+
32+ Config file sample:
33+
34+ ``` json
35+ {
36+ "Host" : " " ,
37+ "Port" : 0 ,
38+ "SSL" : false ,
39+ "Username" : " " ,
40+ "Password" : " " ,
41+ "BeginString" : " FIX.4.4" ,
42+ "SenderCompID" : " " ,
43+ "SenderSubID" : " QUOTE" ,
44+ "TargetCompID" : " cServer" ,
45+ "TargetSubID" : " QUOTE" ,
46+ "HeartBeat" : " 30"
47+ }
48+ ```
49+
3050# Usage
3151
3252``` python
33-
34-
53+ from twisted.internet import reactor
54+ from inputimeout import inputimeout, TimeoutOccurred
55+ import json
56+ from ctrader_fix import *
57+
58+ # Callback for receiving all messages
59+ def onMessageReceived (client , responseMessage ):
60+ print (" Received: " , responseMessage.getMessage().replace(" " , " |" ))
61+ messageType = responseMessage.getFieldValue(35 )
62+ if messageType == " A" :
63+ print (" We are logged in" )
64+
65+ # Callback for client disconnection
66+ def disconnected (client , reason ):
67+ print (" Disconnected, reason: " , reason)
68+
69+ # Callback for client connection
70+ def connected (client ):
71+ print (" Connected" )
72+ logonRequest = LogonRequest(config)
73+ send(logonRequest)
74+
75+ # you can use two separate config files for QUOTE and TRADE
76+ with open (" config-trade.json" ) as configFile:
77+ config = json.load(configFile)
78+
79+ client = Client(config[" Host" ], config[" Port" ], ssl = config[" SSL" ])
80+
81+ # Setting client callbacks
82+ client.setConnectedCallback(connected)
83+ client.setDisconnectedCallback(disconnected)
84+ client.setMessageReceivedCallback(onMessageReceived)
85+ # Starting the client service
86+ client.startService()
87+ reactor.run()
3588```
3689
3790Please check documentation or samples for a complete example.
0 commit comments