def queryNewOrderSingle44(self): ordType = fix.OrdType() message = fix44.NewOrderSingle() message.setField(self.queryClOrdID()) message.setField(fix.HandlInst('1')) message.setField(self.querySymbol()) message.setField(self.querySide()) message.setField(fix.TransactTime()) ordType = self.queryOrdType() message.setField(ordType) message.setField(self.queryOrderQty()) message.setField(self.queryTimeInForce()) message.setField(self.querySecurityExchange()) message.setField(self.queryAccount()) if ordType.getValue() == fix.OrdType_LIMIT or ordType.getValue( ) == fix.OrdType_STOP_LIMIT: message.setField(self.queryPrice()) if ordType.getValue() == fix.OrdType_STOP or ordType.getValue( ) == fix.OrdType_STOP_LIMIT: message.setField(self.queryStopPx()) header = message.getHeader() self.queryHeader(header) return message
def send(self, order): orderId = self.SocketInitiator.application.genOrderID() account = self.SocketInitiator.application.Settings.get().getString( 'Account') trade = fix44.NewOrderSingle() trade.setField(fix.Account(account)) trade.setField(fix.ClOrdID(orderId)) trade.setField(order.CFICode) trade.setField(order.TransactionTime) trade.setField(order.Quantity) trade.setField(order.OrdType) trade.setField(order.Side) trade.setField(order.Symbol) trade.setField(order.Maturity) if isinstance(order, FutureLimitOrder): trade.setField(order.Price) self.SocketInitiator.application.send(trade) ordType = OrderType.Limit if isinstance( order, FutureLimitOrder) else OrderType.Market ordSide = OrderSide.Buy if isinstance(order, BuyOrder) else OrderSide.Sell price = order.Price.getValue() if isinstance( order, FutureLimitOrder) else None return Trade(orderId, order.Symbol.getString(), order.Maturity.getString(), order.Quantity.getValue(), ordType, ordSide, price)
def put_new_order(self, instrument, side, price, size): """Request sample new order single""" message = quickfix44.NewOrderSingle() header = message.getHeader() print("Executing : " + str(instrument) + ":" + str(side) + ":" + str(price) + ":" + str(size)) message.setField(quickfix.ClOrdID(self.genExecID())) message.setField(quickfix.Side(side)) message.setField(quickfix.Symbol(instrument.symbol)) message.setField(quickfix.SecurityExchange(instrument.exchange)) message.setField(quickfix.OrderQty(size)) message.setField(quickfix.Price(int(price))) message.setField(quickfix.OrdType(quickfix.OrdType_LIMIT)) message.setField(quickfix.TimeInForce('0')) message.setField(quickfix.Text("NewOrderSingle")) trstime = quickfix.TransactTime() trstime.setString( datetime.utcnow().strftime("%Y%m%d-%H:%M:%S.%f")[:-3]) message.setField(trstime) msg = message.toString().replace(__SOH__, "|") print("New Order Single: " + msg) quickfix.Session.sendToTarget(message, self.sessionID)
def make_single_order(self, order_id, symbol, qty): account = "YIZHE0" order = fix44.NewOrderSingle() order.setField(fix.Account(account)) order.setField(fix.ClOrdID(order_id)) order.setField(fix.Symbol(symbol)) order.setField(fix.Side("1")) order.setField(fix.OrdType("U")) order.setField(fix.OrderQty(qty)) order.setField(fix.Price(49)) return order
def test_order(self): cid = fix.ClOrdID('100') requestTime = fix.TransactTime() requestTime.setString('20170606-03:52:34.924') request = fix44.NewOrderSingle() request.setField(requestTime) request.setField(cid) responseTime = fix.TransactTime() responseTime.setString('20170606-03:52:14.824') response = fix44.ExecutionReport() response.setField(responseTime) response.setField(cid) currentLag = {} def receive(event): currentLag[0] = event.CurrentTimeLag self.Store.addTimeLagListener(receive) self.Store.addRequest(request) self.Store.addResponse(response) self.assertEqual(currentLag[0], 20.1)
while not app.logged_on: time.sleep(0.1) print("Logged in!") # Send message using normal Quickfix messages m = fix44.SecurityListRequest() m.setField(fix.SecurityReqID(str(uuid.uuid4()))) m.setField( fix.SecurityListRequestType( fix.SecurityListRequestType_ALL_SECURITIES)) fix.Session.sendToTarget(m, app.session_id) # Send an order m = fix44.NewOrderSingle() m.setField(fix.ClOrdID(str(uuid.uuid4()))) m.setField(fix.SecurityID('25')) m.setField( fix.SecurityIDSource( fix.SecurityIDSource_MARKETPLACE_ASSIGNED_IDENTIFIER)) m.setField(fix.Side(fix.Side_BUY)) m.setField(fix.OrderQty(0.01)) m.setField(fix.Price(123)) m.setField(fix.OrdType(fix.OrdType_LIMIT)) # Python QuickFIX UtcTimeStampField doesn't accept a `datetime` object, we # provide an easy helper function for you t = fix.TransactTime() t.setString(easyfix.fix_utctimestamp(datetime.datetime.utcnow())) m.setField(t)