private void CollectAndSortServerDataByMaps(string topic, string[] data) { LOGGER.Debug("Starting process of colleting and sorting data. Topic: {0}, data array: {1} ", topic, String.Join(" ", data)); if (futRecievedDataFlag == false || optRecievedDataFlag == false) { CheckConnectionFlags(); } //DDE ORDER IS: futures -> options -> pos if (topic.Equals(FUTURES_DESK)) { if (GetBasicFutures() == null) { LOGGER.Debug("Initializing basic futures."); string ticker = data[0]; DateTime maturity = DateTime.Parse(data[1]); double commission = Convert.ToDouble(data[2]); double marginRequirement = Convert.ToDouble(data[3]); double priceStep = Convert.ToDouble(data[4]); double priceStepValue = Convert.ToDouble(data[5]); TradeBlotter futuresBlotter = new TradeBlotter(); futuresBlotter.BidPrice = Convert.ToDouble(data[6]); futuresBlotter.BidSize = Convert.ToDouble(data[7]); futuresBlotter.AskPrice = Convert.ToDouble(data[8]); futuresBlotter.AskSize = Convert.ToDouble(data[9]); string baseContract = data[10]; basicFutures = new Futures(ticker, maturity, commission, marginRequirement, priceStep, priceStepValue); basicFutures.BaseContract = baseContract; basicFutures.AssignTradeBlotter(futuresBlotter); basicFutures.MinPriceLimit = Convert.ToDouble(data[11]); basicFutures.MaxPriceLimit = Convert.ToDouble(data[12]); LOGGER.Debug("Initializing completed. Futures instance: {0}", basicFutures); } else { LOGGER.Debug("Updating basic futures."); TradeBlotter futuresBlotter = basicFutures.GetTradeBlotter(); futuresBlotter.BidPrice = Convert.ToDouble(data[6]); futuresBlotter.BidSize = Convert.ToDouble(data[7]); futuresBlotter.AskPrice = Convert.ToDouble(data[8]); futuresBlotter.AskSize = Convert.ToDouble(data[9]); basicFutures.MinPriceLimit = Convert.ToDouble(data[11]); basicFutures.MaxPriceLimit = Convert.ToDouble(data[12]); LOGGER.Debug("Updating completed."); } if (OnSpotPriceChanged != null && infoOption != null && futRecievedDataFlag == true) { OnSpotPriceChanged(this, new OptionEventArgs(infoOption)); } } else if (topic.Equals(OPTIONS_DESK)) { OptionType optionType = (OptionType)Enum.Parse(typeof(OptionType), data[0]); double strike = Convert.ToDouble(data[1]); SortedDictionary <double, Option> suitOptionsMap = GetSuitableOptionsMap(optionType); Option tempOption; if (suitOptionsMap.ContainsKey(strike)) { LOGGER.Debug("Initializing option: {0}, {1}", optionType, strike); tempOption = suitOptionsMap[strike]; tempOption.MarginRequirementNotCover = Convert.ToDouble(data[2]); tempOption.MarginRequirementCover = Convert.ToDouble(data[3]); tempOption.MarginRequirementBuyer = Convert.ToDouble(data[4]); TradeBlotter optionsBlotter = tempOption.GetTradeBlotter(); optionsBlotter.BidPrice = Convert.ToDouble(data[10]); optionsBlotter.BidSize = Convert.ToDouble(data[11]); optionsBlotter.AskPrice = Convert.ToDouble(data[12]); optionsBlotter.AskSize = Convert.ToDouble(data[13]); LOGGER.Debug("Initializing completed. Option instance: {0}", tempOption); } else { LOGGER.Debug("Updating option: {0}, {1}", optionType, strike); double marginRequirementCover = Convert.ToDouble(data[2]);; double marginRequirementNotCover = Convert.ToDouble(data[3]);; double marginRequirementBuyer = Convert.ToDouble(data[4]);; string ticker = data[5]; double priceStep = Convert.ToDouble(data[6]); double priceStepValue = Convert.ToDouble(data[7]); DateTime expirationDate = DateTime.Parse(data[8]); int remainingDays = Convert.ToInt32(data[9]); tempOption = new Option(basicFutures, optionType, strike, marginRequirementCover, marginRequirementNotCover, marginRequirementBuyer, ticker, priceStep, priceStepValue, expirationDate, remainingDays); TradeBlotter optionsBlotter = new TradeBlotter(); optionsBlotter.BidPrice = Convert.ToDouble(data[10]); optionsBlotter.BidSize = Convert.ToDouble(data[11]); optionsBlotter.AskPrice = Convert.ToDouble(data[12]); optionsBlotter.AskSize = Convert.ToDouble(data[13]); tempOption.AssignTradeBlotter(optionsBlotter); suitOptionsMap.Add(strike, tempOption); tickerMap.Add(ticker, tempOption); LOGGER.Debug("Updating completed."); } if (infoOption == null) { //just for access to general options field infoOption = suitOptionsMap[strike]; LOGGER.Debug("info option created: {0}", infoOption); } if (OnOptionsDeskChanged != null && optRecievedDataFlag == true && tempOption.Strike <= CalculateMaxImportantStrike() && tempOption.Strike >= CalculateMinImportantStrike()) { OnOptionsDeskChanged(this, new OptionEventArgs(tempOption)); } } else if (topic.Equals(POS_TABLE)) { string account = data[0]; // ? string ticker = data[1]; int pos = Convert.ToInt32(data[2]); DerivativesClasses cls; if (ticker.Equals(basicFutures.Ticker)) { cls = DerivativesClasses.FUTURES; } else { cls = DerivativesClasses.OPTIONS; } if (OnActualPosChanged != null) { OnActualPosChanged(this, new TerminalPosEventArgs(cls, ticker, pos)); } } else { throw new QuikDdeException("table with a such name wasn't mapped: " + String.Join(" ", TOPICS_AND_ROWS_LENGTH_MAP.Keys)); } }