Exemple #1
0
        /// <summary>
        /// Creates a FIX4.2 NewOrderSingle message for Currenex
        /// </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);

            var securityType = new QuickFix.Fields.SecurityType(FixCommon.Constants.SecurityType.ForeignExchangeContract);

            newOrderSingle.SetField(securityType);

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

            newOrderSingle.SetField(symbol);

            //set order side
            if (order.OrderSide == Constants.OrderSide.BUY)
            {
                newOrderSingle.Set(new Side(Side.BUY));
            }
            else if (order.OrderSide == Constants.OrderSide.SELL)
            {
                newOrderSingle.Set(new Side(Side.SELL));
            }

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

            newOrderSingle.SetField(transactTime);

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

            newOrderSingle.SetField(orderQty);

            var minQty = new QuickFix.Fields.MinQty(order.OrderSize);

            newOrderSingle.SetField(minQty);

            //only limit and market orders are supported.
            if (order.GetType() == typeof(LimitOrder))
            {
                newOrderSingle.Set(new OrdType('F'));
                newOrderSingle.Set(new Price(((LimitOrder)order).LimitPrice));
            }
            else if (order.GetType() == typeof(MarketOrder))
            {
                newOrderSingle.Set(new OrdType('C'));
            }

            //if (order.OrderSize != order.OrderSizeToShow)
            //{
            //    var maxShow = new QuickFix.Fields.MaxShow(order.OrderSizeToShow);
            //    newOrderSingle.SetField(maxShow);
            //}

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

            newOrderSingle.SetField(tif);

            var execInst = new QuickFix.Fields.ExecInst(ExecInst.BEST_EXECUTION);

            newOrderSingle.SetField(execInst);

            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);

            return(newOrderSingle);
        }
Exemple #2
0
        // public bool EnviarOrdemCross(OrdemCrossInfo info) { return false; }

        public bool EnviarOrdem(OrdemInfo ordem, long ini = 0, long fim = 0, int delay = 0, string mnemonic = "", string senderSubID = "", string extraTags = "")
        {
            //Cria a mensagem FIX de NewOrderSingle
            QuickFix.FIX42.NewOrderSingle ordersingle = new QuickFix.FIX42.NewOrderSingle();

            ordersingle.Set(new Account(ordem.Account.ToString()));
            if (!string.IsNullOrEmpty(mnemonic))
            {
                ordersingle.SetField(new Account(mnemonic), true);
            }
            if (!string.IsNullOrEmpty(senderSubID))
            {
                ordersingle.Header.SetField(new SenderSubID(senderSubID));
            }

            ordersingle.Set(new Symbol(ordem.Symbol));
            ordersingle.Set(new ClOrdID(ordem.ClOrdID));

            // Armazena ClOrdID em Memo (5149) para posterior referência nos tratamentos de retornos
            QuickFix.Fields.StringField field5149 = new QuickFix.Fields.StringField(5149, ordem.ClOrdID);
            ordersingle.SetField(field5149);

            //ordersingle.Set(new IDSource());
            if (ordem.Side == OrdemDirecaoEnum.Venda)
            {
                ordersingle.Set(new Side(Side.SELL));
            }
            else
            {
                ordersingle.Set(new Side(Side.BUY));
            }

            TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce);

            if (tif != null)
            {
                ordersingle.Set(tif);
            }

            ordersingle.Set(new OrderQty(ordem.OrderQty));

            if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData)
            {
                DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate);
                ordersingle.Set(new ExpireDate(expiredate.ToString("yyyyMMdd")));
            }

            OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType);

            if (ordType != null)
            {
                ordersingle.Set(ordType);
            }

            // Para versao 4.2, os novos tipos de OrdType a serem enviados (5, A ou B);
            if (!string.IsNullOrEmpty(ordem.Memo5149))
            {
                ordersingle.SetField(new OrdType(Convert.ToChar(ordem.Memo5149)), true);
            }

            // Verifica envio do preco
            switch (ordem.OrdType)
            {
            case OrdemTipoEnum.Limitada:
            case OrdemTipoEnum.MarketWithLeftOverLimit:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                break;

            case OrdemTipoEnum.StopLimitada:
            case OrdemTipoEnum.StopStart:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                ordersingle.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice)));
                break;

            case OrdemTipoEnum.Mercado:
            case OrdemTipoEnum.OnClose:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                break;

            default:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                break;
            }

            ordersingle.Set(new TransactTime(DateTime.Now));
            ordersingle.Set(new HandlInst('1'));

            ordersingle.Set(new ExecBroker("227"));

            if (ordem.MaxFloor > 0)
            {
                ordersingle.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor)));
            }

            if (ordem.MinQty > 0)
            {
                ordersingle.Set(new MinQty(Convert.ToDecimal(ordem.MinQty)));
            }

            // Tags Customizadas Bloomberg
            if (!string.IsNullOrEmpty(extraTags))
            {
                string[] arr = extraTags.Split(';');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (!string.IsNullOrEmpty(arr[i]))
                    {
                        string []   valor = arr[i].Split('=');
                        StringField fld   = new StringField(Convert.ToInt32(valor[0]), valor[1]);
                        ordersingle.SetField(fld);
                    }
                }
            }

            QuickFix.FIX42.NewOrderSingle.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.NewOrderSingle.NoAllocsGroup();
            noAllocsGrp.Set(new AllocAccount("67"));
            ordersingle.AddGroup(noAllocsGrp);
            bool bRet = false;

            if (ini == 0)
            {
                bRet = Session.SendToTarget(ordersingle, _session.SessionID);
            }
            else
            {
                long times = fim - ini;
                logger.Info("=====================================> INICIO ========> Qtd: " + times);
                for (long i = 0; i < times; i++)
                {
                    ClOrdID xx = new ClOrdID(ini.ToString());
                    ordersingle.ClOrdID = xx;
                    bRet = Session.SendToTarget(ordersingle, _session.SessionID);
                    if (!bRet)
                    {
                        logger.Info("erro");
                        break;
                    }
                    if (0 != delay)
                    {
                        Thread.Sleep(delay);
                    }
                    ini++;
                }
                logger.Info("=====================================> FIM ========> Qtd: " + times);
            }
            return(bRet);
        }
Exemple #3
0
        public bool EnviarOrdem(OrdemInfo ordem)
        {
            //Cria a mensagem FIX de NewOrderSingle
            QuickFix.FIX42.NewOrderSingle ordersingle = new QuickFix.FIX42.NewOrderSingle();

            ordersingle.Set(new Account(ordem.Account.ToString()));
            ordersingle.Set(new Symbol(ordem.Symbol));
            ordersingle.Set(new ClOrdID(ordem.ClOrdID));

            // Armazena ClOrdID em Memo (5149) para posterior referência nos tratamentos de retornos
            QuickFix.Fields.StringField field5149 = new QuickFix.Fields.StringField(5149, ordem.ClOrdID);
            ordersingle.SetField(field5149);

            //ordersingle.Set(new IDSource());
            if (ordem.Side == OrdemDirecaoEnum.Venda)
            {
                ordersingle.Set(new Side(Side.SELL));
            }
            else
            {
                ordersingle.Set(new Side(Side.BUY));
            }

            TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce);

            if (tif != null)
            {
                ordersingle.Set(tif);
            }

            ordersingle.Set(new OrderQty(ordem.OrderQty));

            if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData)
            {
                DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate);
                ordersingle.Set(new ExpireDate(expiredate.ToString("yyyyMMdd")));
            }

            OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType);

            if (ordType != null)
            {
                ordersingle.Set(ordType);
            }

            // Verifica envio do preco
            switch (ordem.OrdType)
            {
            case OrdemTipoEnum.Limitada:
            case OrdemTipoEnum.MarketWithLeftOverLimit:
            case OrdemTipoEnum.StopLimitada:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                break;

            case OrdemTipoEnum.StopStart:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                ordersingle.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice)));
                break;

            case OrdemTipoEnum.Mercado:
            case OrdemTipoEnum.OnClose:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                break;

            default:
                ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price)));
                break;
            }

            ordersingle.Set(new TransactTime(DateTime.Now));
            ordersingle.Set(new HandlInst('1'));
            ordersingle.Set(new ExecBroker("227"));

            if (ordem.MaxFloor > 0)
            {
                ordersingle.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor)));
            }

            if (ordem.MinQty > 0)
            {
                ordersingle.Set(new MinQty(Convert.ToDecimal(ordem.MinQty)));
            }

            QuickFix.FIX42.NewOrderSingle.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.NewOrderSingle.NoAllocsGroup();
            noAllocsGrp.Set(new AllocAccount("67"));
            ordersingle.AddGroup(noAllocsGrp);

            bool bRet = Session.SendToTarget(ordersingle, _session.SessionID);

            return(bRet);
        }