コード例 #1
0
        public override void onMessage(QuickFix44.MarketDataSnapshotFullRefresh message, SessionID session)
        {
            // getting attributes

            Symbol      symbol      = message.getSymbol();
            SendingTime sendingTime = new SendingTime(message.getHeader().getUtcTimeStamp(SendingTime.FIELD));
            NoMDEntries noMDEntries = message.getNoMDEntries();

            decimal ask     = 0m;
            decimal bid     = 0m;
            decimal askSize = 0m;
            decimal bidSize = 0m;

            for (int i = 0; i < noMDEntries.getValue(); i++)
            {
                QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries group = new QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries();
                message.getGroup((uint)i + 1, group);
                MDEntryType mdEntryType = group.getMDEntryType();
                MDEntryPx   mdEntryPx   = group.getMDEntryPx();
                MDEntrySize mdEntrySize = group.getMDEntrySize();

                if (mdEntryType.getValue() == MDEntryType.BID)
                {
                    bid     = (decimal)mdEntryPx.getValue();
                    bidSize = (decimal)mdEntrySize.getValue();
                }
                else if (mdEntryType.getValue() == MDEntryType.OFFER)
                {
                    ask     = (decimal)mdEntryPx.getValue();
                    askSize = (decimal)mdEntrySize.getValue();
                }
            }

            // firing event

            Console.WriteLine("QuickFix44.MarketDataSnapshotFullRefresh: {0}, {1}/{2}, {3}/{4}, {5}", symbol, ask, bid, askSize, bidSize, sendingTime);

            this.fixServices.NotifyQuote(Counterpart.Dukascopy, symbol.getValue(), ask, askSize, bid, bidSize, sendingTime.getValue());
        }
コード例 #2
0
        public static void ProcessMsgMarketDataIncrRefresh(Message msgOrig, FixMessage msg)
        {
            loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                     LogMagicMarketData, 1000 * 60 * 60 * 2, "Quote incr: {0}", msg.ToString());

            try
            {
                // информация по тикерам разбита на группы, каждому тикеру - по группе
                var groupHeader = new NoMDEntries();
                msgOrig.getField(groupHeader);
                int numGroups = groupHeader.getValue();

                var group = FixMessage.FixVersion == FixVersion.Fix42
                                ? new QuickFix42.MarketDataIncrementalRefresh.NoMDEntries()
                                : FixMessage.FixVersion == FixVersion.Fix43
                                      ? (Group) new QuickFix43.MarketDataIncrementalRefresh.NoMDEntries()
                                      : new QuickFix44.MarketDataIncrementalRefresh.NoMDEntries();

                var lastQuotes = new System.Collections.Generic.Dictionary <string, QuoteData>();

                for (var i = 1; i <= numGroups; i++)
                {
                    var groupTicker = msgOrig.getGroup((uint)i, group);
                    var symbol      = groupTicker.getField(new Symbol()).getValue();

                    if (!ConvertFromProviderSymbolNaming(ref symbol))
                    {
                        return;
                    }

                    var entType     = new MDEntryType();
                    var entTypeChar = groupTicker.getField(entType).getValue();
                    var priceType   = entTypeChar == FixMessage.VALUE_MD_ENTRY_TYPE_BID[0]
                                        ? Contract.Entity.QuoteType.Bid
                                        : entTypeChar == FixMessage.VALUE_MD_ENTRY_TYPE_OFFER[0]
                                              ? Contract.Entity.QuoteType.Ask
                                              : Contract.Entity.QuoteType.NonSpecified;
                    if (priceType == Contract.Entity.QuoteType.NonSpecified)
                    {
                        continue;
                    }
                    var price = msg.GetValueFloat(FixMessage.TAG_MD_ENTRY_PX) ?? 0;
                    if (price == 0)
                    {
                        continue;
                    }

                    if (lastQuotes.ContainsKey(symbol))
                    {
                        var quote = lastQuotes[symbol];
                        if (priceType == Contract.Entity.QuoteType.Bid)
                        {
                            quote.bid = price;
                        }
                        else
                        {
                            quote.ask = price;
                        }
                    }
                    else
                    {
                        lastQuotes.Add(symbol, new QuoteData(
                                           priceType == Contract.Entity.QuoteType.Bid ? price : 0,
                                           priceType == Contract.Entity.QuoteType.Ask ? price : 0, DateTime.Now));
                    }
                }

                foreach (var quote in lastQuotes)
                {
                    loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                             LogMagicQuote, 1000 * 60 * 15,
                                                             "Котировка {0}: {1} - {2}",
                                                             quote.Key, quote.Value.bid, quote.Value.ask);

                    QuoteDistributor.Instance.UpdateQuote(quote.Key,
                                                          quote.Value.bid == 0 ? (float?)null : quote.Value.bid,
                                                          quote.Value.ask == 0 ? (float?)null : quote.Value.ask);
                }

                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataSuccess,
                                                         1000 * 60 * 10, "Обработан пакет MarketDataIncrRefresh");
            }
            catch (Exception ex)
            {
                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataError,
                                                         1000 * 60 * 10, "Ошибка разбора MarketDataIncrRefresh: {0}", ex);
            }
        }
コード例 #3
0
        public static void ProcessMsgMarketDataFullRefresh(Message msgOrig, FixMessage msg)
        {
            loggerNoFlood.LogMessageFormatCheckFlood(
                LogEntryType.Info,
                LogMagicMarketData,
                1000 * 60 * 60 * 2, "Quote full: {0}", msg.ToString());

            // 8=FIX.4.4#9=128#35=W#34=2#49=XTB#52=20141125-16:12:33.269#56=PARTNER1#55=USDJPY..#262=USDJPY-25-16-12#268=2#269=0#270=117.906#10=097#

            try
            {
                var reqIdField = msgOrig.getField(new MDReqID());
                if (reqIdField == null)
                    throw new Exception("Поле MDReqID не прочитано");
                // инструмент указан в самом запросе
                var requestedSymbol = msg.GetValueString(FixMessage.TAG_SYMBOL);
                //requestedSymbol = TickerCodeDictionary.Instance.GetClearTickerName(requestedSymbol);
                // котировка будет исправлена в дальнейшем

                var groupHeader = new NoMDEntries();
                msgOrig.getField(groupHeader);
                var numGroups = groupHeader.getValue();

                if (numGroups == 0)
                    throw new Exception("Поле NoMDEntries не прочитано");

                var group = FixMessage.FixVersion == FixVersion.Fix42
                                ? new QuickFix42.MarketDataIncrementalRefresh.NoMDEntries()
                                : FixMessage.FixVersion == FixVersion.Fix43
                                      ? (Group)new QuickFix43.MarketDataIncrementalRefresh.NoMDEntries()
                                      : new QuickFix44.MarketDataIncrementalRefresh.NoMDEntries();

                float bid = 0, ask = 0;
                for (var i = 1; i <= numGroups; i++)
                {
                    var groupTicker = msgOrig.getGroup((uint)i, group);
                    // тип (бид или аск)
                    var isBid = true;
                    var typeField = groupTicker.getField(new MDEntryType());
                    if (typeField == null)
                        throw new Exception("Поле MDEntryType не прочитано");
                    isBid = typeField.getValue() == '0';
                    // цена
                    var priceField = group.getField(new MDEntryPx());
                    if (priceField == null)
                        throw new Exception("Поле MDEntryPx не прочитано");
                    var price = priceField.getValue();
                    if (isBid)
                        bid = (float)price;
                    else
                        ask = (float)price;
                }
                // цены прочитаны?
                if (bid == 0 || ask == 0)
                {
                    loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                             LogMagicLackPrice,
                                                             1000 * 60 * 10, "MarketDataFullRefresh - нет цены (" +
                                                             bid.ToStringUniformPriceFormat() + ", " + ask.ToStringUniformPriceFormat() + ")");
                    return;
                }

                // обновить котировку
                QuoteDistributor.Instance.UpdateQuote(requestedSymbol, bid, ask);

                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataSuccess,
                                                         1000 * 60 * 10,
                                                         "Обработан пакет MarketDataFullRefresh - {0}: {1}/{2}",
                                                         requestedSymbol, bid, ask);
            }
            catch (Exception ex)
            {
                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataError,
                                                         1000 * 60 * 10, "Ошибка разбора MarketDataFullRefresh: {0}", ex);
            }
        }
コード例 #4
0
        public static void ProcessMsgMarketDataFullRefresh(Message msgOrig, FixMessage msg)
        {
            loggerNoFlood.LogMessageFormatCheckFlood(
                LogEntryType.Info,
                LogMagicMarketData,
                1000 * 60 * 60 * 2, "Quote full: {0}", msg.ToString());

            // 8=FIX.4.4#9=128#35=W#34=2#49=XTB#52=20141125-16:12:33.269#56=PARTNER1#55=USDJPY..#262=USDJPY-25-16-12#268=2#269=0#270=117.906#10=097#

            try
            {
                var reqIdField = msgOrig.getField(new MDReqID());
                if (reqIdField == null)
                {
                    throw new Exception("Поле MDReqID не прочитано");
                }
                // инструмент указан в самом запросе
                var requestedSymbol = msg.GetValueString(FixMessage.TAG_SYMBOL);
                //requestedSymbol = TickerCodeDictionary.Instance.GetClearTickerName(requestedSymbol);
                // котировка будет исправлена в дальнейшем

                var groupHeader = new NoMDEntries();
                msgOrig.getField(groupHeader);
                var numGroups = groupHeader.getValue();

                if (numGroups == 0)
                {
                    throw new Exception("Поле NoMDEntries не прочитано");
                }

                var group = FixMessage.FixVersion == FixVersion.Fix42
                                ? new QuickFix42.MarketDataIncrementalRefresh.NoMDEntries()
                                : FixMessage.FixVersion == FixVersion.Fix43
                                      ? (Group) new QuickFix43.MarketDataIncrementalRefresh.NoMDEntries()
                                      : new QuickFix44.MarketDataIncrementalRefresh.NoMDEntries();

                float bid = 0, ask = 0;
                for (var i = 1; i <= numGroups; i++)
                {
                    var groupTicker = msgOrig.getGroup((uint)i, group);
                    // тип (бид или аск)
                    var isBid     = true;
                    var typeField = groupTicker.getField(new MDEntryType());
                    if (typeField == null)
                    {
                        throw new Exception("Поле MDEntryType не прочитано");
                    }
                    isBid = typeField.getValue() == '0';
                    // цена
                    var priceField = group.getField(new MDEntryPx());
                    if (priceField == null)
                    {
                        throw new Exception("Поле MDEntryPx не прочитано");
                    }
                    var price = priceField.getValue();
                    if (isBid)
                    {
                        bid = (float)price;
                    }
                    else
                    {
                        ask = (float)price;
                    }
                }
                // цены прочитаны?
                if (bid == 0 || ask == 0)
                {
                    loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                             LogMagicLackPrice,
                                                             1000 * 60 * 10, "MarketDataFullRefresh - нет цены (" +
                                                             bid.ToStringUniformPriceFormat() + ", " + ask.ToStringUniformPriceFormat() + ")");
                    return;
                }

                // обновить котировку
                QuoteDistributor.Instance.UpdateQuote(requestedSymbol, bid, ask);

                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataSuccess,
                                                         1000 * 60 * 10,
                                                         "Обработан пакет MarketDataFullRefresh - {0}: {1}/{2}",
                                                         requestedSymbol, bid, ask);
            }
            catch (Exception ex)
            {
                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataError,
                                                         1000 * 60 * 10, "Ошибка разбора MarketDataFullRefresh: {0}", ex);
            }
        }
コード例 #5
0
        public static void ProcessMsgMarketDataIncrRefresh(Message msgOrig, FixMessage msg)
        {
            loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                LogMagicMarketData, 1000 * 60 * 60 * 2, "Quote incr: {0}", msg.ToString());

            try
            {
                // информация по тикерам разбита на группы, каждому тикеру - по группе
                var groupHeader = new NoMDEntries();
                msgOrig.getField(groupHeader);
                int numGroups = groupHeader.getValue();

                var group = FixMessage.FixVersion == FixVersion.Fix42
                                ? new QuickFix42.MarketDataIncrementalRefresh.NoMDEntries()
                                : FixMessage.FixVersion == FixVersion.Fix43
                                      ? (Group)new QuickFix43.MarketDataIncrementalRefresh.NoMDEntries()
                                      : new QuickFix44.MarketDataIncrementalRefresh.NoMDEntries();

                var lastQuotes = new System.Collections.Generic.Dictionary<string, QuoteData>();

                for (var i = 1; i <= numGroups; i++)
                {
                    var groupTicker = msgOrig.getGroup((uint)i, group);
                    var symbol = groupTicker.getField(new Symbol()).getValue();

                    if (!ConvertFromProviderSymbolNaming(ref symbol)) return;

                    var entType = new MDEntryType();
                    var entTypeChar = groupTicker.getField(entType).getValue();
                    var priceType = entTypeChar == FixMessage.VALUE_MD_ENTRY_TYPE_BID[0]
                                        ? Contract.Entity.QuoteType.Bid
                                        : entTypeChar == FixMessage.VALUE_MD_ENTRY_TYPE_OFFER[0]
                                              ? Contract.Entity.QuoteType.Ask
                                              : Contract.Entity.QuoteType.NonSpecified;
                    if (priceType == Contract.Entity.QuoteType.NonSpecified) continue;
                    var price = msg.GetValueFloat(FixMessage.TAG_MD_ENTRY_PX) ?? 0;
                    if (price == 0) continue;

                    if (lastQuotes.ContainsKey(symbol))
                    {
                        var quote = lastQuotes[symbol];
                        if (priceType == Contract.Entity.QuoteType.Bid)
                            quote.bid = price;
                        else
                            quote.ask = price;
                    }
                    else
                    {
                        lastQuotes.Add(symbol, new QuoteData(
                            priceType == Contract.Entity.QuoteType.Bid ? price : 0,
                            priceType == Contract.Entity.QuoteType.Ask ? price : 0, DateTime.Now));
                    }
                }

                foreach (var quote in lastQuotes)
                {
                    loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                             LogMagicQuote, 1000 * 60 * 15,
                                                             "Котировка {0}: {1} - {2}",
                                                             quote.Key, quote.Value.bid, quote.Value.ask);

                    QuoteDistributor.Instance.UpdateQuote(quote.Key,
                        quote.Value.bid == 0 ? (float?)null : quote.Value.bid,
                        quote.Value.ask == 0 ? (float?)null : quote.Value.ask);
                }

                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataSuccess,
                                                         1000 * 60 * 10, "Обработан пакет MarketDataIncrRefresh");
            }
            catch (Exception ex)
            {
                loggerNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info,
                                                         LogMagicParseMarketDataError,
                                                         1000 * 60 * 10, "Ошибка разбора MarketDataIncrRefresh: {0}", ex);
            }
        }