Skip to content

Commit

Permalink
Merge pull request #11 from spotware/dev
Browse files Browse the repository at this point in the history
Added market data subscription code to Jupyter
  • Loading branch information
amusleh-spotware-com authored Apr 12, 2022
2 parents 65dc80a + 7681607 commit f213449
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion samples/ConsoleSample/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ctrader_fix import *

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

client = Client(config["Host"], config["Port"], ssl = config["SSL"])
Expand Down
37 changes: 27 additions & 10 deletions samples/jupyter/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"outputs": [],
"source": [
"# you can use two separate config files for QUOTE and TRADE\n",
"with open(\"config-trade.json\") as configFile:\n",
"with open(\"config-quote.json\") as configFile:\n",
" config = json.load(configFile)"
]
},
Expand Down Expand Up @@ -115,7 +115,13 @@
"id": "9e722b92",
"metadata": {},
"source": [
"Now let's set and client call backs that will be used by client after it got message received/connected/disconnected:"
"We are going to:\n",
"\n",
"1. Send a log on requst\n",
"2. After receiving log on response we send security list request\n",
"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",
"\n",
"Let's set the client call backs that will be used by client after it got message received/connected/disconnected:"
]
},
{
Expand All @@ -137,17 +143,28 @@
" send(securityListRequest)\n",
" # After receiving the security list we send a market order request by using the security list first symbol\n",
" elif messageType == \"y\":\n",
" newOrderSingle = NewOrderSingle(config)\n",
" newOrderSingle.ClOrdID = \"B\"\n",
" # We use getFieldValue to get all symbol IDs, it will return a list in this case\n",
" # because the symbol ID field is repetitive\n",
" symboldIds = responseMessage.getFieldValue(55)\n",
" newOrderSingle.Symbol = symboldIds[0]\n",
" newOrderSingle.Side = 1\n",
" newOrderSingle.OrderQty = 1000\n",
" newOrderSingle.OrdType = 1\n",
" newOrderSingle.Designation = \"From Jupyter\"\n",
" send(newOrderSingle)\n",
" if config[\"TargetSubID\"] == \"TRADE\":\n",
" newOrderSingle = NewOrderSingle(config)\n",
" newOrderSingle.ClOrdID = \"B\"\n",
" newOrderSingle.Symbol = symboldIds[1]\n",
" newOrderSingle.Side = 1\n",
" newOrderSingle.OrderQty = 1000\n",
" newOrderSingle.OrdType = 1\n",
" newOrderSingle.Designation = \"From Jupyter\"\n",
" send(newOrderSingle)\n",
" else:\n",
" marketDataRequest = MarketDataRequest(config)\n",
" marketDataRequest.MDReqID = \"a\"\n",
" marketDataRequest.SubscriptionRequestType = 1\n",
" marketDataRequest.MarketDepth = 1\n",
" marketDataRequest.NoMDEntryTypes = 1\n",
" marketDataRequest.MDEntryType = 0\n",
" marketDataRequest.NoRelatedSym = 1\n",
" marketDataRequest.Symbol = symboldIds[1]\n",
" send(marketDataRequest)\n",
" # after receiving the new order request response we stop the reactor\n",
" # And we will be disconnected from API\n",
" elif messageType == \"8\" or messageType == \"j\":\n",
Expand Down

0 comments on commit f213449

Please sign in to comment.