public int addOrder(OrderStruct os) { OrderDAO odao = new OrderDAO(); Console.WriteLine("Going to call DB"); int ordNo = odao.insertOrder(os); ClOrdID OrdId = new ClOrdID(Convert.ToString(os.ID)); string symbol = sanitiseField(os.symbol); var order = new QuickFix.FIX42.NewOrderSingle(OrdId, new HandlInst('1'), new Symbol(symbol), new Side(Side.BUY), new TransactTime(DateTime.Now.ToUniversalTime()), new OrdType(OrdType.LIMIT)); order.Price = new Price((decimal)os.price); order.SetField(new OrderQty(1)); Session.SendToTarget(order, FixClient.MySess); return(ordNo); }
public int addOrder(OrderStruct os) { OrderDAO odao = new OrderDAO(); Console.WriteLine("Going to call DB"); int ordNo = odao.insertOrder(ref os); // Keep the OrderNO for client and pass the OrderID to FIX. ClOrdID OrdId = new ClOrdID(Convert.ToString(os.ID)); string symboldata = sanitiseField(os.symbol); //check Futures or Options Order string exch = new string(os.exch); if (exch.Equals("STK")) { if (os.direction == 'B') { Symbol symbol = new Symbol(symboldata); Side side = new Side(Side.BUY); int Qty = (int)os.quantity; var orderNFO = new QuickFix.FIX42.NewOrderSingle(OrdId, new HandlInst('1'), symbol, side, new TransactTime(DateTime.Now.ToUniversalTime()), new OrdType(OrdType.LIMIT)); orderNFO.SetField(new OrderQty(Qty)); orderNFO.ExDestination = new ExDestination("NS"); orderNFO.SecurityType = new SecurityType(SecurityType.COMMON_STOCK); //string expiry = new string(os.expiry); //orderNFO.MaturityMonthYear = new MaturityMonthYear(expiry.Substring(0, 6)); orderNFO.Account = new Account("D2"); OrdType ordType = new OrdType(OrdType.LIMIT); if (os.orderType == 1) { ordType = new OrdType(OrdType.MARKET); } orderNFO.OrdType = ordType; orderNFO.Price = new Price((decimal)os.price); Console.WriteLine("STOCK BUY Order for : " + symbol + "orderType : " + ordType); //Send Future order to fix server Session.SendToTarget(orderNFO, FixClient.MySess); } else if (os.direction == 'S') { Symbol symbol = new Symbol(symboldata); Side side = new Side(Side.SELL); int Qty = (int)os.quantity; var orderNFO = new QuickFix.FIX42.NewOrderSingle(OrdId, new HandlInst('1'), symbol, side, new TransactTime(DateTime.Now.ToUniversalTime()), new OrdType(OrdType.LIMIT)); orderNFO.SetField(new OrderQty(Qty)); orderNFO.ExDestination = new ExDestination("NS"); orderNFO.SecurityType = new SecurityType(SecurityType.COMMON_STOCK); //string expiry = new string(os.expiry); //orderNFO.MaturityMonthYear = new MaturityMonthYear(expiry.Substring(0, 6)); orderNFO.Account = new Account("D2"); OrdType ordType = new OrdType(OrdType.LIMIT); if (os.orderType == 1) { ordType = new OrdType(OrdType.MARKET); } orderNFO.OrdType = ordType; orderNFO.Price = new Price((decimal)os.price); Console.WriteLine("STOCK SELL Order for : " + symbol + "orderType : " + ordType); //Send Future order to fix server Session.SendToTarget(orderNFO, FixClient.MySess); } } else if (exch.Equals("NFO")) { if (os.direction == 'B') { Symbol symbol = new Symbol(symboldata); Side side = new Side(Side.BUY); int Qty = (int)os.quantity; var orderNFO = new QuickFix.FIX42.NewOrderSingle(OrdId, new HandlInst('1'), symbol, side, new TransactTime(DateTime.Now.ToUniversalTime()), new OrdType(OrdType.LIMIT)); orderNFO.Price = new Price((decimal)os.price); orderNFO.SetField(new OrderQty(Qty)); orderNFO.ExDestination = new ExDestination("NS"); orderNFO.SecurityType = new SecurityType(SecurityType.FUTURE); string expiry = new string(os.expiry); orderNFO.MaturityMonthYear = new MaturityMonthYear(expiry.Substring(0, 6)); orderNFO.Account = new Account("D2"); OrdType ordType = new OrdType(OrdType.LIMIT); if (os.orderType == 1) { ordType = new OrdType(OrdType.MARKET); } orderNFO.OrdType = ordType; Console.WriteLine("NFO BUY Order for ExpiryDate " + expiry.Substring(0, 6)); //Send Future order to fix server Session.SendToTarget(orderNFO, FixClient.MySess); } else if (os.direction == 'S') { Symbol symbol = new Symbol(symboldata); Side side = new Side(Side.SELL); int Qty = (int)os.quantity; var orderNFO = new QuickFix.FIX42.NewOrderSingle(OrdId, new HandlInst('1'), symbol, side, new TransactTime(DateTime.Now.ToUniversalTime()), new OrdType(OrdType.LIMIT)); orderNFO.Price = new Price((decimal)os.price); orderNFO.SetField(new OrderQty(Qty)); orderNFO.ExDestination = new ExDestination("NS"); orderNFO.SecurityType = new SecurityType(SecurityType.FUTURE); string expiry = new string(os.expiry); orderNFO.MaturityMonthYear = new MaturityMonthYear(expiry.Substring(0, 6)); orderNFO.Account = new Account("D2"); OrdType ordType = new OrdType(OrdType.LIMIT); if (os.orderType == 1) { ordType = new OrdType(OrdType.MARKET); } orderNFO.OrdType = ordType; Console.WriteLine("NFO SELL Order for ExpiryDate " + expiry.Substring(0, 6)); //Send Future order to fix server Session.SendToTarget(orderNFO, FixClient.MySess); } } else if (exch.Equals("NOP")) { if (os.direction == 'B') { Symbol symbol = new Symbol(symboldata); Side side = new Side(Side.BUY); int Qty = (int)os.quantity; string callput = new string(os.callput); var orderNOP = new QuickFix.FIX42.NewOrderSingle(OrdId, new HandlInst('1'), symbol, side, new TransactTime(DateTime.Now.ToUniversalTime()), new OrdType(OrdType.LIMIT)); orderNOP.Price = new Price((decimal)os.price); orderNOP.SetField(new OrderQty(Qty)); orderNOP.ExDestination = new ExDestination("NS"); orderNOP.SecurityType = new SecurityType(SecurityType.OPTION); string expiry = new string(os.expiry); orderNOP.MaturityMonthYear = new MaturityMonthYear(expiry.Substring(0, 6)); orderNOP.StrikePrice = new StrikePrice((decimal)(os.strike)); if (callput.Equals("CE")) // 0 = PE & 1 = CE { orderNOP.PutOrCall = new PutOrCall(1); } else if (callput.Equals("PE")) // 0 = PE & 1 = CE { orderNOP.PutOrCall = new PutOrCall(0); } orderNOP.Account = new Account("D2"); OrdType ordType = new OrdType(OrdType.LIMIT); if (os.orderType == 1) { ordType = new OrdType(OrdType.MARKET); } orderNOP.OrdType = ordType; Console.WriteLine("NOP BUY Order for ExpiryDate " + expiry.Substring(0, 6)); //Send Option order to fix server Session.SendToTarget(orderNOP, FixClient.MySess); } else if (os.direction == 'S') { Symbol symbol = new Symbol(symboldata); Side side = new Side(Side.SELL); int Qty = (int)os.quantity; string callput = new string(os.callput); var orderNOP = new QuickFix.FIX42.NewOrderSingle(OrdId, new HandlInst('1'), symbol, side, new TransactTime(DateTime.Now.ToUniversalTime()), new OrdType(OrdType.LIMIT)); orderNOP.Price = new Price((decimal)os.price); orderNOP.SetField(new OrderQty(Qty)); orderNOP.ExDestination = new ExDestination("NS"); orderNOP.SecurityType = new SecurityType(SecurityType.OPTION); string expiry = new string(os.expiry); orderNOP.MaturityMonthYear = new MaturityMonthYear(expiry.Substring(0, 6)); orderNOP.StrikePrice = new StrikePrice((decimal)(os.strike)); if (callput.Equals("CE")) // 0 = PE & 1 = CE { orderNOP.PutOrCall = new PutOrCall(1); } else if (callput.Equals("PE")) // 0 = PE & 1 = CE { orderNOP.PutOrCall = new PutOrCall(0); } orderNOP.Account = new Account("D2"); OrdType ordType = new OrdType(OrdType.LIMIT); if (os.orderType == 1) { ordType = new OrdType(OrdType.MARKET); } orderNOP.OrdType = ordType; Console.WriteLine("NOP SELL Order for ExpiryDate " + expiry.Substring(0, 6)); //Send Option order to fix server Session.SendToTarget(orderNOP, FixClient.MySess); } } return(ordNo); }