private void OnQuotationsResponse(QuotationsResponse response) { foreach (var quote in response.Quotations) { var message = new Level1ChangeMessage { SecurityId = new SecurityId { Native = quote.SecId }, ServerTime = SessionHolder.CurrentTime.Convert(TimeHelper.Moscow), }; message.TryAdd(Level1Fields.AccruedCouponIncome, quote.AccruedIntValue); message.TryAdd(Level1Fields.OpenPrice, quote.Open); message.TryAdd(Level1Fields.HighPrice, quote.High); message.TryAdd(Level1Fields.LowPrice, quote.Low); message.TryAdd(Level1Fields.ClosePrice, quote.ClosePrice); message.TryAdd(Level1Fields.BidsCount, quote.BidsCount); message.TryAdd(Level1Fields.BidsVolume, (decimal?)quote.BidsVolume); message.TryAdd(Level1Fields.AsksCount, quote.AsksCount); message.TryAdd(Level1Fields.AsksVolume, (decimal?)quote.AsksVolume); message.TryAdd(Level1Fields.HighBidPrice, quote.HighBid); message.TryAdd(Level1Fields.LowAskPrice, quote.LowAsk); message.TryAdd(Level1Fields.Yield, quote.Yield); message.TryAdd(Level1Fields.MarginBuy, quote.BuyDeposit); message.TryAdd(Level1Fields.MarginSell, quote.SellDeposit); message.TryAdd(Level1Fields.HistoricalVolatility, quote.Volatility); message.TryAdd(Level1Fields.TheorPrice, quote.TheoreticalPrice); message.TryAdd(Level1Fields.Change, quote.Change); message.TryAdd(Level1Fields.Volume, (decimal?)quote.VolToday); message.TryAdd(Level1Fields.StepPrice, quote.PointCost); message.TryAdd(Level1Fields.OpenInterest, (decimal?)quote.OpenInterest); message.TryAdd(Level1Fields.TradesCount, quote.TradesCount); if (quote.Status != null) { message.Add(Level1Fields.State, quote.Status.Value.FromTransaq()); } // Transaq передает только изменения (например, передать только цену сделки, если объем при этом не изменился) message.TryAdd(Level1Fields.LastTradePrice, quote.LastTradePrice); message.TryAdd(Level1Fields.LastTradeVolume, (decimal?)quote.LastTradeVolume); if (quote.LastTradeTime != null) { message.Add(Level1Fields.LastTradeTime, quote.LastTradeTime.Value.ApplyTimeZone(TimeHelper.Moscow)); } message.TryAdd(Level1Fields.BestBidPrice, quote.BestBidPrice); message.TryAdd(Level1Fields.BestBidVolume, (decimal?)quote.BestBidVolume); message.TryAdd(Level1Fields.BestAskPrice, quote.BestAskPrice); message.TryAdd(Level1Fields.BestAskVolume, (decimal?)quote.BestAskVolume); SendOutMessage(message); } }
private void OnProcessLevel1(string[] data) { var f = Wrapper.FieldsLevel1; foreach (var row in data) { var cols = row.ToColumns(); var paperNo = f.PaperNo.GetValue(cols); var secId = new SecurityId { Native = paperNo }; var l1Msg = new Level1ChangeMessage { SecurityId = secId, ServerTime = (f.LastUpdateDate.GetValue(cols).Date + f.LastUpdateTime.GetValue(cols).TimeOfDay).ApplyTimeZone(TimeHelper.Moscow) }; l1Msg.Add(Level1Fields.State, f.TradingStatus.GetValue(cols)); l1Msg.TryAdd(Level1Fields.MarginBuy, f.GoBuy.GetValue(cols)); l1Msg.TryAdd(Level1Fields.MarginSell, f.GoSell.GetValue(cols)); l1Msg.TryAdd(Level1Fields.OpenInterest, (decimal)f.OpenPosQty.GetValue(cols)); var minPrice = f.MinDeal.GetValue(cols); var maxPrice = f.MaxDeal.GetValue(cols); l1Msg.TryAdd(Level1Fields.OpenPrice, f.OpenPrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.ClosePrice, f.ClosePrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.HighPrice, maxPrice); l1Msg.TryAdd(Level1Fields.LowPrice, minPrice); l1Msg.TryAdd(Level1Fields.BestBidPrice, f.Buy.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BestBidVolume, (decimal)f.BuyQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BestAskPrice, f.Sell.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BestAskVolume, (decimal)f.SellQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.MinPrice, minPrice); l1Msg.TryAdd(Level1Fields.MaxPrice, maxPrice); l1Msg.TryAdd(Level1Fields.Multiplier, (decimal)f.LotSize.GetValue(cols)); l1Msg.TryAdd(Level1Fields.ImpliedVolatility, f.Volatility.GetValue(cols)); l1Msg.TryAdd(Level1Fields.TheorPrice, f.TheorPrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.LastTradePrice, f.LastPrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.LastTradeVolume, (decimal)f.LastQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.PriceStep, f.PriceStep.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BidsVolume, (decimal)f.BuySQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BidsCount, f.BuyCount.GetValue(cols)); l1Msg.TryAdd(Level1Fields.AsksVolume, (decimal)f.SellSQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.AsksCount, f.SellCount.GetValue(cols)); SendOutMessage(l1Msg); } }
private void OnSessionMarketDataChanged(OrderBookEvent orderBookEvent) { var time = TimeHelper.GregorianStart.AddMilliseconds(orderBookEvent.Timestamp).ApplyTimeZone(TimeZoneInfo.Utc); var secId = new SecurityId { Native = orderBookEvent.InstrumentId }; var l1Msg = new Level1ChangeMessage { ServerTime = time, SecurityId = secId, }; if (orderBookEvent.HasMarketClosePrice) { l1Msg.Add(Level1Fields.ClosePrice, orderBookEvent.MktClosePrice); } if (orderBookEvent.HasDailyHighestTradedPrice) { l1Msg.Add(Level1Fields.HighPrice, orderBookEvent.DailyHighestTradedPrice); } if (orderBookEvent.HasDailyLowestTradedPrice) { l1Msg.Add(Level1Fields.LowPrice, orderBookEvent.DailyLowestTradedPrice); } if (orderBookEvent.HasLastTradedPrice) { l1Msg.Add(Level1Fields.LastTradePrice, orderBookEvent.LastTradedPrice); } SendOutMessage(l1Msg); SendOutMessage(new QuoteChangeMessage { SecurityId = secId, Bids = orderBookEvent.BidPrices.Select(p => new QuoteChange(Sides.Buy, p.Price, p.Quantity)), Asks = orderBookEvent.AskPrices.Select(p => new QuoteChange(Sides.Sell, p.Price, p.Quantity)), ServerTime = time }); }
private static Level1ChangeMessage ToLevel2(string value) { var parts = value.SplitByComma(); var isBidValid = parts[10] == "T"; var isAskValid = parts[11] == "T"; if (!isBidValid && !isAskValid) { return(null); } var date = parts[7].ToDateTime("yyyy-MM-dd"); var l1Msg = new Level1ChangeMessage { SecurityId = new SecurityId { SecurityCode = parts[0], BoardCode = parts[1] }, }; // http://www.iqfeed.net/dev/api/docs/ConditionCodes.cfm l1Msg.Add(Level1Fields.IsSystem, parts[8] == "52"); if (isAskValid) { l1Msg.ServerTime = date.Add(parts[9].To <TimeSpan>()).ApplyTimeZone(TimeHelper.Est); l1Msg .TryAdd(Level1Fields.BestAskPrice, parts[3].To <decimal>()) .TryAdd(Level1Fields.BestAskVolume, parts[5].To <decimal>()) .Add(Level1Fields.BestAskTime, l1Msg.ServerTime); } if (isBidValid) { var bidTime = date.Add(parts[6].To <TimeSpan>()).ApplyTimeZone(TimeHelper.Est); if (bidTime > l1Msg.ServerTime) { l1Msg.ServerTime = bidTime; } l1Msg .TryAdd(Level1Fields.BestBidPrice, parts[2].To <decimal>()) .TryAdd(Level1Fields.BestBidVolume, parts[4].To <decimal>()) .Add(Level1Fields.BestBidTime, bidTime); } return(l1Msg); }
private void OnSecurityChanged(string smartId, Tuple <decimal?, decimal?, DateTime> lastTrade, decimal?open, decimal?high, decimal?low, decimal?close, decimal?volume, QuoteChange bid, QuoteChange ask, decimal?openInt, Tuple <decimal?, decimal?> goBuySell, Tuple <decimal?, decimal?> goBase, Tuple <decimal?, decimal?> limits, int tradingStatus, Tuple <decimal?, decimal?> volatTheorPrice) { var secId = new SecurityId { Native = smartId }; var message = new Level1ChangeMessage { SecurityId = secId, ExtensionInfo = new Dictionary <object, object> { { SmartComExtensionInfoHelper.SecurityOptionsMargin, goBase.Item1 }, { SmartComExtensionInfoHelper.SecurityOptionsSyntheticMargin, goBase.Item2 } }, ServerTime = CurrentTime.Convert(TimeHelper.Moscow), }; message.TryAdd(Level1Fields.LastTradePrice, lastTrade.Item1); message.TryAdd(Level1Fields.LastTradeVolume, lastTrade.Item2); message.Add(Level1Fields.LastTradeTime, lastTrade.Item3.ApplyTimeZone(TimeHelper.Moscow)); var prevQuotes = _bestQuotes.TryGetValue(secId); if (bid.Price != 0) { message.Add(Level1Fields.BestBidPrice, bid.Price); if (prevQuotes != null && prevQuotes.First != null && prevQuotes.First.Item1 == bid.Price) { message.Add(Level1Fields.BestBidVolume, prevQuotes.First.Item2); } } if (ask.Price != 0) { message.Add(Level1Fields.BestAskPrice, ask.Price); if (prevQuotes != null && prevQuotes.Second != null && prevQuotes.Second.Item1 == ask.Price) { message.Add(Level1Fields.BestAskVolume, prevQuotes.Second.Item2); } } message.TryAdd(Level1Fields.BidsVolume, bid.Volume); message.TryAdd(Level1Fields.AsksVolume, ask.Volume); message.TryAdd(Level1Fields.OpenPrice, open); message.TryAdd(Level1Fields.LowPrice, low); message.TryAdd(Level1Fields.HighPrice, high); message.TryAdd(Level1Fields.ClosePrice, close); message.TryAdd(Level1Fields.MinPrice, limits.Item1); message.TryAdd(Level1Fields.MaxPrice, limits.Item2); message.TryAdd(Level1Fields.MarginBuy, goBuySell.Item1); message.TryAdd(Level1Fields.MarginSell, goBuySell.Item2); message.TryAdd(Level1Fields.OpenInterest, openInt); message.TryAdd(Level1Fields.ImpliedVolatility, volatTheorPrice.Item1); message.TryAdd(Level1Fields.TheorPrice, volatTheorPrice.Item2); message.TryAdd(Level1Fields.Volume, volume); message.Add(Level1Fields.State, tradingStatus == 0 ? SecurityStates.Trading : SecurityStates.Stoped); SendOutMessage(message); }
private static Level1ChangeMessage ToLevel2(string value) { var parts = value.SplitByComma(); var isBidValid = parts[10] == "T"; var isAskValid = parts[11] == "T"; if (!isBidValid && !isAskValid) return null; var date = parts[7].ToDateTime("yyyy-MM-dd"); var l1Msg = new Level1ChangeMessage { SecurityId = new SecurityId { SecurityCode = parts[0], BoardCode = parts[1] }, }; // http://www.iqfeed.net/dev/api/docs/ConditionCodes.cfm l1Msg.Add(Level1Fields.IsSystem, parts[8] == "52"); if (isAskValid) { l1Msg.ServerTime = date.Add(parts[9].To<TimeSpan>()).ApplyTimeZone(TimeHelper.Est); l1Msg .TryAdd(Level1Fields.BestAskPrice, parts[3].To<decimal>()) .TryAdd(Level1Fields.BestAskVolume, parts[5].To<decimal>()) .Add(Level1Fields.BestAskTime, l1Msg.ServerTime); } if (isBidValid) { var bidTime = date.Add(parts[6].To<TimeSpan>()).ApplyTimeZone(TimeHelper.Est); if (bidTime > l1Msg.ServerTime) l1Msg.ServerTime = bidTime; l1Msg .TryAdd(Level1Fields.BestBidPrice, parts[2].To<decimal>()) .TryAdd(Level1Fields.BestBidVolume, parts[4].To<decimal>()) .Add(Level1Fields.BestBidTime, bidTime); } return l1Msg; }
private void OnSecurityChanged(string smartId, Tuple<decimal, decimal, DateTime> lastTrade, decimal open, decimal high, decimal low, decimal close, decimal volume, QuoteChange bid, QuoteChange ask, decimal openInt, Tuple<decimal, decimal> goBuySell, Tuple<decimal, decimal> goBase, Tuple<decimal, decimal> limits, int tradingStatus, Tuple<decimal, decimal> volatTheorPrice) { var secId = new SecurityId { Native = smartId }; var message = new Level1ChangeMessage { SecurityId = secId, ExtensionInfo = new Dictionary<object, object> { { SmartComExtensionInfoHelper.SecurityOptionsMargin, goBase.Item1 }, { SmartComExtensionInfoHelper.SecurityOptionsSyntheticMargin, goBase.Item2 } }, ServerTime = CurrentTime.Convert(TimeHelper.Moscow), }; message.TryAdd(Level1Fields.LastTradePrice, lastTrade.Item1); message.TryAdd(Level1Fields.LastTradeVolume, lastTrade.Item2); message.Add(Level1Fields.LastTradeTime, lastTrade.Item3.ApplyTimeZone(TimeHelper.Moscow)); var prevQuotes = _bestQuotes.TryGetValue(secId); if (bid.Price != 0) { message.Add(Level1Fields.BestBidPrice, bid.Price); if (prevQuotes != null && prevQuotes.First != null && prevQuotes.First.Item1 == bid.Price) message.Add(Level1Fields.BestBidVolume, prevQuotes.First.Item2); } if (ask.Price != 0) { message.Add(Level1Fields.BestAskPrice, ask.Price); if (prevQuotes != null && prevQuotes.Second != null && prevQuotes.Second.Item1 == ask.Price) message.Add(Level1Fields.BestAskVolume, prevQuotes.Second.Item2); } message.TryAdd(Level1Fields.BidsVolume, bid.Volume); message.TryAdd(Level1Fields.AsksVolume, ask.Volume); message.TryAdd(Level1Fields.OpenPrice, open); message.TryAdd(Level1Fields.LowPrice, low); message.TryAdd(Level1Fields.HighPrice, high); message.TryAdd(Level1Fields.ClosePrice, close); message.TryAdd(Level1Fields.MinPrice, limits.Item1); message.TryAdd(Level1Fields.MaxPrice, limits.Item2); message.TryAdd(Level1Fields.MarginBuy, goBuySell.Item1); message.TryAdd(Level1Fields.MarginSell, goBuySell.Item2); message.TryAdd(Level1Fields.OpenInterest, openInt); message.TryAdd(Level1Fields.ImpliedVolatility, volatTheorPrice.Item1); message.TryAdd(Level1Fields.TheorPrice, volatTheorPrice.Item2); message.TryAdd(Level1Fields.Volume, volume); message.Add(Level1Fields.State, tradingStatus == 0 ? SecurityStates.Trading : SecurityStates.Stoped); SendOutMessage(message); }
private void OnSessionMarketDataChanged(OrderBookEvent orderBookEvent) { var time = TimeHelper.GregorianStart.AddMilliseconds(orderBookEvent.Timestamp).ApplyTimeZone(TimeZoneInfo.Utc); var secId = new SecurityId { Native = orderBookEvent.InstrumentId }; var l1Msg = new Level1ChangeMessage { ServerTime = time, SecurityId = secId, }; if (orderBookEvent.HasMarketClosePrice) l1Msg.Add(Level1Fields.ClosePrice, orderBookEvent.MktClosePrice); if (orderBookEvent.HasDailyHighestTradedPrice) l1Msg.Add(Level1Fields.HighPrice, orderBookEvent.DailyHighestTradedPrice); if (orderBookEvent.HasDailyLowestTradedPrice) l1Msg.Add(Level1Fields.LowPrice, orderBookEvent.DailyLowestTradedPrice); if (orderBookEvent.HasLastTradedPrice) { l1Msg.Add(Level1Fields.LastTradePrice, orderBookEvent.LastTradedPrice); } SendOutMessage(l1Msg); SendOutMessage(new QuoteChangeMessage { SecurityId = secId, Bids = orderBookEvent.BidPrices.Select(p => new QuoteChange(Sides.Buy, p.Price, p.Quantity)), Asks = orderBookEvent.AskPrices.Select(p => new QuoteChange(Sides.Sell, p.Price, p.Quantity)), ServerTime = time }); }
private void OnQuotationsResponse(QuotationsResponse response) { foreach (var quote in response.Quotations) { var message = new Level1ChangeMessage { SecurityId = new SecurityId { Native = quote.SecId }, ServerTime = CurrentTime.Convert(TimeHelper.Moscow), }; message.TryAdd(Level1Fields.AccruedCouponIncome, quote.AccruedIntValue); message.TryAdd(Level1Fields.OpenPrice, quote.Open); message.TryAdd(Level1Fields.HighPrice, quote.High); message.TryAdd(Level1Fields.LowPrice, quote.Low); message.TryAdd(Level1Fields.ClosePrice, quote.ClosePrice); message.TryAdd(Level1Fields.BidsCount, quote.BidsCount); message.TryAdd(Level1Fields.BidsVolume, (decimal?)quote.BidsVolume); message.TryAdd(Level1Fields.AsksCount, quote.AsksCount); message.TryAdd(Level1Fields.AsksVolume, (decimal?)quote.AsksVolume); message.TryAdd(Level1Fields.HighBidPrice, quote.HighBid); message.TryAdd(Level1Fields.LowAskPrice, quote.LowAsk); message.TryAdd(Level1Fields.Yield, quote.Yield); message.TryAdd(Level1Fields.MarginBuy, quote.BuyDeposit); message.TryAdd(Level1Fields.MarginSell, quote.SellDeposit); message.TryAdd(Level1Fields.HistoricalVolatility, quote.Volatility); message.TryAdd(Level1Fields.TheorPrice, quote.TheoreticalPrice); message.TryAdd(Level1Fields.Change, quote.Change); message.TryAdd(Level1Fields.Volume, (decimal?)quote.VolToday); message.TryAdd(Level1Fields.StepPrice, quote.PointCost); message.TryAdd(Level1Fields.OpenInterest, (decimal?)quote.OpenInterest); message.TryAdd(Level1Fields.TradesCount, quote.TradesCount); if (quote.Status != null) message.Add(Level1Fields.State, quote.Status.Value.FromTransaq()); // Transaq передает только изменения (например, передать только цену сделки, если объем при этом не изменился) message.TryAdd(Level1Fields.LastTradePrice, quote.LastTradePrice); message.TryAdd(Level1Fields.LastTradeVolume, (decimal?)quote.LastTradeVolume); if (quote.LastTradeTime != null) message.Add(Level1Fields.LastTradeTime, quote.LastTradeTime.Value.ToDto()); message.TryAdd(Level1Fields.BestBidPrice, quote.BestBidPrice); message.TryAdd(Level1Fields.BestBidVolume, (decimal?)quote.BestBidVolume); message.TryAdd(Level1Fields.BestAskPrice, quote.BestAskPrice); message.TryAdd(Level1Fields.BestAskVolume, (decimal?)quote.BestAskVolume); SendOutMessage(message); } }
private void OnProcessLevel1(string[] data) { var f = Wrapper.FieldsLevel1; foreach (var row in data) { var cols = row.ToColumns(); var paperNo = f.PaperNo.GetValue(cols); var secId = new SecurityId { Native = paperNo }; var l1Msg = new Level1ChangeMessage { SecurityId = secId, ServerTime = (f.LastUpdateDate.GetValue(cols).Date + f.LastUpdateTime.GetValue(cols).TimeOfDay).ApplyTimeZone(TimeHelper.Moscow) }; l1Msg.Add(Level1Fields.State, f.TradingStatus.GetValue(cols)); l1Msg.TryAdd(Level1Fields.MarginBuy, f.GoBuy.GetValue(cols)); l1Msg.TryAdd(Level1Fields.MarginSell, f.GoSell.GetValue(cols)); l1Msg.TryAdd(Level1Fields.OpenInterest, (decimal)f.OpenPosQty.GetValue(cols)); var minPrice = f.MinDeal.GetValue(cols); var maxPrice = f.MaxDeal.GetValue(cols); l1Msg.TryAdd(Level1Fields.OpenPrice, f.OpenPrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.ClosePrice, f.ClosePrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.HighPrice, maxPrice); l1Msg.TryAdd(Level1Fields.LowPrice, minPrice); l1Msg.TryAdd(Level1Fields.BestBidPrice, f.Buy.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BestBidVolume, (decimal)f.BuyQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BestAskPrice, f.Sell.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BestAskVolume, (decimal)f.SellQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.MinPrice, minPrice); l1Msg.TryAdd(Level1Fields.MaxPrice, maxPrice); l1Msg.TryAdd(Level1Fields.Multiplier, (decimal)f.LotSize.GetValue(cols)); l1Msg.TryAdd(Level1Fields.ImpliedVolatility, f.Volatility.GetValue(cols)); l1Msg.TryAdd(Level1Fields.TheorPrice, f.TheorPrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.LastTradePrice, f.LastPrice.GetValue(cols)); l1Msg.TryAdd(Level1Fields.LastTradeVolume, (decimal)f.LastQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.PriceStep, f.PriceStep.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BidsVolume, (decimal)f.BuySQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.BidsCount, f.BuyCount.GetValue(cols)); l1Msg.TryAdd(Level1Fields.AsksVolume, (decimal)f.SellSQty.GetValue(cols)); l1Msg.TryAdd(Level1Fields.AsksCount, f.SellCount.GetValue(cols)); SendOutMessage(l1Msg); } }