Purchase order with python.
Purchase order with python.
10 Mar 2022, 12:40
I am trying to send a purchase order, but I am not receiving a response from the server. The session is correct, and I am connected to port 5202. The python code is:
mdr = fix.Message()
mdr.getHeader().setField(fix.BeginString(fix.BeginString_FIX44))
mdr.getHeader().setField(fix.MsgType(fix.MsgType_NewOrderSingle))
mdr.getHeader().setField(fix.TargetSubID('TRADE'))
mdr.getHeader().setField(fix.SenderSubID('TRADE'))
mdr.setField(fix.ClOrdID(str(str(self.genExecID())))
mdr.setField(fix.HandlInst('1')))
mdr.setField(fix.Side('1'))
mdr.setField(fix.Symbol('1'))
mdr.setField(fix.OrderQty(0.01))
mdr.setField(fix.Currency('EUR'))
mdr.setField(fix.TimeInForce('1'))
mdr.setField(fix.OrdType('1'))
trstime = fix.TransactTime()
trstime.setString(datetime.utcnow().strftime('%Y%m%d-%H:%M:%S.%f')[:-3])
mdr.setField(trstime)
fix.Session.sendToTarget(mdr, self.sessionID)
And the message it generates is:
8=FIX.4.4☺9=158☺35=D☺34=2☺49=demo.ctrader.3449248☺50=TRADE☺52=20220310-10:37:36.000☺56=CSERVER☺57=TRADE☺11=1☺15=EUR☺21=1☺38=0.01☺40=1☺54=1☺55=1☺59=1☺60=20220310-10:37:36.898☺10=130☺
No response from the server except:
FIX.4.4:demo.ctrader.3449248->CSERVER:SessionTrade
Does anyone miss any fields or see any errors in the message. Thank you very much.
amusleh
10 Mar 2022, 14:49
Hi,
Our FIX server never sends back something like:
FIX.4.4:demo.ctrader.3449248->CSERVER:SessionTrade
If server is not responding to your message then most probably your message checksum is invalid.
Please try our Python FIX package: spotware/cTraderFixPy: A Python package for interacting with cTrader FIX API. (github.com)
It's not released yet, but you can install it from TestPyPi:
Once you installed it try to use the Console sample which is inside it's repository.
@amusleh