Exemplo n.º 1
0
        private static void ResolveMarketDataRequest(MarketDataRequest message, out Symbol symbol, out char bidAskObj, out string currencyCodeObj)
        {
            MDReqID mdReqId = new MDReqID();

            message.Get(mdReqId);

            SubscriptionRequestType subType = new SubscriptionRequestType();

            message.Get(subType);

            MarketDepth marketDepth = new MarketDepth();

            message.Get(marketDepth);

            var symbolGroup = new FixSpec.MarketDataRequest.NoRelatedSymGroup();

            message.GetGroup(1, symbolGroup);
            symbol = new Symbol();
            symbolGroup.Get(symbol);

            FixSpec.MarketDataRequest.NoMDEntryTypesGroup marketDataEntryGroup = new FixSpec.MarketDataRequest.NoMDEntryTypesGroup();
            message.GetGroup(1, marketDataEntryGroup);
            var mDEntryType = new MDEntryType();

            marketDataEntryGroup.Get(mDEntryType);

            bidAskObj       = mDEntryType.Obj;
            currencyCodeObj = symbol.Obj;
            var marketDepthObj = marketDepth.Obj;
        }
Exemplo n.º 2
0
		public static bool Compare(this MDEntryType[] array1, MDEntryType[] array2)
		{
			if (array1 == array2) return true;
			if (array1 == null) return false;
			if (array2 == null) return false;
			if (array1.Length != array2.Length) return false;
			foreach (MDEntryType t in array1)
				if (!array2.Contains(t)) return false;
			return true;
		}
Exemplo n.º 3
0
 public static char GetBidOrAsk(MDEntryType MDEntryType)
 {
     if (MDEntryType == MDEntryType.Bid)
     {
         return(DepthOfBook._BID_ENTRY);
     }
     else if (MDEntryType == MDEntryType.Ask)
     {
         return(DepthOfBook._ASK_ENTRY);
     }
     else
     {
         throw new Exception(string.Format("Unknown MDEntryType {0}", MDEntryType));
     }
 }
        public void OnMessage(QuickFix.FIX44.MarketDataSnapshotFullRefresh marketDataSnapshot, SessionID session)
        {
            MarketPrice marketPrice = new MarketPrice
            {
                Symbol = marketDataSnapshot.Symbol.getValue()
            };
            var nomdentries = marketDataSnapshot.NoMDEntries;
            // message.GetGroup(1, noMdEntries);
            var grp = new QuickFix.FIX44.MarketDataSnapshotFullRefresh.NoMDEntriesGroup();

            for (int i = 1; i <= nomdentries.getValue(); i++)
            {
                grp = (QuickFix.FIX44.MarketDataSnapshotFullRefresh.NoMDEntriesGroup)marketDataSnapshot.GetGroup(i, grp);

                //	var grp = marketDataSnapshot.GetGroup(i, new QuickFix.FIX44.MarketDataSnapshotFullRefresh.NoMDEntriesGroup()) as QuickFix.FIX44.MarketDataSnapshotFullRefresh.NoMDEntriesGroup;
                MDEntryType priceType = grp.Get(new MDEntryType());
                MDEntryPx   mdEntryPx = grp.Get(new MDEntryPx());
                if (priceType.getValue() == MDEntryType.BID)
                {
                    marketPrice.Bid = mdEntryPx.getValue();
                }
                else if (priceType.getValue() == MDEntryType.OFFER)
                {
                    marketPrice.Offer = mdEntryPx.getValue();
                }
                else if (priceType.getValue() == MDEntryType.TRADE)
                {
                    marketPrice.TradedPrice = mdEntryPx.getValue();
                }
                else if (priceType.getValue() == MDEntryType.TRADING_SESSION_LOW_PRICE)
                {
                    marketPrice.LowPx = mdEntryPx.getValue();
                }
                else if (priceType.getValue() == MDEntryType.TRADING_SESSION_HIGH_PRICE)
                {
                    marketPrice.HighPx = mdEntryPx.getValue();
                }
            }

            if (OnMarketPrice != null)
            {
                OnMarketPrice(marketPrice);
            }
        }
Exemplo n.º 5
0
        public void OnMessage(MarketDataIncrementalRefresh message, SessionID session)
        {
            var noMdEntries     = message.NoMDEntries;
            var listOfMdEntries = noMdEntries.getValue();
            //message.GetGroup(1, noMdEntries);
            var group = new MarketDataIncrementalRefresh.NoMDEntriesGroup();

            Group gr = message.GetGroup(1, group);

            string sym = message.MDReqID.getValue();

            var price = new MarketPrice();


            for (int i = 1; i <= listOfMdEntries; i++)
            {
                group = (MarketDataIncrementalRefresh.NoMDEntriesGroup)message.GetGroup(i, group);

                price.Symbol = group.Symbol.getValue();

                MDEntryType mdentrytype = group.MDEntryType;

                if (mdentrytype.getValue() == '0') //bid
                {
                    decimal px = group.MDEntryPx.getValue();
                    price.Bid = px;
                }
                else if (mdentrytype.getValue() == '1') //offer
                {
                    decimal px = group.MDEntryPx.getValue();
                    price.Offer = px;
                }

                price.TimeStamp = group.MDEntryTime.ToString();
            }

            if (OnMarketDataIncrementalRefresh != null)
            {
                OnMarketDataIncrementalRefresh(price);
            }
        }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
0
        public void Subscribe(string symbol, SessionID sessionId)
        {
            var marketDataRequest = new MarketDataRequest
            {
                MDReqID = new MDReqID(symbol),
                SubscriptionRequestType = new SubscriptionRequestType('1'),
                //incremental refresh
                MarketDepth  = new MarketDepth(1),                            //yes market depth need
                MDUpdateType = new MDUpdateType(1)                            //
            };

            var relatedSymbol = new MarketDataRequest.NoRelatedSymGroup {
                Symbol = new Symbol(symbol)
            };

            marketDataRequest.AddGroup(relatedSymbol);

            var noMdEntryTypes = new MarketDataRequest.NoMDEntryTypesGroup();

            var mdEntryTypeBid = new MDEntryType('0');

            noMdEntryTypes.MDEntryType = mdEntryTypeBid;

            marketDataRequest.AddGroup(noMdEntryTypes);

            noMdEntryTypes = new MarketDataRequest.NoMDEntryTypesGroup();

            var mdEntryTypeOffer = new MDEntryType('1');

            noMdEntryTypes.MDEntryType = mdEntryTypeOffer;

            marketDataRequest.AddGroup(noMdEntryTypes);

            //Send message
            Session.SendToTarget(marketDataRequest, sessionId);
        }
Exemplo n.º 8
0
        public Task SendMarketDataRequest(string symbol, string exchange, Action <string> progressHandler)
        {
            return(Task.Run(() =>
            {
                //Create object of Security Definition
                QuickFix.FIX42.MarketDataRequest securityDefinition = new QuickFix.FIX42.MarketDataRequest
                {
                    MDReqID = new MDReqID(Guid.NewGuid().ToString()),
                    SubscriptionRequestType = new SubscriptionRequestType(SubscriptionRequestType.SNAPSHOT_PLUS_UPDATES),
                    MarketDepth = new MarketDepth(1),
                    MDUpdateType = new MDUpdateType(0)
                };

                var noMDEntryTypes = new QuickFix.FIX42.MarketDataRequest.NoMDEntryTypesGroup();
                var mdEntryType_bid = new MDEntryType(MDEntryType.BID);
                noMDEntryTypes.Set(mdEntryType_bid);
                securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.OFFER)); securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.TRADE)); securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.OPENING_PRICE)); securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.SETTLEMENT_PRICE)); securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.TRADING_SESSION_HIGH_PRICE)); securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.TRADING_SESSION_LOW_PRICE)); securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.TRADE_VOLUME)); securityDefinition.AddGroup(noMDEntryTypes);
                noMDEntryTypes.Set(new MDEntryType(MDEntryType.OPEN_INTEREST)); securityDefinition.AddGroup(noMDEntryTypes);

                securityDefinition.NoRelatedSym = new NoRelatedSym(1);

                var relatedSymbol = new QuickFix.FIX42.MarketDataRequest.NoRelatedSymGroup();
                relatedSymbol.Set(new Symbol(symbol));
                relatedSymbol.Set(new SecurityExchange(exchange));
                securityDefinition.AddGroup(relatedSymbol);
                Session.SendToTarget(securityDefinition, _currentSessionId);
                progressHandler("Sent MarketData Request");
            }));
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
		public static bool In(this MDEntryType type, MDEntryType[] array)
		{
			return array.Contains(type);
		}
Exemplo n.º 11
0
 public static bool In(this MDEntryType type, MDEntryType[] array)
 {
     return(array.Contains(type));
 }
Exemplo n.º 12
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);
            }
        }