Skip to content

Commit f213449

Browse files
Merge pull request #11 from spotware/dev
Added market data subscription code to Jupyter
2 parents 65dc80a + 7681607 commit f213449

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

samples/ConsoleSample/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ctrader_fix import *
77

88
# you can use two separate config files for QUOTE and TRADE
9-
with open("config-trade.json") as configFile:
9+
with open("config-quote.json") as configFile:
1010
config = json.load(configFile)
1111

1212
client = Client(config["Host"], config["Port"], ssl = config["SSL"])

samples/jupyter/main.ipynb

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"outputs": [],
6969
"source": [
7070
"# you can use two separate config files for QUOTE and TRADE\n",
71-
"with open(\"config-trade.json\") as configFile:\n",
71+
"with open(\"config-quote.json\") as configFile:\n",
7272
" config = json.load(configFile)"
7373
]
7474
},
@@ -115,7 +115,13 @@
115115
"id": "9e722b92",
116116
"metadata": {},
117117
"source": [
118-
"Now let's set and client call backs that will be used by client after it got message received/connected/disconnected:"
118+
"We are going to:\n",
119+
"\n",
120+
"1. Send a log on requst\n",
121+
"2. After receiving log on response we send security list request\n",
122+
"3. Then if host is Trade we create a new market order for second symbol otherwise we send a mrket data request for the second symbol\n",
123+
"\n",
124+
"Let's set the client call backs that will be used by client after it got message received/connected/disconnected:"
119125
]
120126
},
121127
{
@@ -137,17 +143,28 @@
137143
" send(securityListRequest)\n",
138144
" # After receiving the security list we send a market order request by using the security list first symbol\n",
139145
" elif messageType == \"y\":\n",
140-
" newOrderSingle = NewOrderSingle(config)\n",
141-
" newOrderSingle.ClOrdID = \"B\"\n",
142146
" # We use getFieldValue to get all symbol IDs, it will return a list in this case\n",
143147
" # because the symbol ID field is repetitive\n",
144148
" symboldIds = responseMessage.getFieldValue(55)\n",
145-
" newOrderSingle.Symbol = symboldIds[0]\n",
146-
" newOrderSingle.Side = 1\n",
147-
" newOrderSingle.OrderQty = 1000\n",
148-
" newOrderSingle.OrdType = 1\n",
149-
" newOrderSingle.Designation = \"From Jupyter\"\n",
150-
" send(newOrderSingle)\n",
149+
" if config[\"TargetSubID\"] == \"TRADE\":\n",
150+
" newOrderSingle = NewOrderSingle(config)\n",
151+
" newOrderSingle.ClOrdID = \"B\"\n",
152+
" newOrderSingle.Symbol = symboldIds[1]\n",
153+
" newOrderSingle.Side = 1\n",
154+
" newOrderSingle.OrderQty = 1000\n",
155+
" newOrderSingle.OrdType = 1\n",
156+
" newOrderSingle.Designation = \"From Jupyter\"\n",
157+
" send(newOrderSingle)\n",
158+
" else:\n",
159+
" marketDataRequest = MarketDataRequest(config)\n",
160+
" marketDataRequest.MDReqID = \"a\"\n",
161+
" marketDataRequest.SubscriptionRequestType = 1\n",
162+
" marketDataRequest.MarketDepth = 1\n",
163+
" marketDataRequest.NoMDEntryTypes = 1\n",
164+
" marketDataRequest.MDEntryType = 0\n",
165+
" marketDataRequest.NoRelatedSym = 1\n",
166+
" marketDataRequest.Symbol = symboldIds[1]\n",
167+
" send(marketDataRequest)\n",
151168
" # after receiving the new order request response we stop the reactor\n",
152169
" # And we will be disconnected from API\n",
153170
" elif messageType == \"8\" or messageType == \"j\":\n",

0 commit comments

Comments
 (0)