public void MakeMessage(Message m, string fix)
        {
            idx = 0; prevIdx = 0;

            // Handle first field differently, no SOH at start.
            StringField sf = new StringField(0);
            idx = fix.IndexOf('\x01');
            if (idx != -1)
            {
                field = fix.Substring(prevIdx, (idx - prevIdx));
                tagIndex = field.IndexOf('=');

                sf.Tag = IntParse(field.Substring(0, tagIndex));
                sf.Obj = field.Substring(tagIndex + 1);
                m.setField(sf);
            }
            else return;

            while (idx != -1)
            {
                prevIdx = idx;
                idx = fix.IndexOf('\x01', prevIdx + 1);

                if (idx == -1) break;

                StringField sf2 = new StringField(0);
                field = fix.Substring(prevIdx + 1, (idx - prevIdx) - 1);
                tagIndex = field.IndexOf('=');

                sf2.Tag = IntParse(field.Substring(0, tagIndex));
                sf2.Obj = field.Substring(tagIndex + 1);
                m.setField(sf2);
            }
        }
 long ServerQuickFix_newSendOrderRequest(Order o)
 {
     QuickFix.Message        message = new QuickFix.Message();
     QuickFix.Message.Header header  = message.getHeader();
     header.setField(new BeginString(FIXID));
     header.setField(new SenderCompID(SenderCompId));
     header.setField(new TargetCompID(TargetCompId));
     header.setField(new MsgType(CANCEL));
     message.setField(new OrigClOrdID(o.id.ToString()));
     message.setField(new ClOrdID(o.id.ToString()));
     message.setField(new Symbol(o.symbol));
     message.setField(new Side(o.side ? Side.BUY : Side.SELL));
     //message.setField(new Text("Cancel My Order!"));
     Session.sendToTarget(message);
     return(0);
 }
        public override void toAdmin(QuickFix.Message message, QuickFix.SessionID sessionID)
        {
            base.toAdmin(message, sessionID);

            if (message is QuickFix42.Logon)
            {
                message.setField(new ResetSeqNumFlag(true));

                GSFIX gsfix = provider as GSFIX;

                string encrypt_pwd      = gsfix.Password;
                byte[] encrypt_pwd_byte = new byte[128];
                switch (gsfix.EncryptType)
                {
                case EncryptType.NONE:
                    message.setField(new EncryptMethod(EncryptMethod.NONE));
                    break;

                case EncryptType.DESECB:
                    gsEncrypt(2, gsfix.Password, gsfix.Password.Length, gsfix.PublicKey, encrypt_pwd_byte, 128);
                    encrypt_pwd = Encoding.ASCII.GetString(encrypt_pwd_byte);
                    message.setField(new EncryptMethod(EncryptMethod.DESECBMODE));
                    break;

                case EncryptType.BlowFish:
                    gsEncrypt(101, gsfix.Password, gsfix.Password.Length, gsfix.PublicKey, encrypt_pwd_byte, 128);
                    encrypt_pwd = Encoding.ASCII.GetString(encrypt_pwd_byte);
                    message.setField(new EncryptMethod((int)EncryptType.BlowFish));
                    break;

                default:
                    break;
                }

                if (!string.IsNullOrEmpty(gsfix.Account) && !string.IsNullOrEmpty(gsfix.CreditAccount))
                {
                    message.setField(new RawData(string.Format("T:{0},{1}:{2}:", gsfix.Account, gsfix.CreditAccount, encrypt_pwd.ToString())));
                }
                else if (!string.IsNullOrEmpty(gsfix.Account))
                {
                    message.setField(new RawData(string.Format("Z:{0}:{1}:", gsfix.Account, encrypt_pwd.ToString())));
                }
                else if (!string.IsNullOrEmpty(gsfix.CreditAccount))
                {
                    message.setField(new RawData(string.Format("X:{0}:{1}:", gsfix.CreditAccount, encrypt_pwd.ToString())));
                }
                else
                {
                    message.setField(new RawData(string.Format("T:{0},{1}:{2}:", gsfix.Account, gsfix.CreditAccount, encrypt_pwd.ToString())));
                }
            }
        }
Exemple #4
0
        /**
         * Callback chamado logo antes do envio da mensagem FIX de controle de sessão.
         *
         */
        public void toAdmin(QuickFix.Message message, SessionID sessionId)
        {
            try
            {
                // Se for mensagem de Logon, inclui o RawData e RawDataLength na mensagem
                if (message.getHeader().getString(MsgType.FIELD).Equals("A"))
                {
                    message.setBoolean(ResetSeqNumFlag.FIELD, true);
                    message.setInt(NextExpectedMsgSeqNum.FIELD,
                                   (new NextExpectedMsgSeqNum(ConstantesMDS.BMF_SEQNUM_INICIAL)).getValue());

                    message.setField(RawData.FIELD, new RawData(senha).ToString());
                    message.setField(RawDataLength.FIELD, new RawDataLength(senha.Length).ToString());

                    if (novaSenha != null && novaSenha.Length > 0)
                    {
                        message.setField(NewPassword.FIELD, new NewPassword(novaSenha).ToString());
                        logger.Info("Enviada nova senha para alteracao!");
                    }
                }
                else if (message.getHeader().getString(MsgType.FIELD).Equals("5"))
                {
                    if (assinados)
                    {
                        cancelaInstrumentos();
                    }
                }

                logger.Debug("SEND(SES) --> " + message.ToString());
            }

            catch (FieldNotFound e)
            {
                logger.Error("Campo nao encontrado: " + e.Message, e);
            }
        }
Exemple #5
0
 long ServerQuickFix_newSendOrderRequest(Order o)
 {
     QuickFix.Message message = new QuickFix.Message();
     QuickFix.Message.Header header = message.getHeader();
     header.setField(new BeginString(FIXID));
     header.setField(new SenderCompID(SenderCompId));
     header.setField(new TargetCompID(TargetCompId));
     header.setField(new MsgType(CANCEL));
     message.setField(new OrigClOrdID(o.id.ToString()));
     message.setField(new ClOrdID(o.id.ToString()));
     message.setField(new Symbol(o.symbol));
     message.setField(new Side(o.side ? Side.BUY : Side.SELL));
     //message.setField(new Text("Cancel My Order!"));
     Session.sendToTarget(message);
     return 0;
     
 }
        private static bool AddBidAskQueryClause(Message msg, string ticker)
        {
            var simGroup = new QuickFix44.MarketDataRequest.NoRelatedSym(); // 146=1

            // подписаться на символ по его коду?
            if (subscribeBySecurityId)
            {
                int tickerCode;
                if (!TickerCodeDictionary.Instance.tickerCode.TryGetValue(ticker, out tickerCode))
                {
                    Logger.ErrorFormat("Запрос котировки {0} - нет кода", ticker);
                    return false;
                }

                simGroup.setField(new SecurityID(tickerCode.ToString())); // 48=4006 symbol
                simGroup.setField(new SecurityIDSource("8")); // 22=8 symbol
            }
            else
            // подписаться по названию
            {
                simGroup.setField(new Symbol(TickerCodeDictionary.Instance.GetTickerNameFormatted(ticker)));
            }

            // два отдельных запроса на bid-ask?
            if (distinctQueriesForBidAsk)
            {
                var group = new QuickFix44.MarketDataRequest.NoMDEntryTypes(); // 267=2
                group.setField(new MDEntryType('0')); // 269=0 (bid)
                simGroup.addGroup(group);

                group = new QuickFix44.MarketDataRequest.NoMDEntryTypes();
                group.setField(new MDEntryType('1')); // 269=1 (offer)
                simGroup.addGroup(group);
            }
            else
            // один запрос
            {
                var group = new QuickFix44.MarketDataRequest.NoMDEntryTypes(); // 267=2
                group.setField(new MDEntryType('2')); // 269=0 (bid + offer)
                simGroup.addGroup(group);
            }
            msg.addGroup(simGroup);

            msg.setField(new NoRelatedSym(1)); // 1 subscription
            msg.setField(new Symbol(ticker));

            return true;
        }
		protected void SetUserDefinedFields(FIXMessage Message, Message message)
		{
			foreach (FIXField fixField in Message.Fields)
			{
				if (fixField.Tag >= 500)
				{
					switch (fixField.FIXType)
					{
						case FIXType.Bool:
							message.setField(new BooleanField(fixField.Tag, ((FIXBoolField)fixField).Value));
							continue;
						case FIXType.Int:
							message.setField(new IntField(fixField.Tag, ((FIXIntField)fixField).Value));
							continue;
						case FIXType.Double:
							message.setField(new DoubleField(fixField.Tag, ((FIXDoubleField)fixField).Value));
							continue;
						case FIXType.Char:
							message.setField(new CharField(fixField.Tag, ((FIXCharField)fixField).Value));
							continue;
						case FIXType.String:
							message.setField(new StringField(fixField.Tag, ((FIXStringField)fixField).Value));
							continue;
						case FIXType.DateTime:
							message.setField((UtcDateOnlyField)new UtcDateField(fixField.Tag, ((FIXDateTimeField)fixField).Value));
							continue;
						default:
							continue;
					}
				}
			}
		}