Esempio n. 1
0
 /// <summary>
 /// Gets a string field; saves its value into the parameter object, which is also the return value.
 /// </summary>
 /// <param name="field">this field's tag is used to extract the value from the message; that value is saved back into this object</param>
 /// <exception cref="FieldNotFoundException">thrown if <paramref name="field"/> isn't found</exception>
 /// <returns><paramref name="field"/></returns>
 public Fields.StringField GetField(Fields.StringField field)
 {
     field.Obj = GetString(field.Tag);
     return(field);
 }
Esempio n. 2
0
        public bool CancelarOrdem(OrdemCancelamentoInfo ordem, long ini = 0, long fim = 0, long oriini = 0, long orifim = 0, int delay = 0, string mnemonic = "", string senderSubID = "", string extraTags = "")
        {
            //Cria a mensagem FIX de NewOrderSingle
            QuickFix.FIX42.OrderCancelRequest ordercrr = new QuickFix.FIX42.OrderCancelRequest();

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

            ordercrr.Set(new Symbol(ordem.Symbol));
            ordercrr.Set(new ClOrdID(ordem.ClOrdID));
            ordercrr.Set(new OrigClOrdID(ordem.OrigClOrdID));

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

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

            //TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce);
            //if (tif != null)
            //    ordercrr.Set(tif);

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

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

            ////OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType);
            ////if (ordType != null)
            ////    ordercrr.Set(ordType);

            // Verifica envio do preco
            //switch (ordem.OrdType)
            //{

            //    case OrdemTipoEnum.Limitada:
            //    case OrdemTipoEnum.MarketWithLeftOverLimit:
            //    case OrdemTipoEnum.StopLimitada:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        break;
            //    case OrdemTipoEnum.StopStart:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        ordercrr.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice)));
            //        break;
            //    case OrdemTipoEnum.Mercado:
            //    case OrdemTipoEnum.OnClose:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        break;
            //    default:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        break;
            //}

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

            //if (ordem.MaxFloor > 0)
            //    ordercrr.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor)));

            //if (ordem.MinQty > 0)
            //    ordercrr.Set(new MinQty(Convert.ToDecimal(ordem.MinQty)));

            //QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup();
            //noAllocsGrp.Set(new AllocAccount("67"));
            //ordercrr.AddGroup(noAllocsGrp);

            bool bRet = false;

            // 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]);
                        ordercrr.SetField(fld);
                    }
                }
            }
            if (oriini != 0 && orifim != 0)
            {
                long times = fim - ini;
                logger.Info("=====================================> INICIO CANCELAR ORDEM========> Qtd: " + times);
                for (long i = 0; i < times; i++)
                {
                    ClOrdID     xx  = new ClOrdID(ini.ToString());
                    OrigClOrdID xx2 = new OrigClOrdID(oriini.ToString());
                    ordercrr.ClOrdID     = xx;
                    ordercrr.OrigClOrdID = xx2;

                    bRet = Session.SendToTarget(ordercrr, _session.SessionID);
                    if (!bRet)
                    {
                        logger.Info("erro");
                        break;
                    }
                    if (0 != delay)
                    {
                        Thread.Sleep(delay);
                    }
                    ini++;
                    oriini++;
                }
                logger.Info("=====================================> FIM CANCELAR ORDEM========> Qtd: " + times);
            }
            else
            {
                bRet = Session.SendToTarget(ordercrr, _session.SessionID);
            }

            return(bRet);
        }
Esempio n. 3
0
        public bool CancelarOrdem(OrdemCancelamentoInfo ordem)
        {
            //Cria a mensagem FIX de NewOrderSingle
            QuickFix.FIX42.OrderCancelRequest ordercrr = new QuickFix.FIX42.OrderCancelRequest();

            ordercrr.Set(new Account(ordem.Account.ToString()));
            ordercrr.Set(new Symbol(ordem.Symbol));
            ordercrr.Set(new ClOrdID(ordem.ClOrdID));
            ordercrr.Set(new OrigClOrdID(ordem.OrigClOrdID));

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

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

            //TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce);
            //if (tif != null)
            //    ordercrr.Set(tif);

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

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

            ////OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType);
            ////if (ordType != null)
            ////    ordercrr.Set(ordType);

            // Verifica envio do preco
            //switch (ordem.OrdType)
            //{

            //    case OrdemTipoEnum.Limitada:
            //    case OrdemTipoEnum.MarketWithLeftOverLimit:
            //    case OrdemTipoEnum.StopLimitada:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        break;
            //    case OrdemTipoEnum.StopStart:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        ordercrr.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice)));
            //        break;
            //    case OrdemTipoEnum.Mercado:
            //    case OrdemTipoEnum.OnClose:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        break;
            //    default:
            //        ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price)));
            //        break;
            //}

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

            //if (ordem.MaxFloor > 0)
            //    ordercrr.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor)));

            //if (ordem.MinQty > 0)
            //    ordercrr.Set(new MinQty(Convert.ToDecimal(ordem.MinQty)));

            //QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup();
            //noAllocsGrp.Set(new AllocAccount("67"));
            //ordercrr.AddGroup(noAllocsGrp);

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

            return(bRet);
        }
Esempio n. 4
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 tag115 = "", 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(tag115))
            {
                ordersingle.Header.SetField(new OnBehalfOfCompID(tag115));
            }

            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);
        }
Esempio n. 5
0
 public void GetField(Fields.StringField field)
 {
     field.Obj = GetString(field.Tag);
 }