Skip to content

Commit 2158f0d

Browse files
Merge pull request #5 from spotware/dev
Dev
2 parents 8193ed2 + e6a226d commit 2158f0d

6 files changed

Lines changed: 145 additions & 266 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ dmypy.json
135135
/samples/ConsoleSample/config-quote.json
136136
/samples/KleinWebAppSample/config-trade.json
137137
/samples/KleinWebAppSample/config-quote.json
138+
/samples/jupyter/config-trade.json
139+
/samples/jupyter/config-quote.json

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,64 @@ This package uses Twisted and it works asynchronously.
2727
pip 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

3790
Please check documentation or samples for a complete example.

samples/jupyter/README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
# Jupyter Sample
22

3-
This is sample that will show you how to use the OpenApiPy Python package on a Jupyter notebook.
3+
This is sample that will show you how to use the cTraderFix Python package on a Jupyter notebook.
44

5-
In the notebook we get the daily bars data from cTrader Open API, then we use it to train a sklearn model.
5+
In the notebook we logon, retrive account securities/symbols, and then we execute a market order.
66

7-
To use the sample you have to create a copy of "credentials.json" file and rename it to "credentials-dev.json".
7+
Before running the sample you have to create a config file and fill it with your trading account FIX API credentials.
88

9-
Then fill the file with your Open API application credentials, access token, and a trading account ID.
9+
Then replace the config file name on sample main file to your config file name.
10+
11+
Config file sample:
12+
13+
```json
14+
{
15+
"Host": "",
16+
"Port": 0,
17+
"SSL": false,
18+
"Username": "",
19+
"Password": "",
20+
"BeginString": "FIX.4.4",
21+
"SenderCompID": "",
22+
"SenderSubID": "QUOTE",
23+
"TargetCompID": "cServer",
24+
"TargetSubID": "QUOTE",
25+
"HeartBeat": "30"
26+
}
27+
```

samples/jupyter/config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Host": "",
3+
"Port": 0,
4+
"SSL": false,
5+
"Username": "",
6+
"Password": "",
7+
"BeginString": "FIX.4.4",
8+
"SenderCompID": "",
9+
"SenderSubID": "QUOTE",
10+
"TargetCompID": "cServer",
11+
"TargetSubID": "QUOTE",
12+
"HeartBeat": "30"
13+
}

samples/jupyter/credentials.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)