private void fillOrderInfoForICE(QuickFix.FIX42.NewOrderSingle order, OrderModel orderModel)
        {
            if (orderModel.TAG47_Rule80A.useTag)
            {
                order.Rule80A = new Rule80A(orderModel.TAG47_Rule80A.tagCharValue);
            }

            if (orderModel.TAG204_CustomerOrFirm.useTag)
            {
                order.CustomerOrFirm = new CustomerOrFirm(orderModel.TAG204_CustomerOrFirm.tagIntValue);
            }

            if (orderModel.TAG18205_TTAccountType.useTag)
            {
                order.SetField(new StringField(18205, orderModel.TAG18205_TTAccountType.tagStringValue));
            }

            if (orderModel.TAG440_ClearingAccount.useTag)
            {
                order.ClearingAccount = new ClearingAccount(orderModel.TAG440_ClearingAccount.tagStringValue);
            }

            if (orderModel.TAG16102_FFT2.useTag)
            {
                order.SetField(new StringField(16102, orderModel.TAG16102_FFT2.tagStringValue));
            }
        }
        private QuickFix.FIX42.NewOrderSingle createHeldOptionOrder(Model.OrderModel orderModel)
        {
            var order = new QuickFix.FIX42.NewOrderSingle(
                new ClOrdID(orderModel.messageId),
                new HandlInst('1'),
                new Symbol(orderModel.underlyingExchangeSymbol),
                StageOrdersToTTWPFLibrary.FixEnumTranslator.ToField(orderModel.side),
                new TransactTime(DateTime.Now),
                new OrdType(OrdType.LIMIT));

            order.SecurityType = StageOrdersToTTWPFLibrary.FixEnumTranslator.ToField(orderModel.securityType);

            order.SecurityExchange = new SecurityExchange(orderModel.underlyingExchange);

            order.SetField(new StringField(18203, orderModel.underlyingGateway));

            order.PutOrCall = StageOrdersToTTWPFLibrary.FixEnumTranslator.ToField(orderModel.optionType);

            order.StrikePrice = new StrikePrice(orderModel.optionStrikePrice);  //new StrikePrice(new decimal(207000));

            order.MaturityMonthYear = new MaturityMonthYear(orderModel.maturityMonthYear);

            order.OrderQty = new OrderQty(orderModel.orderQty);


            order.SetField(new CharField(11028, 'Y'));

            //order.SetField(new StringField(50, "TML1"));

            //order.SetField(new StringField(16142, "TML NORTH VANCOUVER"));

            order.SetField(new StringField(18220, orderModel.broker_18220));

            //order.SetField(new StringField(16106, orderModel.stagedOrderMessage));

            order.SetField(new CharField(16111, 'I'));

            order.Account = new Account(orderModel.acct);

            order.Price = new Price(orderModel.orderPrice);

            order.ExecInst = new ExecInst("5");


            fillOrderInfoForICE(order, orderModel);


            //OrderRecord r = new OrderRecord(order);
            //lock (_orderViewModel.ordersLock)
            //{
            //    _orderViewModel.Orders.Add(r);
            //}

            //if (_fixConnectionSystem.InitiatorRunning && _connectionViewModel.IsOrderConnected)
            //{
            //    QuickFix.Session.SendToTarget(order, _fixConnectionSystem.orderSession.SessionID);
            //}

            return(order);
        }
        private QuickFix.FIX42.NewOrderSingle createStagedFutureOrder(Model.OrderModel orderModel)
        {
            var order = new QuickFix.FIX42.NewOrderSingle(
                new ClOrdID(orderModel.messageId),
                new HandlInst('3'),
                new Symbol(orderModel.underlyingExchangeSymbol),
                StageOrdersToTTWPFLibrary.FixEnumTranslator.ToField(orderModel.side),
                new TransactTime(DateTime.Now),
                new OrdType(OrdType.LIMIT));

            //if(order.Side.Obj == Side.BUY)

            //switch (order.Side.Obj)
            //{
            //    case QuickFix.Fields.Side.BUY:
            //        Console.Write("t");
            //        break;
            //    case QuickFix.Fields.Side.SELL:
            //        Console.Write("t");
            //        break;
            //}



            order.SecurityType = StageOrdersToTTWPFLibrary.FixEnumTranslator.ToField(orderModel.securityType);

            order.SecurityExchange = new SecurityExchange(orderModel.underlyingExchange);

            order.SetField(new StringField(18203, orderModel.underlyingGateway));

            order.MaturityMonthYear = new MaturityMonthYear(orderModel.maturityMonthYear);

            order.OrderQty = new OrderQty(orderModel.orderQty);

            //order.Price = new Price(new decimal(207175));

            order.SetField(new CharField(11028, 'Y'));

            //order.SetField(new StringField(50, "TML1"));

            //order.SetField(new StringField(16142, "TML NORTH VANCOUVER"));

            order.SetField(new StringField(18220, orderModel.broker_18220));

            order.SetField(new StringField(16106, orderModel.stagedOrderMessage));

            order.SetField(new CharField(16111, 'I'));

            order.Account = new Account(orderModel.acct);

            order.Price = new Price(0);


            fillOrderInfoForICE(order, orderModel);


            return(order);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a NewOrderSingle message.
        /// </summary>
        /// <param name="customFields"></param>
        /// <param name="orderType"></param>
        /// <param name="side"></param>
        /// <param name="symbol"></param>
        /// <param name="orderQty"></param>
        /// <param name="tif"></param>
        /// <param name="price">ignored if orderType=Market</param>
        /// <returns></returns>
        static public QuickFix.FIX42.NewOrderSingle NewOrderSingle(
            Dictionary <int, string> customFields,
            OrderType orderType, Side side, string symbol,
            int orderQty, TimeInForce tif, decimal price)
        {
            // hard-coded fields
            QuickFix.Fields.HandlInst fHandlInst = new QuickFix.Fields.HandlInst(QuickFix.Fields.HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE);

            // from params
            QuickFix.Fields.OrdType      fOrdType      = FixEnumTranslator.ToField(orderType);
            QuickFix.Fields.Side         fSide         = FixEnumTranslator.ToField(side);
            QuickFix.Fields.Symbol       fSymbol       = new QuickFix.Fields.Symbol(symbol);
            QuickFix.Fields.TransactTime fTransactTime = new QuickFix.Fields.TransactTime(DateTime.Now);
            QuickFix.Fields.ClOrdID      fClOrdID      = GenerateClOrdID();

            QuickFix.FIX42.NewOrderSingle nos = new QuickFix.FIX42.NewOrderSingle(
                fClOrdID, fHandlInst, fSymbol, fSide, fTransactTime, fOrdType);
            nos.OrderQty    = new QuickFix.Fields.OrderQty(orderQty);
            nos.TimeInForce = FixEnumTranslator.ToField(tif);

            if (orderType == OrderType.Limit)
            {
                nos.Price = new QuickFix.Fields.Price(price);
            }

            // add custom fields
            foreach (KeyValuePair <int, string> p in customFields)
            {
                nos.SetField(new QuickFix.Fields.StringField(p.Key, p.Value));
            }

            return(nos);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a NewOrderSingle message.
        /// </summary>
        /// <param name="customFields"></param>
        /// <param name="orderType"></param>
        /// <param name="side"></param>
        /// <param name="symbol"></param>
        /// <param name="orderQty"></param>
        /// <param name="tif"></param>
        /// <param name="price">ignored if orderType=Market</param>
        /// <returns></returns>
        static public QuickFix.FIX42.NewOrderSingle NewOrderSingle(
            Dictionary<int,string> customFields,
            OrderType orderType, Side side, string symbol,
            int orderQty, TimeInForce tif, decimal price)
        {
            // hard-coded fields
            QuickFix.Fields.HandlInst fHandlInst = new QuickFix.Fields.HandlInst(QuickFix.Fields.HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE);
            
            // from params
            QuickFix.Fields.OrdType fOrdType = FixEnumTranslator.ToField(orderType);
            QuickFix.Fields.Side fSide = FixEnumTranslator.ToField(side);
            QuickFix.Fields.Symbol fSymbol = new QuickFix.Fields.Symbol(symbol);
            QuickFix.Fields.TransactTime fTransactTime = new QuickFix.Fields.TransactTime(DateTime.Now);
            QuickFix.Fields.ClOrdID fClOrdID = GenerateClOrdID();

            QuickFix.FIX42.NewOrderSingle nos = new QuickFix.FIX42.NewOrderSingle(
                fClOrdID, fHandlInst, fSymbol, fSide, fTransactTime, fOrdType);
            nos.OrderQty = new QuickFix.Fields.OrderQty(orderQty);
            nos.TimeInForce = FixEnumTranslator.ToField(tif);

            if (orderType == OrderType.Limit)
                nos.Price = new QuickFix.Fields.Price(price);

            // add custom fields
            foreach (KeyValuePair<int,string> p in customFields)
                nos.SetField(new QuickFix.Fields.StringField(p.Key, p.Value));

            return nos;
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a FIX4.2 NewOrderSingle message for Redi
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public QuickFix.FIX42.NewOrderSingle NewOrderSingle(Order order)
        {
            var newOrderSingle = new QuickFix.FIX42.NewOrderSingle();

            var clOrdId = new QuickFix.Fields.ClOrdID(order.OrderID);

            newOrderSingle.SetField(clOrdId);

            if (!string.IsNullOrEmpty(_account))
            {
                var account = new QuickFix.Fields.Account(_account);
                newOrderSingle.SetField(account);
            }

            var currency = new QuickFix.Fields.Currency(order.OrderCurrency);

            newOrderSingle.SetField(currency);

            var handlInst = new QuickFix.Fields.HandlInst(HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE);

            newOrderSingle.SetField(handlInst);

            //only limit and market orders are supported.
            if (order.GetType() == typeof(LimitOrder))
            {
                var execInst = new QuickFix.Fields.ExecInst("h");
                newOrderSingle.SetField(execInst);

                newOrderSingle.Set(new OrdType(OrdType.LIMIT));
                newOrderSingle.Set(new Price(((LimitOrder)order).LimitPrice));
            }
            else if (order.GetType() == typeof(MarketOrder))
            {
                newOrderSingle.Set(new OrdType(OrdType.MARKET));
            }

            var orderQty = new QuickFix.Fields.OrderQty(order.OrderSize);

            newOrderSingle.SetField(orderQty);

            var exDestination = new QuickFix.Fields.ExDestination(";");

            newOrderSingle.SetField(exDestination);

            var country = new QuickFix.Fields.DeliverToLocationID("1");

            newOrderSingle.SetField(country);

            var side = new QuickFix.Fields.Side(Convert.ToChar(order.OrderSide));

            newOrderSingle.SetField(side);

            var symbol = new QuickFix.Fields.Symbol(order.Security.Symbol);

            newOrderSingle.SetField(symbol);

            var tif = new QuickFix.Fields.TimeInForce(FixCommon.Converter.ConvertTif.GetFixValue(order.OrderTif));

            newOrderSingle.SetField(tif);

            var transactTime = new QuickFix.Fields.TransactTime(order.OrderDateTime);

            newOrderSingle.SetField(transactTime);

            return(newOrderSingle);
        }