コード例 #1
0
ファイル: FIX42BnpClient.cs プロジェクト: radtek/Gradual
        public bool AlterarOrdem(OrdemInfo 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.OrderCancelReplaceRequest ordercrr = new QuickFix.FIX42.OrderCancelReplaceRequest();

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

            if (ordem.ExchangeNumberID != null && ordem.ExchangeNumberID.Length > 0)
            {
                ordercrr.Set(new OrderID(ordem.ExchangeNumberID));
            }

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

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

            // 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 ALTERAR 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 ALTERAR ORDEM========> Qtd: " + times);
            }
            else
            {
                bRet = Session.SendToTarget(ordercrr, _session.SessionID);
            }

            return(bRet);
        }
コード例 #2
0
        public bool AlterarOrdem(OrdemInfo ordem)
        {
            //Cria a mensagem FIX de NewOrderSingle
            QuickFix.FIX42.OrderCancelReplaceRequest ordercrr = new QuickFix.FIX42.OrderCancelReplaceRequest();

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

            if (ordem.ExchangeNumberID != null && ordem.ExchangeNumberID.Length > 0)
            {
                ordercrr.Set(new OrderID(ordem.ExchangeNumberID));
            }

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