/// <summary> /// Initializes a new instance of the <see cref="CsvDataProcessor"/> class /// </summary> /// <param name="dataDirectory">The root data directory, /Data</param> /// <param name="resolution">The resolution being sent into the Process method</param> /// <param name="tickType">The tick type, trade or quote</param> public CsvDataProcessor(string dataDirectory, Resolution resolution, TickType tickType) { _dataDirectory = dataDirectory; _resolution = resolution; _tickType = tickType; _writers = new Dictionary<Symbol, Writer>(); }
/// <summary> /// Full Constructor /// </summary> /// <param name="tickerId">The ticker Id that was specified previously in the call to reqMktData().</param> /// <param name="tickType">Specifies the type of price.</param> /// <param name="price">Specifies the price for the specified field.</param> /// <param name="canAutoExecute">specifies whether the price tick is available for automatic execution.</param> public TickPriceEventArgs(int tickerId, TickType tickType, decimal price, bool canAutoExecute) { this.tickerId = tickerId; this.canAutoExecute = canAutoExecute; this.price = price; this.tickType = tickType; }
/// <summary> /// Initializes a new instance of the <see cref="LeanDataPathComponents"/> class /// </summary> public LeanDataPathComponents(SecurityType securityType, string market, Resolution resolution, Symbol symbol, string filename, DateTime date, TickType tickType) { Date = date; SecurityType = securityType; Market = market; Resolution = resolution; Filename = filename; Symbol = symbol; TickType = tickType; }
/// <summary> /// Full Constructor /// </summary> /// <param name="tickerId">The ticker Id that was specified previously in the call to reqMktData().</param> /// <param name="tickType">Specifies the type of option computation.</param> /// <param name="impliedVol">The implied volatility calculated by the TWS option modeler, using the specificed ticktype value.</param> /// <param name="delta">The option delta calculated by the TWS option modeler.</param> /// <param name="modelPrice">The model price.</param> /// <param name="pvDividend">Present value of dividends expected on the option’s underlier.</param> public TickOptionComputationEventArgs(int tickerId, TickType tickType, double impliedVol, double delta, double modelPrice, double pvDividend) { this.tickerId = tickerId; this.pvDividend = pvDividend; this.delta = delta; this.modelPrice = modelPrice; this.impliedVol = impliedVol; this.tickType = tickType; }
// In Base Class: Last Trade Tick: //public decimal Price = 0; // In Base Class: Ticker String Symbol of the Asset //public string Symbol = ""; // In Base Class: DateTime of this SnapShot //public DateTime Time = new DateTime(); /******************************************************** * CLASS CONSTRUCTORS *********************************************************/ /// <summary> /// Initialize Tick Class /// </summary> public Tick() { base.Value = 0; base.Time = new DateTime(); base.DataType = MarketDataType.Tick; base.Symbol = ""; TickType = TickType.Trade; Quantity = 0; Exchange = ""; SaleCondition = ""; Suspicious = false; }
public Arguments(Symbol symbol, DateTime date, Resolution resolution, string market, TickType tickType) { Symbol = symbol; Date = date; Resolution = resolution; TickType = tickType; Market = market; if (symbol.ID.SecurityType != SecurityType.Option && (resolution == Resolution.Hour || resolution == Resolution.Daily)) { // for the time being this is true, eventually I'm sure we'd like to support hourly/daily quote data in other security types TickType = TickType.Trade; } }
/// <summary> /// Full Constructor /// </summary> /// <param name="tickerId">The ticker Id that was specified previously in the call to reqMktData().</param> /// <param name="tickType">Specifies the type of option computation.</param> /// <param name="impliedVol">The implied volatility calculated by the TWS option modeler, using the specificed ticktype value.</param> /// <param name="delta">The option delta calculated by the TWS option modeler.</param> /// <param name="optionPrice">The model price.</param> /// <param name="pvDividend">Present value of dividends expected on the option’s underlier.</param> /// <param name="gamma">Gamma</param> /// <param name="vega">Vega</param> /// <param name="theta">Theta</param> /// <param name="undPrice">Underlying Price</param> public TickOptionComputationEventArgs(int tickerId, TickType tickType, double impliedVol, double delta, double optionPrice, double pvDividend, double gamma, double vega, double theta, double undPrice) { this.tickerId = tickerId; this.pvDividend = pvDividend; this.delta = delta; this.optionPrice = optionPrice; this.impliedVol = impliedVol; this.tickType = tickType; this.gamma = gamma; this.vega = vega; this.theta = theta; this.underlyingPrice = undPrice; }
/******************************************************** * CLASS CONSTRUCTORS *********************************************************/ /// <summary> /// Initialize Tick Class /// </summary> public Tick() { Price = 0; Type = MarketDataType.Tick; Time = new DateTime(); TickType = TickType.Trade; Quantity = 0; Exchange = ""; SaleCondition = ""; Suspicious = false; DataType = DataType.MarketData; Symbol = ""; }
/// <summary> /// Full Constructor /// </summary> /// <param name="tickerId">The ticker Id that was specified previously in the call to reqMktData().</param> /// <param name="tickType">Specifies the type of price.</param> /// <param name="basisPoints">Annualized basis points, which is representative of the /// financing rate that can be directly compared to broker rates.</param> /// <param name="formattedBasisPoints">Annualized basis points as a formatted string that depicts them in percentage form.</param> /// <param name="impliedFuture">Implied futures price.</param> /// <param name="holdDays">Number of “hold days” until the expiry of the EFP.</param> /// <param name="futureExpiry">Expiration date of the single stock future.</param> /// <param name="dividendImpact">The “dividend impact” upon the annualized basis points interest rate.</param> /// <param name="dividendsToExpiry">The dividends expected until the expiration of the single stock future.</param> public TickEfpEventArgs(int tickerId, TickType tickType, double basisPoints, string formattedBasisPoints, double impliedFuture, int holdDays, string futureExpiry, double dividendImpact, double dividendsToExpiry) { this.tickerId = tickerId; this.dividendsToExpiry = dividendsToExpiry; this.dividendImpact = dividendImpact; this.futureExpiry = futureExpiry; this.holdDays = holdDays; this.impliedFuture = impliedFuture; this.formattedBasisPoints = formattedBasisPoints; this.basisPoints = basisPoints; this.tickType = tickType; }
/// <summary> /// Creates the entry name for a QC zip data file /// </summary> public static string CreateZipEntryName(string symbol, SecurityType securityType, DateTime date, Resolution resolution, TickType dataType = TickType.Trade) { symbol = symbol.ToLower(); if (resolution == Resolution.Hour || resolution == Resolution.Daily) { return symbol + ".csv"; } //All fx is quote data. if (securityType == SecurityType.Forex) dataType = TickType.Quote; return String.Format("{0}_{1}_{2}_{3}.csv", date.ToString(DateFormat.EightCharacter), symbol, resolution.ToString().ToLower(), dataType.ToString().ToLower()); }
/// <summary> /// Create a new lean data writer to this base data directory. /// </summary> /// <param name="symbol">Symbol string</param> /// <param name="dataDirectory">Base data directory</param> /// <param name="resolution">Resolution of the desired output data</param> /// <param name="dataType">Write the data to trade files</param> public LeanDataWriter(Resolution resolution, Symbol symbol, string dataDirectory, TickType dataType = TickType.Trade) { _securityType = symbol.ID.SecurityType; _dataDirectory = dataDirectory; _resolution = resolution; _symbol = symbol; _market = symbol.ID.Market.ToLower(); _dataType = dataType; // All fx data is quote data. if (_securityType == SecurityType.Forex || _securityType == SecurityType.Cfd) { _dataType = TickType.Quote; } // Can only process Fx and equity for now if (_securityType != SecurityType.Equity && _securityType != SecurityType.Forex && _securityType != SecurityType.Cfd) { throw new Exception("Sorry this security type is not yet supported by the LEAN data writer: " + _securityType); } }
private Type GetDataType(SecurityType securityType, Resolution resolution, TickType tickType) { if (resolution == Resolution.Tick) { return typeof (Tick); } switch (securityType) { case SecurityType.Base: case SecurityType.Equity: case SecurityType.Cfd: case SecurityType.Forex: return typeof (TradeBar); case SecurityType.Option: if (tickType == TickType.Trade) return typeof (TradeBar); if (tickType == TickType.Quote) return typeof (QuoteBar); break; } var parameters = string.Join(" | ", securityType, resolution, tickType); throw new NotImplementedException("LeanParser.GetDataType does has not yet implemented: " + parameters); }
/// <summary> /// Creates a data processor that will aggregate and zip the requested resolutions of data /// </summary> public static IDataProcessor Zip(string dataDirectory, IEnumerable<Resolution> resolutions, TickType tickType, bool sourceIsTick) { var set = resolutions.ToHashSet(); var root = new PipeDataProcessor(); // only filter tick sources var stack = !sourceIsTick ? root : (IDataProcessor) new FilteredDataProcessor(root, x => ((Tick) x).TickType == tickType); if (set.Contains(Resolution.Tick)) { // tick is filtered via trade/quote var tick = new CsvDataProcessor(dataDirectory, Resolution.Tick, tickType); root.PipeTo(tick); } if (set.Contains(Resolution.Second)) { root = AddResolution(dataDirectory, tickType, root, Resolution.Second, sourceIsTick); sourceIsTick = false; } if (set.Contains(Resolution.Minute)) { root = AddResolution(dataDirectory, tickType, root, Resolution.Minute, sourceIsTick); sourceIsTick = false; } if (set.Contains(Resolution.Hour)) { root = AddResolution(dataDirectory, tickType, root, Resolution.Hour, sourceIsTick); sourceIsTick = false; } if (set.Contains(Resolution.Daily)) { AddResolution(dataDirectory, tickType, root, Resolution.Daily, sourceIsTick); } return stack; }
/// <summary> /// Generates the zip file name for the specified date of data. /// </summary> public static string GenerateZipFileName(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { var tickTypeString = tickType.TickTypeToLower(); var formattedDate = date.ToStringInvariant(DateFormat.EightCharacter); var isHourOrDaily = resolution == Resolution.Hour || resolution == Resolution.Daily; switch (symbol.ID.SecurityType) { case SecurityType.Base: case SecurityType.Index: case SecurityType.Equity: case SecurityType.Forex: case SecurityType.Cfd: if (isHourOrDaily) { return($"{symbol.Value.ToLowerInvariant()}.zip"); } return($"{formattedDate}_{tickTypeString}.zip"); case SecurityType.Crypto: if (isHourOrDaily) { return($"{symbol.Value.ToLowerInvariant()}_{tickTypeString}.zip"); } return($"{formattedDate}_{tickTypeString}.zip"); case SecurityType.Option: case SecurityType.IndexOption: if (isHourOrDaily) { var optionPath = symbol.Underlying.Value.ToLowerInvariant(); return($"{optionPath}_{tickTypeString}_{symbol.ID.OptionStyle.ToLower()}.zip"); } return($"{formattedDate}_{tickTypeString}_{symbol.ID.OptionStyle.ToLower()}.zip"); case SecurityType.FutureOption: if (isHourOrDaily) { var futureOptionPath = symbol.ID.Symbol.ToLowerInvariant(); return($"{futureOptionPath}_{tickTypeString}_{symbol.ID.OptionStyle.ToLower()}.zip"); } return($"{formattedDate}_{tickTypeString}_{symbol.ID.OptionStyle.ToLower()}.zip"); case SecurityType.Future: if (isHourOrDaily) { return($"{symbol.ID.Symbol.ToLowerInvariant()}_{tickTypeString}.zip"); } return($"{formattedDate}_{tickTypeString}.zip"); case SecurityType.Commodity: default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Parse a tick data line from quantconnect zip source files. /// </summary> /// <param name="reader">The source stream reader</param> /// <param name="date">Base date for the tick (ticks date is stored as int milliseconds since midnight)</param> /// <param name="config">Subscription configuration object</param> public Tick(SubscriptionDataConfig config, StreamReader reader, DateTime date) { try { DataType = MarketDataType.Tick; Symbol = config.Symbol; // Which security type is this data feed: var scaleFactor = GetScaleFactor(config.Symbol); switch (config.SecurityType) { case SecurityType.Equity: { TickType = config.TickType; Time = date.Date.AddMilliseconds((double)reader.GetDecimal()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); bool pastLineEnd; if (TickType == TickType.Trade) { Value = reader.GetDecimal() / scaleFactor; Quantity = reader.GetDecimal(out pastLineEnd); if (!pastLineEnd) { Exchange = reader.GetString(); SaleCondition = reader.GetString(); Suspicious = reader.GetInt32() == 1; } } else if (TickType == TickType.Quote) { BidPrice = reader.GetDecimal() / scaleFactor; BidSize = reader.GetDecimal(); AskPrice = reader.GetDecimal() / scaleFactor; AskSize = reader.GetDecimal(out pastLineEnd); SetValue(); if (!pastLineEnd) { Exchange = reader.GetString(); SaleCondition = reader.GetString(); Suspicious = reader.GetInt32() == 1; } } else { throw new InvalidOperationException($"Tick(): Unexpected tick type {TickType}"); } break; } case SecurityType.Forex: case SecurityType.Cfd: { TickType = TickType.Quote; Time = date.Date.AddMilliseconds((double)reader.GetDecimal()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); BidPrice = reader.GetDecimal(); AskPrice = reader.GetDecimal(); SetValue(); break; } case SecurityType.Crypto: { TickType = config.TickType; Exchange = config.Market; if (TickType == TickType.Trade) { Time = date.Date.AddMilliseconds((double)reader.GetDecimal()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); Value = reader.GetDecimal(); Quantity = reader.GetDecimal(); } if (TickType == TickType.Quote) { Time = date.Date.AddMilliseconds((double)reader.GetDecimal()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); BidPrice = reader.GetDecimal(); BidSize = reader.GetDecimal(); AskPrice = reader.GetDecimal(); AskSize = reader.GetDecimal(); SetValue(); } break; } case SecurityType.Future: case SecurityType.Option: case SecurityType.FutureOption: case SecurityType.IndexOption: { TickType = config.TickType; Time = date.Date.AddMilliseconds((double)reader.GetDecimal()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); if (TickType == TickType.Trade) { Value = reader.GetDecimal() / scaleFactor; Quantity = reader.GetDecimal(); Exchange = reader.GetString(); SaleCondition = reader.GetString(); Suspicious = reader.GetInt32() == 1; } else if (TickType == TickType.OpenInterest) { Value = reader.GetDecimal(); } else { BidPrice = reader.GetDecimal() / scaleFactor; BidSize = reader.GetDecimal(); AskPrice = reader.GetDecimal() / scaleFactor; AskSize = reader.GetDecimal(); Exchange = reader.GetString(); Suspicious = reader.GetInt32() == 1; SetValue(); } break; } } } catch (Exception err) { Log.Error(err); } }
/// <summary> /// Parse a tick data line from quantconnect zip source files. /// </summary> /// <param name="line">CSV source line of the compressed source</param> /// <param name="date">Base date for the tick (ticks date is stored as int milliseconds since midnight)</param> /// <param name="config">Subscription configuration object</param> public Tick(SubscriptionDataConfig config, string line, DateTime date) { try { DataType = MarketDataType.Tick; Symbol = config.Symbol; // Which security type is this data feed: var scaleFactor = GetScaleFactor(config.Symbol); switch (config.SecurityType) { case SecurityType.Equity: { var index = 0; TickType = config.TickType; var csv = line.ToCsv(TickType == TickType.Trade ? 6 : 8); Time = date.Date.AddMilliseconds(csv[index++].ToInt64()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); if (TickType == TickType.Trade) { Value = csv[index++].ToDecimal() / scaleFactor; Quantity = csv[index++].ToDecimal(); if (csv.Count > index) { Exchange = csv[index++]; SaleCondition = csv[index++]; Suspicious = (csv[index++] == "1"); } } else if (TickType == TickType.Quote) { BidPrice = csv[index++].ToDecimal() / scaleFactor; BidSize = csv[index++].ToDecimal(); AskPrice = csv[index++].ToDecimal() / scaleFactor; AskSize = csv[index++].ToDecimal(); SetValue(); if (csv.Count > index) { Exchange = csv[index++]; SaleCondition = csv[index++]; Suspicious = (csv[index++] == "1"); } } else { throw new InvalidOperationException($"Tick(): Unexpected tick type {TickType}"); } break; } case SecurityType.Forex: case SecurityType.Cfd: { var csv = line.ToCsv(3); TickType = TickType.Quote; var ticks = (long)(csv[0].ToDecimal() * TimeSpan.TicksPerMillisecond); Time = date.Date.AddTicks(ticks) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); BidPrice = csv[1].ToDecimal(); AskPrice = csv[2].ToDecimal(); SetValue(); break; } case SecurityType.Crypto: { TickType = config.TickType; Exchange = config.Market; if (TickType == TickType.Trade) { var csv = line.ToCsv(3); Time = date.Date.AddMilliseconds((double)csv[0].ToDecimal()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); Value = csv[1].ToDecimal(); Quantity = csv[2].ToDecimal(); } if (TickType == TickType.Quote) { var csv = line.ToCsv(6); Time = date.Date.AddMilliseconds((double)csv[0].ToDecimal()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); BidPrice = csv[1].ToDecimal(); BidSize = csv[2].ToDecimal(); AskPrice = csv[3].ToDecimal(); AskSize = csv[4].ToDecimal(); SetValue(); } break; } case SecurityType.Future: case SecurityType.Option: case SecurityType.FutureOption: case SecurityType.IndexOption: { var csv = line.ToCsv(7); TickType = config.TickType; Time = date.Date.AddMilliseconds(csv[0].ToInt64()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); if (TickType == TickType.Trade) { Value = csv[1].ToDecimal() / scaleFactor; Quantity = csv[2].ToDecimal(); Exchange = csv[3]; SaleCondition = csv[4]; Suspicious = csv[5] == "1"; } else if (TickType == TickType.OpenInterest) { Value = csv[1].ToDecimal(); } else { if (csv[1].Length != 0) { BidPrice = csv[1].ToDecimal() / scaleFactor; BidSize = csv[2].ToDecimal(); } if (csv[3].Length != 0) { AskPrice = csv[3].ToDecimal() / scaleFactor; AskSize = csv[4].ToDecimal(); } Exchange = csv[5]; Suspicious = csv[6] == "1"; SetValue(); } break; } } } catch (Exception err) { Log.Error(err); } }
/// <summary> /// Constructor for Data Subscriptions /// </summary> /// <param name="objectType">Type of the data objects.</param> /// <param name="symbol">Symbol of the asset we're requesting</param> /// <param name="resolution">Resolution of the asset we're requesting</param> /// <param name="dataTimeZone">The time zone the raw data is time stamped in</param> /// <param name="exchangeTimeZone">Specifies the time zone of the exchange for the security this subscription is for. This /// is this output time zone, that is, the time zone that will be used on BaseData instances</param> /// <param name="fillForward">Fill in gaps with historical data</param> /// <param name="extendedHours">Equities only - send in data from 4am - 8pm</param> /// <param name="isInternalFeed">Set to true if this subscription is added for the sole purpose of providing currency conversion rates, /// setting this flag to true will prevent the data from being sent into the algorithm's OnData methods</param> /// <param name="isCustom">True if this is user supplied custom data, false for normal QC data</param> /// <param name="tickType">Specifies if trade or quote data is subscribed</param> /// <param name="isFilteredSubscription">True if this subscription should have filters applied to it (market hours/user filters from security), false otherwise</param> /// <param name="dataNormalizationMode">Specifies normalization mode used for this subscription</param> public SubscriptionDataConfig(Type objectType, Symbol symbol, Resolution resolution, DateTimeZone dataTimeZone, DateTimeZone exchangeTimeZone, bool fillForward, bool extendedHours, bool isInternalFeed, bool isCustom = false, TickType?tickType = null, bool isFilteredSubscription = true, DataNormalizationMode dataNormalizationMode = DataNormalizationMode.Adjusted) { if (objectType == null) { throw new ArgumentNullException(nameof(objectType)); } if (symbol == null) { throw new ArgumentNullException(nameof(symbol)); } if (dataTimeZone == null) { throw new ArgumentNullException(nameof(dataTimeZone)); } if (exchangeTimeZone == null) { throw new ArgumentNullException(nameof(exchangeTimeZone)); } Type = objectType; SecurityType = symbol.ID.SecurityType; Resolution = resolution; _sid = symbol.ID; Symbol = symbol; FillDataForward = fillForward; ExtendedMarketHours = extendedHours; PriceScaleFactor = 1; IsInternalFeed = isInternalFeed; IsCustomData = isCustom; Market = symbol.ID.Market; DataTimeZone = dataTimeZone; ExchangeTimeZone = exchangeTimeZone; IsFilteredSubscription = isFilteredSubscription; Consolidators = new HashSet <IDataConsolidator>(); DataNormalizationMode = dataNormalizationMode; TickType = tickType ?? LeanData.GetCommonTickTypeForCommonDataTypes(objectType, SecurityType); switch (resolution) { case Resolution.Tick: //Ticks are individual sales and fillforward doesn't apply. Increment = TimeSpan.FromSeconds(0); FillDataForward = false; break; case Resolution.Second: Increment = TimeSpan.FromSeconds(1); break; case Resolution.Minute: Increment = TimeSpan.FromMinutes(1); break; case Resolution.Hour: Increment = TimeSpan.FromHours(1); break; case Resolution.Daily: Increment = TimeSpan.FromDays(1); break; default: throw new InvalidEnumArgumentException(Invariant($"Unexpected Resolution: {resolution}")); } }
/// <summary> /// Subscribes the given symbol /// </summary> /// <param name="symbol">The symbol</param> /// <param name="tickType">Type of tick data</param> public void Subscribe(Symbol symbol, TickType tickType) { Subscribe(symbol, tickType, true); }
/// <summary> /// Constructor for QuantConnect tick data /// </summary> /// <param name="symbol">Symbol for underlying asset</param> /// <param name="line">CSV line of data from QC tick csv</param> /// <param name="baseDate">The base date of the tick</param> public Tick(string symbol, string line, DateTime baseDate) { var csv = line.Split(','); DataType = MarketDataType.Tick; Symbol = symbol; Time = baseDate.Date.AddMilliseconds(csv[0].ToInt32()); Value = csv[1].ToDecimal()/10000m; TickType = TickType.Trade; Quantity = csv[2].ToInt32(); Exchange = csv[3].Trim(); SaleCondition = csv[4]; Suspicious = csv[5].ToInt32() == 1; }
private void ConvertMinuteFuturesData(Symbol canonical, TickType tickType, Resolution outputResolution, Resolution inputResolution = Resolution.Minute) { var timeSpans = new Dictionary <Resolution, TimeSpan>() { { Resolution.Daily, TimeSpan.FromHours(24) }, { Resolution.Hour, TimeSpan.FromHours(1) }, }; var timeSpan = timeSpans[outputResolution]; var tickTypeConsolidatorMap = new Dictionary <TickType, Func <IDataConsolidator> >() { { TickType.Quote, () => new QuoteBarConsolidator(timeSpan) }, { TickType.OpenInterest, () => new OpenInterestConsolidator(timeSpan) }, { TickType.Trade, () => new TradeBarConsolidator(timeSpan) } }; var consolidators = new Dictionary <string, IDataConsolidator>(); var configs = new Dictionary <string, SubscriptionDataConfig>(); var outputFiles = new Dictionary <string, StringBuilder>(); var futures = new Dictionary <string, Symbol>(); var date = _fromDate; while (date <= _toDate) { var futureChain = LoadFutureChain(canonical, date, tickType, inputResolution); foreach (var future in futureChain) { if (!futures.ContainsKey(future.Value)) { futures[future.Value] = future; var config = new SubscriptionDataConfig(LeanData.GetDataType(outputResolution, tickType), future, inputResolution, TimeZones.NewYork, TimeZones.NewYork, false, false, false, false, tickType); configs[future.Value] = config; consolidators[future.Value] = tickTypeConsolidatorMap[tickType].Invoke(); var sb = new StringBuilder(); outputFiles[future.Value] = sb; consolidators[future.Value].DataConsolidated += (sender, bar) => { sb.Append(LeanData.GenerateLine(bar, SecurityType.Future, outputResolution) + Environment.NewLine); }; } var leanDataReader = new LeanDataReader(configs[future.Value], future, inputResolution, date, _dataDirectory); var consolidator = consolidators[future.Value]; foreach (var bar in leanDataReader.Parse()) { consolidator.Update(bar); } } date = date.AddDays(1); } //write all results foreach (var consolidator in consolidators.Values) { consolidator.Scan(date); } var zip = LeanData.GenerateRelativeZipFilePath(canonical, _fromDate, outputResolution, tickType); var zipPath = Path.Combine(_dataDirectory, zip); var fi = new FileInfo(zipPath); if (!fi.Directory.Exists) { fi.Directory.Create(); } foreach (var future in futures.Values) { var zipEntry = LeanData.GenerateZipEntryName(future, _fromDate, outputResolution, tickType); var sb = outputFiles[future.Value]; //Uncomment to write zip files //QuantConnect.Compression.ZipCreateAppendData(zipPath, zipEntry, sb.ToString()); Assert.IsTrue(sb.Length > 0); } }
private int GetTickTypeOrder(SecurityType securityType, TickType tickType) { return(SubscriptionManager.AvailableDataTypes[securityType].IndexOf(tickType)); }
private void ibClient_Tick(TickOptionMessage msg) { if (isDebug) { Console.WriteLine("Tick Option. Ticker Id: {0}, Symbol: {1}, Type: {2}", msg.RequestId, dicAssets[msg.RequestId].Con.Symbol, TickType.getField(msg.Field)); Console.WriteLine("Delta: {0}, Gamma: {1}, Vega: {2}, Theta: {3}, IV: {4}, OptPrice: {5}, PvDividend: {6}, UndPrice: {7}", msg.Delta, msg.Gamma, msg.Vega, msg.Theta, msg.ImpliedVolatility, msg.OptPrice, msg.PvDividend, msg.UndPrice); } dicAssets[msg.RequestId].ImpliedVolatility = msg.ImpliedVolatility; dicAssets[msg.RequestId].Delta = msg.Delta; dicAssets[msg.RequestId].Gamma = msg.Gamma; dicAssets[msg.RequestId].Vega = msg.Vega; dicAssets[msg.RequestId].Theta = msg.Theta; dicAssets[msg.RequestId].OptPrice = msg.OptPrice; dicAssets[msg.RequestId].PvDividend = msg.PvDividend; dicAssets[msg.RequestId].UndPrice = msg.UndPrice; if (OnGreeksEvent != null) { OnGreeksMessage e = new OnGreeksMessage(); e.RequestId = msg.RequestId; e.Symbol = dicAssets[msg.RequestId].Con.Symbol; e.AssetID = dicAssets[msg.RequestId].ID; e.Type = TickType.getField(msg.Field); e.Delta = msg.Delta; e.Gamma = msg.Gamma; e.Vega = msg.Vega; e.Theta = msg.Theta; e.ImpliedVolatility = msg.ImpliedVolatility; e.OptPrice = msg.OptPrice; e.PvDividend = msg.PvDividend; e.UndPrice = msg.UndPrice; OnGreeksEvent(e); } }
private void ibClient_Tick(TickSizeMessage msg) { if (isDebug) { Console.WriteLine("Tick Size. Ticker Id: {0}, Symbol: {1}, Type: {2}, Size: {3}", msg.RequestId, dicAssets[msg.RequestId].Con.Symbol, TickType.getField(msg.Field), msg.Size); } switch (msg.Field) { case TickType.ASK_SIZE: dicAssets[msg.RequestId].AskSize = msg.Size; break; case TickType.BID_SIZE: dicAssets[msg.RequestId].BidSize = msg.Size; break; } }
private void ibClient_Tick(TickPriceMessage msg) { if (isDebug) { Console.WriteLine("Tick Price. Ticker Id:{1}, Symbol: {2}, Type: {3}, Price: {4}, Pre-Open: {4}", msg.RequestId, dicAssets[msg.RequestId].Con.Symbol, TickType.getField(msg.Field), msg.Price, msg.Attribs.PreOpen); } switch (msg.Field) { case TickType.ASK: case TickType.DELAYED_ASK: dicAssets[msg.RequestId].Ask = msg.Price; break; case TickType.BID: case TickType.DELAYED_BID: dicAssets[msg.RequestId].Bid = msg.Price; break; case TickType.LAST: case TickType.DELAYED_LAST: dicAssets[msg.RequestId].Last = msg.Price; break; } if (OnPriceEvent != null) { OnPriceMessage e = new OnPriceMessage(); e.RequestId = msg.RequestId; e.Symbol = dicAssets[msg.RequestId].Con.Symbol; e.AssetID = dicAssets[msg.RequestId].ID; e.Type = TickType.getField(msg.Field); e.Price = msg.Price; e.PreOpen = msg.Attribs.PreOpen; OnPriceEvent(e); } }
/// <summary> /// Parse a tick data line from quantconnect zip source files. /// </summary> /// <param name="line">CSV source line of the compressed source</param> /// <param name="date">Base date for the tick (ticks date is stored as int milliseconds since midnight)</param> /// <param name="config">Subscription configuration object</param> public Tick(SubscriptionDataConfig config, string line, DateTime date) { try { DataType = MarketDataType.Tick; // Which security type is this data feed: switch (config.SecurityType) { case SecurityType.Equity: { var csv = line.ToCsv(6); Symbol = config.Symbol; Time = date.Date.AddMilliseconds(csv[0].ToInt64()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); Value = config.GetNormalizedPrice(csv[1].ToDecimal() / 10000m); TickType = TickType.Trade; Quantity = csv[2].ToInt32(); if (csv.Count > 3) { Exchange = csv[3]; SaleCondition = csv[4]; Suspicious = (csv[5] == "1"); } break; } case SecurityType.Forex: case SecurityType.Cfd: { var csv = line.ToCsv(3); Symbol = config.Symbol; TickType = TickType.Quote; Time = date.Date.AddMilliseconds(csv[0].ToInt64()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); BidPrice = csv[1].ToDecimal(); AskPrice = csv[2].ToDecimal(); Value = (BidPrice + AskPrice) / 2; break; } } } catch (Exception err) { Log.Error(err); } }
/// <summary> /// Initializer for a last-trade equity tick with bid or ask prices. /// </summary> /// <param name="time">Full date and time</param> /// <param name="symbol">Underlying equity security symbol</param> /// <param name="bid">Bid value</param> /// <param name="ask">Ask value</param> /// <param name="last">Last trade price</param> public Tick(DateTime time, string symbol, decimal last, decimal bid, decimal ask) { DataType = MarketDataType.Tick; Time = time; Symbol = symbol; Value = last; TickType = TickType.Quote; BidPrice = bid; AskPrice = ask; }
private Subscription CreateSubscription(Resolution resolution, string symbol = "AAPL", bool isInternalFeed = false, SecurityType type = SecurityType.Equity, TickType tickType = TickType.Trade) { var start = DateTime.UtcNow; var end = start.AddSeconds(10); Security security; Symbol _symbol; if (type == SecurityType.Equity) { _symbol = new Symbol(SecurityIdentifier.GenerateEquity(DateTime.Now, symbol, Market.USA), symbol); security = new Equity( _symbol, SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), new Cash(Currencies.USD, 0, 1), SymbolProperties.GetDefault(Currencies.USD), ErrorCurrencyConverter.Instance ); } else if (type == SecurityType.Option) { _symbol = new Symbol(SecurityIdentifier.GenerateOption(DateTime.Now, SecurityIdentifier.GenerateEquity(DateTime.Now, symbol, Market.USA), Market.USA, 0.0m, OptionRight.Call, OptionStyle.American), symbol); security = new Option( _symbol, SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), new Cash(Currencies.USD, 0, 1), new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)), ErrorCurrencyConverter.Instance ); } else if (type == SecurityType.Future) { _symbol = new Symbol(SecurityIdentifier.GenerateFuture(DateTime.Now, symbol, Market.USA), symbol); security = new Future( _symbol, SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), new Cash(Currencies.USD, 0, 1), SymbolProperties.GetDefault(Currencies.USD), ErrorCurrencyConverter.Instance ); } else { throw new Exception("SecurityType not implemented"); } var config = new SubscriptionDataConfig(typeof(TradeBar), _symbol, resolution, DateTimeZone.Utc, DateTimeZone.Utc, true, false, isInternalFeed, false, tickType); var timeZoneOffsetProvider = new TimeZoneOffsetProvider(DateTimeZone.Utc, start, end); var enumerator = new EnqueueableEnumerator <BaseData>(); var subscriptionDataEnumerator = new SubscriptionDataEnumerator(config, security.Exchange.Hours, timeZoneOffsetProvider, enumerator); var subscriptionRequest = new SubscriptionRequest(false, null, security, config, start, end); return(new Subscription(subscriptionRequest, subscriptionDataEnumerator, timeZoneOffsetProvider)); }
/// <summary> /// Unsubscribes the given symbol /// </summary> /// <param name="symbol">The symbol</param> /// <param name="tickType">Type of tick data</param> public void Unsubscribe(Symbol symbol, TickType tickType) { Subscribe(symbol, tickType, false); }
/// <summary> /// Generates the relative zip file path rooted in the /Data directory /// </summary> public static string GenerateRelativeZipFilePath(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { return Path.Combine(GenerateRelativeZipFileDirectory(symbol, resolution), GenerateZipFileName(symbol, date, resolution, tickType)); }
public void tickString(int tickerId, int field, string value) { WriteMessageToConsole( $"Tick String. TickerId: {tickerId}, Type: {TickType.getField(field)}, Value: {value}"); }
/// <summary> /// Creates the entry name for a QC zip data file /// </summary> public static string GenerateZipEntryName(string symbol, SecurityType securityType, DateTime date, Resolution resolution, TickType dataType = TickType.Trade) { if (securityType != SecurityType.Base && securityType != SecurityType.Equity && securityType != SecurityType.Forex && securityType != SecurityType.Cfd) { throw new NotImplementedException("This method only implements base, equity, forex and cfd security type."); } symbol = symbol.ToLower(); if (resolution == Resolution.Hour || resolution == Resolution.Daily) { return symbol + ".csv"; } //All fx is quote data. if (securityType == SecurityType.Forex || securityType == SecurityType.Cfd) { dataType = TickType.Quote; } return string.Format("{0}_{1}_{2}_{3}.csv", date.ToString(DateFormat.EightCharacter), symbol, resolution.ToLower(), dataType.ToLower()); }
/// <summary> /// Parse a tick data line from quantconnect zip source files. /// </summary> /// <param name="line">CSV source line of the compressed source</param> /// <param name="date">Base date for the tick (ticks date is stored as int milliseconds since midnight)</param> /// <param name="config">Subscription configuration object</param> public Tick(SubscriptionDataConfig config, string line, DateTime date) { try { DataType = MarketDataType.Tick; // Which security type is this data feed: var scaleFactor = GetScaleFactor(config.SecurityType); switch (config.SecurityType) { case SecurityType.Equity: { var csv = line.ToCsv(6); Symbol = config.Symbol; Time = date.Date.AddMilliseconds(csv[0].ToInt64()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); Value = config.GetNormalizedPrice(csv[1].ToDecimal() / scaleFactor); TickType = TickType.Trade; Quantity = csv[2].ToDecimal(); if (csv.Count > 3) { Exchange = csv[3]; SaleCondition = csv[4]; Suspicious = (csv[5] == "1"); } break; } case SecurityType.Forex: case SecurityType.Cfd: { var csv = line.ToCsv(3); Symbol = config.Symbol; TickType = TickType.Quote; var ticks = (long)(csv[0].ToDecimal() * TimeSpan.TicksPerMillisecond); Time = date.Date.AddTicks(ticks) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); BidPrice = csv[1].ToDecimal(); AskPrice = csv[2].ToDecimal(); Value = (BidPrice + AskPrice) / 2; break; } case SecurityType.Crypto: { TickType = config.TickType; Symbol = config.Symbol; Exchange = config.Market; if (TickType == TickType.Trade) { var csv = line.ToCsv(3); Time = date.Date.AddMilliseconds(csv[0].ToInt64()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); Value = csv[1].ToDecimal(); Quantity = csv[2].ToDecimal(); } if (TickType == TickType.Quote) { var csv = line.ToCsv(6); Time = date.Date.AddMilliseconds(csv[0].ToInt64()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); BidPrice = csv[1].ToDecimal(); BidSize = csv[2].ToDecimal(); AskPrice = csv[3].ToDecimal(); AskSize = csv[4].ToDecimal(); Value = (BidPrice + AskPrice) / 2; } break; } case SecurityType.Future: case SecurityType.Option: { var csv = line.ToCsv(7); TickType = config.TickType; Time = date.Date.AddMilliseconds(csv[0].ToInt64()) .ConvertTo(config.DataTimeZone, config.ExchangeTimeZone); Symbol = config.Symbol; if (TickType == TickType.Trade) { Value = config.GetNormalizedPrice(csv[1].ToDecimal() / scaleFactor); Quantity = csv[2].ToDecimal(); Exchange = csv[3]; SaleCondition = csv[4]; Suspicious = csv[5] == "1"; } else if (TickType == TickType.OpenInterest) { Value = csv[1].ToDecimal(); } else { if (csv[1].Length != 0) { BidPrice = config.GetNormalizedPrice(csv[1].ToDecimal() / scaleFactor); BidSize = csv[2].ToDecimal(); } if (csv[3].Length != 0) { AskPrice = config.GetNormalizedPrice(csv[3].ToDecimal() / scaleFactor); AskSize = csv[4].ToDecimal(); } Exchange = csv[5]; Suspicious = csv[6] == "1"; if (BidPrice != 0) { if (AskPrice != 0) { Value = (BidPrice + AskPrice) / 2m; } else { Value = BidPrice; } } else { Value = AskPrice; } } break; } } } catch (Exception err) { Log.Error(err); } }
/// <summary> /// Creates the zip file name for a QC zip data file /// </summary> public static string GenerateZipFileName(string symbol, SecurityType securityType, DateTime date, Resolution resolution, TickType? tickType = null) { if (resolution == Resolution.Hour || resolution == Resolution.Daily) { return symbol.ToLower() + ".zip"; } var zipFileName = date.ToString(DateFormat.EightCharacter); tickType = tickType ?? (securityType == SecurityType.Forex || securityType == SecurityType.Cfd ? TickType.Quote : TickType.Trade); var suffix = string.Format("_{0}.zip", tickType.Value.ToLower()); return zipFileName + suffix; }
/// <summary> /// Use the lean data writer to write the ticks for a specific resolution /// </summary> /// <param name="symbol">The symbol these ticks represent</param> /// <param name="resolution">The resolution that should be written</param> /// <param name="tickType">The tpye (Trades/Quotes) </param> /// <param name="bars">The aggregated bars being written to disk</param> private static void WriteTradeTicksForResolution(Symbol symbol, Resolution resolution, TickType tickType, List <BaseData> bars) { var writer = new LeanDataWriter(resolution, symbol, Globals.DataFolder, tickType); writer.Write(bars); }
/// <summary> /// Full Constructor /// </summary> /// <param name="tickerId">The ticker Id that was specified previously in the call to reqMktData().</param> /// <param name="tickType">Specifies the type of price.</param> /// <param name="value">The value of the specified field.</param> public TickGenericEventArgs(int tickerId, TickType tickType, double value) { this.tickerId = tickerId; this.value = value; this.tickType = tickType; }
/// <summary> /// Downloads historical data from the brokerage and saves it in LEAN format. /// </summary> /// <param name="symbols">The list of symbols</param> /// <param name="tickType">The tick type</param> /// <param name="resolution">The resolution</param> /// <param name="securityType">The security type</param> /// <param name="startTimeUtc">The starting date/time (UTC)</param> /// <param name="endTimeUtc">The ending date/time (UTC)</param> public void DownloadAndSave(List <Symbol> symbols, Resolution resolution, SecurityType securityType, TickType tickType, DateTime startTimeUtc, DateTime endTimeUtc) { var writer = new LeanDataWriter(Globals.DataFolder, resolution, securityType, tickType); writer.DownloadAndSave(_brokerage, symbols, startTimeUtc, endTimeUtc); }
/// <summary> /// Cloner constructor for fill forward engine implementation. Clone the original tick into this new tick: /// </summary> /// <param name="original">Original tick we're cloning</param> public Tick(Tick original) { Symbol = original.Symbol; Time = new DateTime(original.Time.Ticks); Value = original.Value; BidPrice = original.BidPrice; AskPrice = original.AskPrice; Exchange = original.Exchange; SaleCondition = original.SaleCondition; Quantity = original.Quantity; Suspicious = original.Suspicious; DataType = MarketDataType.Tick; TickType = original.TickType; BidSize = original.BidSize; AskSize = original.AskSize; }
public void Performance(Type streamReaderType, Type readLineReaderType, TickType tickType) { var streamReaderMilliSeconds = 0L; var streamReaderCount = 0; var getLineReaderMilliSeconds = 0L; var getLineReaderCount = 0; var stopWatch = new Stopwatch(); { var config = new SubscriptionDataConfig( streamReaderType, Symbols.SPY, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, false, true, false, tickType: tickType ); var zipCache = new ZipDataCacheProvider(new DefaultDataProvider()); var date = new DateTime(2013, 10, 07); var reader = new TextSubscriptionDataSourceReader( zipCache, config, date, false); var source = streamReaderType.GetBaseDataInstance().GetSource(config, date, false); // warmup streamReaderCount = reader.Read(source).Count(); streamReaderCount = 0; // start test stopWatch.Start(); for (int i = 0; i < 200; i++) { streamReaderCount += reader.Read(source).Count(); } stopWatch.Stop(); streamReaderMilliSeconds = stopWatch.ElapsedMilliseconds; zipCache.DisposeSafely(); } { var config = new SubscriptionDataConfig( readLineReaderType, Symbols.SPY, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, false, true, false, tickType: tickType ); var zipCache = new ZipDataCacheProvider(new DefaultDataProvider()); var date = new DateTime(2013, 10, 07); var reader = new TextSubscriptionDataSourceReader( zipCache, config, date, false); var source = readLineReaderType.GetBaseDataInstance().GetSource(config, date, false); // warmup getLineReaderCount = reader.Read(source).Count(); getLineReaderCount = 0; // start test stopWatch.Start(); for (int i = 0; i < 200; i++) { getLineReaderCount += reader.Read(source).Count(); } stopWatch.Stop(); getLineReaderMilliSeconds = stopWatch.ElapsedMilliseconds; zipCache.DisposeSafely(); } Console.WriteLine($"StreamReader: {streamReaderMilliSeconds}ms. Count {streamReaderCount}"); Console.WriteLine($"GetLine Reader: {getLineReaderMilliSeconds}ms. Count {getLineReaderCount}"); // its 50% faster but lets leave some room to avoid noise Assert.IsTrue((streamReaderMilliSeconds * 1.85d) < getLineReaderMilliSeconds); Assert.AreEqual(getLineReaderCount, streamReaderCount); }
/// <summary> /// Generate's the zip entry name to hold the specified data. /// </summary> public static string GenerateZipEntryName(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { var formattedDate = date.ToStringInvariant(DateFormat.EightCharacter); var isHourOrDaily = resolution == Resolution.Hour || resolution == Resolution.Daily; switch (symbol.ID.SecurityType) { case SecurityType.Base: case SecurityType.Equity: case SecurityType.Index: case SecurityType.Forex: case SecurityType.Cfd: case SecurityType.Crypto: if (resolution == Resolution.Tick && symbol.SecurityType == SecurityType.Equity) { return(Invariant($"{formattedDate}_{symbol.Value.ToLowerInvariant()}_{tickType}_{resolution}.csv")); } if (isHourOrDaily) { return($"{symbol.Value.ToLowerInvariant()}.csv"); } return(Invariant($"{formattedDate}_{symbol.Value.ToLowerInvariant()}_{resolution.ResolutionToLower()}_{tickType.TickTypeToLower()}.csv")); case SecurityType.Option: case SecurityType.IndexOption: var optionPath = symbol.Underlying.Value.ToLowerInvariant(); if (isHourOrDaily) { return(string.Join("_", optionPath, tickType.TickTypeToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToStringInvariant(DateFormat.EightCharacter) ) + ".csv"); } return(string.Join("_", formattedDate, optionPath, resolution.ResolutionToLower(), tickType.TickTypeToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToStringInvariant(DateFormat.EightCharacter) ) + ".csv"); case SecurityType.FutureOption: // We want the future option ticker as the lookup name inside the ZIP file var futureOptionPath = symbol.ID.Symbol.ToLowerInvariant(); if (isHourOrDaily) { return(string.Join("_", futureOptionPath, tickType.TickTypeToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToStringInvariant(DateFormat.EightCharacter) ) + ".csv"); } return(string.Join("_", formattedDate, futureOptionPath, resolution.ResolutionToLower(), tickType.TickTypeToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToStringInvariant(DateFormat.EightCharacter) ) + ".csv"); case SecurityType.Future: var expiryDate = symbol.ID.Date; var monthsToAdd = FuturesExpiryUtilityFunctions.GetDeltaBetweenContractMonthAndContractExpiry(symbol.ID.Symbol, expiryDate.Date); var contractYearMonth = expiryDate.AddMonths(monthsToAdd).ToStringInvariant(DateFormat.YearMonth); if (isHourOrDaily) { return(string.Join("_", symbol.ID.Symbol.ToLowerInvariant(), tickType.TickTypeToLower(), contractYearMonth, expiryDate.ToStringInvariant(DateFormat.EightCharacter) ) + ".csv"); } return(string.Join("_", formattedDate, symbol.ID.Symbol.ToLowerInvariant(), resolution.ResolutionToLower(), tickType.TickTypeToLower(), contractYearMonth, expiryDate.ToStringInvariant(DateFormat.EightCharacter) ) + ".csv"); case SecurityType.Commodity: default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Generate's the zip entry name to hold the specified data. /// </summary> public static string GenerateZipEntryName(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { var formattedDate = date.ToString(DateFormat.EightCharacter); var isHourOrDaily = resolution == Resolution.Hour || resolution == Resolution.Daily; switch (symbol.ID.SecurityType) { case SecurityType.Base: case SecurityType.Equity: case SecurityType.Forex: case SecurityType.Cfd: if (isHourOrDaily) { return string.Format("{0}.csv", symbol.Value.ToLower() ); } return string.Format("{0}_{1}_{2}_{3}.csv", formattedDate, symbol.Value.ToLower(), resolution.ToLower(), tickType.ToLower() ); case SecurityType.Option: if (isHourOrDaily) { return string.Join("_", symbol.ID.Symbol.ToLower(), // underlying tickType.ToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToString(DateFormat.EightCharacter) ) + ".csv"; } return string.Join("_", formattedDate, symbol.ID.Symbol.ToLower(), // underlying resolution.ToLower(), tickType.ToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToString(DateFormat.EightCharacter) ) + ".csv"; case SecurityType.Commodity: case SecurityType.Future: default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Generates the zip file name for the specified date of data. /// </summary> public static string GenerateZipFileName(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { var tickTypeString = tickType.ToLower(); var formattedDate = date.ToString(DateFormat.EightCharacter); var isHourOrDaily = resolution == Resolution.Hour || resolution == Resolution.Daily; switch (symbol.ID.SecurityType) { case SecurityType.Base: case SecurityType.Equity: case SecurityType.Forex: case SecurityType.Cfd: if (isHourOrDaily) { return string.Format("{0}.zip", symbol.Value.ToLower() ); } return string.Format("{0}_{1}.zip", formattedDate, tickTypeString ); case SecurityType.Option: if (isHourOrDaily) { return string.Format("{0}_{1}_{2}.zip", symbol.ID.Symbol.ToLower(), // underlying tickTypeString, symbol.ID.OptionStyle.ToLower() ); } return string.Format("{0}_{1}_{2}.zip", formattedDate, tickTypeString, symbol.ID.OptionStyle.ToLower() ); case SecurityType.Commodity: case SecurityType.Future: default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Helper to get history for tests from a brokerage implementation /// </summary> /// <returns>List of data points from history request</returns> private List <BaseData> GetHistory(IBrokerage brokerage, Resolution resolution, SecurityType securityType, Symbol symbol, TickType tickType, DateTime startTimeUtc, DateTime endTimeUtc) { var dataType = LeanData.GetDataType(resolution, tickType); var marketHoursDatabase = MarketHoursDatabase.FromDataFolder(); var ticker = symbol.ID.Symbol; var market = symbol.ID.Market; var canonicalSymbol = Symbol.Create(ticker, securityType, market); var exchangeHours = marketHoursDatabase.GetExchangeHours(canonicalSymbol.ID.Market, canonicalSymbol, securityType); var dataTimeZone = marketHoursDatabase.GetDataTimeZone(canonicalSymbol.ID.Market, canonicalSymbol, securityType); var historyRequest = new HistoryRequest( startTimeUtc, endTimeUtc, dataType, symbol, resolution, exchangeHours, dataTimeZone, resolution, true, false, DataNormalizationMode.Raw, tickType ); return(brokerage.GetHistory(historyRequest) .Select( x => { // Convert to date timezone before we write it x.Time = x.Time.ConvertTo(exchangeHours.TimeZone, dataTimeZone); return x; }) .ToList()); }
/// <summary> /// Calculates a trade. /// </summary> private void CalculateTrade(TickType ticktype) { // Exit bool closeOK = false; if (_closeStrPriceType != StrategyPriceType.CloseAndReverse && Data.PositionTicket != 0) { if (_closeStrPriceType == StrategyPriceType.Open && (ticktype == TickType.Open || ticktype == TickType.OpenClose) || _closeStrPriceType == StrategyPriceType.Close && (ticktype == TickType.Close || ticktype == TickType.OpenClose)) { // Exit at Bar Open or Bar Close. TradeDirection direction = AnalyseExitDirection(); if (direction == TradeDirection.Both || (direction == TradeDirection.Long && Data.PositionDirection == PosDirection.Short) || (direction == TradeDirection.Short && Data.PositionDirection == PosDirection.Long)) closeOK = DoExitTrade(); // Close the current position. } else if (_closeStrPriceType == StrategyPriceType.Indicator) { // Exit at an indicator value. TradeDirection priceReached = AnalyseExitPrice(); if (priceReached == TradeDirection.Long) { TradeDirection direction = AnalyseExitDirection(); if (direction == TradeDirection.Long || direction == TradeDirection.Both) if (Data.PositionDirection == PosDirection.Short) closeOK = DoExitTrade(); // Close a short position. } else if (priceReached == TradeDirection.Short) { TradeDirection direction = AnalyseExitDirection(); if (direction == TradeDirection.Short || direction == TradeDirection.Both) if (Data.PositionDirection == PosDirection.Long) closeOK = DoExitTrade(); // Close a long position. } else if (priceReached == TradeDirection.Both) { TradeDirection direction = AnalyseExitDirection(); if (direction == TradeDirection.Long || direction == TradeDirection.Short || direction == TradeDirection.Both) closeOK = DoExitTrade(); // Close the current position. } } } // Checks if we closed a position successfully. if (closeOK) return; // This is to prevent new entry after Bar Closing has been executed. if (_closeStrPriceType == StrategyPriceType.Close && ticktype == TickType.AfterClose) return; // Entry at Bar Open or Bar Close. if (_openStrPriceType == StrategyPriceType.Open && (ticktype == TickType.Open || ticktype == TickType.OpenClose) || _openStrPriceType == StrategyPriceType.Close && (ticktype == TickType.Close || ticktype == TickType.OpenClose)) { TradeDirection direction = AnalyseEntryDirection(); if (direction == TradeDirection.Long || direction == TradeDirection.Short) DoEntryTrade(direction); } else if (_openStrPriceType == StrategyPriceType.Indicator) { // Entry at an indicator value. TradeDirection priceReached = AnalyseEntryPrice(); if (priceReached == TradeDirection.Long) { TradeDirection direction = AnalyseEntryDirection(); if (direction == TradeDirection.Long || direction == TradeDirection.Both) DoEntryTrade(TradeDirection.Long); } else if (priceReached == TradeDirection.Short) { TradeDirection direction = AnalyseEntryDirection(); if (direction == TradeDirection.Short || direction == TradeDirection.Both) DoEntryTrade(TradeDirection.Short); } else if (priceReached == TradeDirection.Both) { TradeDirection direction = AnalyseEntryDirection(); if (direction == TradeDirection.Long || direction == TradeDirection.Short) DoEntryTrade(direction); } } }
/// <summary> /// Generates the relative zip file path rooted in the /Data directory /// </summary> public static string GenerateRelativeZipFilePath(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { return(Path.Combine(GenerateRelativeZipFileDirectory(symbol, resolution), GenerateZipFileName(symbol, date, resolution, tickType))); }
/// <summary> /// Free Constructor /// </summary> /// <param name="tickerId">The ticker Id that was specified previously in the call to reqMktData().</param> /// <param name="tickType">Specifies the type of price.</param> /// <param name="value">The value of the specified field.</param> public TickStringEventArgs(int tickerId, TickType tickType, string value) { this.tickerId = tickerId; this.value = value; this.tickType = tickType; }
/// <summary> /// Generate's the zip entry name to hold the specified data. /// </summary> public static string GenerateZipEntryName(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { var formattedDate = date.ToString(DateFormat.EightCharacter); var isHourOrDaily = resolution == Resolution.Hour || resolution == Resolution.Daily; switch (symbol.ID.SecurityType) { case SecurityType.Base: case SecurityType.Equity: case SecurityType.Forex: case SecurityType.Cfd: if (resolution == Resolution.Tick && symbol.SecurityType == SecurityType.Equity) { return(string.Format("{0}_{1}_{2}_{3}.csv", formattedDate, symbol.Value.ToLower(), tickType, resolution )); } if (isHourOrDaily) { return(string.Format("{0}.csv", symbol.Value.ToLower() )); } return(string.Format("{0}_{1}_{2}_{3}.csv", formattedDate, symbol.Value.ToLower(), resolution.ToLower(), tickType.ToLower() )); case SecurityType.Option: if (isHourOrDaily) { return(string.Join("_", symbol.Underlying.Value.ToLower(), // underlying tickType.ToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToString(DateFormat.EightCharacter) ) + ".csv"); } return(string.Join("_", formattedDate, symbol.Underlying.Value.ToLower(), // underlying resolution.ToLower(), tickType.ToLower(), symbol.ID.OptionStyle.ToLower(), symbol.ID.OptionRight.ToLower(), Scale(symbol.ID.StrikePrice), symbol.ID.Date.ToString(DateFormat.EightCharacter) ) + ".csv"); case SecurityType.Future: if (isHourOrDaily) { return(string.Join("_", symbol.ID.Symbol.ToLower(), tickType.ToLower(), symbol.ID.Date.ToString(DateFormat.YearMonth) ) + ".csv"); } return(string.Join("_", formattedDate, symbol.ID.Symbol.ToLower(), resolution.ToLower(), tickType.ToLower(), symbol.ID.Date.ToString(DateFormat.YearMonth) ) + ".csv"); case SecurityType.Commodity: default: throw new ArgumentOutOfRangeException(); } }
public Message_TickPrice(int id, TickType tickType, double price, int size) { this.id = id; this.tickType = tickType; this.price = price; this.size = size; }
/// <summary> /// Creates the entry name for a QC zip data file /// </summary> public static string GenerateZipEntryName(string symbol, SecurityType securityType, DateTime date, Resolution resolution, TickType dataType = TickType.Trade) { if (securityType != SecurityType.Base && securityType != SecurityType.Equity && securityType != SecurityType.Forex && securityType != SecurityType.Cfd) { throw new NotImplementedException("This method only implements base, equity, forex and cfd security type."); } symbol = symbol.ToLower(); if (resolution == Resolution.Hour || resolution == Resolution.Daily) { return(symbol + ".csv"); } //All fx is quote data. if (securityType == SecurityType.Forex || securityType == SecurityType.Cfd) { dataType = TickType.Quote; } return(string.Format("{0}_{1}_{2}_{3}.csv", date.ToString(DateFormat.EightCharacter), symbol, resolution.ToLower(), dataType.ToLower())); }
/// <summary> /// Constructor for a FOREX tick where there is no last sale price. The volume in FX is so high its rare to find FX trade data. /// To fake this the tick contains bid-ask prices and the last price is the midpoint. /// </summary> /// <param name="time">Full date and time</param> /// <param name="symbol">Underlying currency pair we're trading</param> /// <param name="bid">FX tick bid value</param> /// <param name="ask">FX tick ask value</param> public Tick(DateTime time, Symbol symbol, decimal bid, decimal ask) { DataType = MarketDataType.Tick; Time = time; Symbol = symbol; Value = (bid + ask) / 2; TickType = TickType.Quote; BidPrice = bid; AskPrice = ask; }
/// <summary> /// Generates the zip file name for the specified date of data. /// </summary> public static string GenerateZipFileName(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { var tickTypeString = tickType.ToLower(); var formattedDate = date.ToString(DateFormat.EightCharacter); var isHourOrDaily = resolution == Resolution.Hour || resolution == Resolution.Daily; switch (symbol.ID.SecurityType) { case SecurityType.Base: case SecurityType.Equity: case SecurityType.Forex: case SecurityType.Cfd: if (isHourOrDaily) { return(string.Format("{0}.zip", symbol.Value.ToLower() )); } return(string.Format("{0}_{1}.zip", formattedDate, tickTypeString )); case SecurityType.Option: if (isHourOrDaily) { return(string.Format("{0}_{1}_{2}.zip", symbol.Underlying.Value.ToLower(), // underlying tickTypeString, symbol.ID.OptionStyle.ToLower() )); } return(string.Format("{0}_{1}_{2}.zip", formattedDate, tickTypeString, symbol.ID.OptionStyle.ToLower() )); case SecurityType.Future: if (isHourOrDaily) { return(string.Format("{0}_{1}.zip", symbol.ID.Symbol.ToLower(), tickTypeString)); } return(string.Format("{0}_{1}.zip", formattedDate, tickTypeString)); case SecurityType.Commodity: default: throw new ArgumentOutOfRangeException(); } }
//In Base Class: Alias of Closing: //public decimal Price; //Symbol of Asset. //In Base Class: public Symbol Symbol; //In Base Class: DateTime Of this TradeBar //public DateTime Time; /// <summary> /// Initialize tick class with a default constructor. /// </summary> public Tick() { Value = 0; Time = new DateTime(); DataType = MarketDataType.Tick; Symbol = Symbol.Empty; TickType = TickType.Trade; Quantity = 0; Exchange = ""; SaleCondition = ""; Suspicious = false; BidSize = 0; AskSize = 0; }
public LeanDataTestParameters(Symbol symbol, DateTime date, Resolution resolution, TickType tickType, string expectedZipFileName, string expectedZipEntryName, string expectedRelativeZipFileDirectory = "") { Symbol = symbol; Date = date; Resolution = resolution; TickType = tickType; ExpectedZipFileName = expectedZipFileName; ExpectedZipEntryName = expectedZipEntryName; ExpectedRelativeZipFilePath = Path.Combine(expectedRelativeZipFileDirectory, expectedZipFileName).Replace("/", Path.DirectorySeparatorChar.ToString()); ExpectedZipFilePath = Path.Combine(Globals.DataFolder, ExpectedRelativeZipFilePath); Name = SecurityType + "_" + resolution; BaseDataType = resolution == Resolution.Tick ? typeof(Tick) : typeof(TradeBar); if (symbol.ID.SecurityType == SecurityType.Option && resolution != Resolution.Tick) { BaseDataType = typeof(QuoteBar); } Config = new SubscriptionDataConfig(BaseDataType, symbol, resolution, TimeZones.NewYork, TimeZones.NewYork, true, false, false, false, tickType); }
/// <summary> /// Constructor for QuantConnect FXCM Data source: /// </summary> /// <param name="symbol">Symbol for underlying asset</param> /// <param name="line">CSV line of data from FXCM</param> public Tick(string symbol, string line) { var csv = line.Split(','); DataType = MarketDataType.Tick; Symbol = symbol; Time = DateTime.ParseExact(csv[0], DateFormat.Forex, CultureInfo.InvariantCulture); Value = (BidPrice + AskPrice) / 2; TickType = TickType.Quote; BidPrice = Convert.ToDecimal(csv[1], CultureInfo.InvariantCulture); AskPrice = Convert.ToDecimal(csv[2], CultureInfo.InvariantCulture); }
public void tickGeneric(int tickerId, int field, double value) { WriteMessageToConsole( $"Tick Generic. TickerId: {tickerId}, Type: {TickType.getField(field)}, Value: {value}"); }
/// <summary> /// Parse a tick data line from quantconnect zip source files. /// </summary> /// <param name="line">CSV source line of the compressed source</param> /// <param name="date">Base date for the tick (ticks date is stored as int milliseconds since midnight)</param> /// <param name="config">Subscription configuration object</param> public Tick(SubscriptionDataConfig config, string line, DateTime date) { try { var csv = line.Split(','); DataType = MarketDataType.Tick; // Which security type is this data feed: switch (config.SecurityType) { case SecurityType.Equity: Symbol = config.Symbol; Time = date.Date.AddMilliseconds(csv[0].ToInt64()); Value = config.GetNormalizedPrice(csv[1].ToDecimal() / 10000m); TickType = TickType.Trade; Quantity = csv[2].ToInt32(); if (csv.Length > 3) { Exchange = csv[3]; SaleCondition = csv[4]; Suspicious = (csv[5] == "1"); } break; case SecurityType.Forex: Symbol = config.Symbol; TickType = TickType.Quote; Time = date.Date.AddMilliseconds(csv[0].ToInt64()); BidPrice = csv[1].ToDecimal(); AskPrice = csv[2].ToDecimal(); Value = (BidPrice + AskPrice) / 2; break; } } catch (Exception err) { Log.Error("Error Generating Tick: " + err.Message); } }
public void tickPrice(int tickerId, int field, double price, int canAutoExecute) { WriteMessageToConsole( $"Tick Price. Ticker Id: {tickerId}, Type: {TickType.getField(field)}, Price: {price}"); }
public void tickSize(int tickerId, int field, int size) { WriteMessageToConsole( $"Tick Size. Ticker Id: {tickerId}, Type: {TickType.getField(field)}, Size: {size}"); }
public IBSampleAppDialog() { InitializeComponent(); ibClient = new IBClient(signal); marketDataManager = new MarketDataManager(ibClient, marketDataGrid_MDT); deepBookManager = new DeepBookManager(ibClient, deepBookGrid); historicalDataManager = new HistoricalDataManager(ibClient, historicalChart, barsGrid); realTimeBarManager = new RealTimeBarsManager(ibClient, rtBarsChart, rtBarsGrid); scannerManager = new ScannerManager(ibClient, scannerGrid, scannerParamsOutput); orderManager = new OrderManager(ibClient, liveOrdersGrid, tradeLogGrid); accountManager = new AccountManager(ibClient, accountSelector, accSummaryGrid, accountValuesGrid, accountPortfolioGrid, positionsGrid); contractManager = new ContractManager(ibClient, fundamentalsOutput, contractDetailsGrid); //ibClient, form tab, form tab. https://interactivebrokers.github.io/tws-api/contract_details.html#gsc.tab=0 advisorManager = new AdvisorManager(ibClient, advisorAliasesGrid, advisorGroupsGrid, advisorProfilesGrid); optionsManager = new OptionsManager(ibClient, optionChainCallGrid, optionChainPutGrid, optionPositionsGrid, listViewOptionParams); acctPosMultiManager = new AcctPosMultiManager(ibClient, positionsMultiGrid, accountUpdatesMultiGrid); mdContractRight.Items.AddRange(ContractRight.GetAll()); mdContractRight.SelectedIndex = 0; conDetRight.Items.AddRange(ContractRight.GetAll()); conDetRight.SelectedIndex = 0; fundamentalsReportType.Items.AddRange(FundamentalsReport.GetAll()); fundamentalsReportType.SelectedIndex = 0; this.groupMethod.DataSource = AllocationGroupMethod.GetAsData(); this.groupMethod.ValueMember = "Value"; this.groupMethod.DisplayMember = "Name"; this.profileType.DataSource = AllocationProfileType.GetAsData(); this.profileType.ValueMember = "Value"; this.profileType.DisplayMember = "Name"; hdRequest_EndTime.Text = DateTime.Now.ToString("yyyyMMdd HH:mm:ss"); DateTime execFilterDefault = DateTime.Now.AddHours(-1); execFilterTime.Text = execFilterDefault.ToString("yyyyMMdd HH:mm:ss"); // Events liniking // All events belong to EWrapper interface and called Public member functions ibClient.Error += ibClient_Error; ibClient.ConnectionClosed += ibClient_ConnectionClosed; ibClient.CurrentTime += time => addTextToBox("Current Time: " + time + "\n"); ibClient.TickPrice += ibClient_TickPrice; ibClient.TickSize += ibClient_TickSize; ibClient.TickString += (tickerId, tickType, value) => addTextToBox("Tick string. Ticker Id:" + tickerId + ", Type: " + TickType.getField(tickType) + ", Value: " + value + "\n"); ibClient.TickGeneric += (tickerId, field, value) => addTextToBox("Tick Generic. Ticker Id:" + tickerId + ", Field: " + TickType.getField(field) + ", Value: " + value + "\n"); ibClient.TickEFP += (tickerId, tickType, basisPoints, formattedBasisPoints, impliedFuture, holdDays, futureLastTradeDate, dividendImpact, dividendsToLastTradeDate) => addTextToBox("TickEFP. " + tickerId + ", Type: " + tickType + ", BasisPoints: " + basisPoints + ", FormattedBasisPoints: " + formattedBasisPoints + ", ImpliedFuture: " + impliedFuture + ", HoldDays: " + holdDays + ", FutureLastTradeDate: " + futureLastTradeDate + ", DividendImpact: " + dividendImpact + ", DividendsToLastTradeDate: " + dividendsToLastTradeDate + "\n"); ibClient.TickSnapshotEnd += tickerId => addTextToBox("TickSnapshotEnd: " + tickerId + "\n"); ibClient.NextValidId += ibClient_NextValidId; // Receives next valid order id. Will be invoked automatically upon successfull API client connection. Used for sending connection status ibClient.DeltaNeutralValidation += (reqId, underComp) => addTextToBox("DeltaNeutralValidation. " + reqId + ", ConId: " + underComp.ConId + ", Delta: " + underComp.Delta + ", Price: " + underComp.Price + "\n"); // Accounts ibClient.ManagedAccounts += accountsList => HandleMessage(new ManagedAccountsMessage(accountsList)); // Options ibClient.TickOptionCommunication += (tickerId, field, impliedVolatility, delta, optPrice, pvDividend, gamma, vega, theta, undPrice) => HandleMessage(new TickOptionMessage(tickerId, field, impliedVolatility, delta, optPrice, pvDividend, gamma, vega, theta, undPrice)); // Account info, portfolio ibClient.AccountSummary += (reqId, account, tag, value, currency) => HandleMessage(new AccountSummaryMessage(reqId, account, tag, value, currency)); ibClient.AccountSummaryEnd += reqId => HandleMessage(new AccountSummaryEndMessage(reqId)); ibClient.UpdateAccountValue += (key, value, currency, accountName) => HandleMessage(new AccountValueMessage(key, value, currency, accountName)); ibClient.UpdatePortfolio += (contract, position, marketPrice, marketValue, averageCost, unrealisedPNL, realisedPNL, accountName) => HandleMessage(new UpdatePortfolioMessage(contract, position, marketPrice, marketValue, averageCost, unrealisedPNL, realisedPNL, accountName)); ibClient.UpdateAccountTime += timestamp => HandleMessage(new UpdateAccountTimeMessage(timestamp)); ibClient.AccountDownloadEnd += account => HandleMessage(new AccountDownloadEndMessage(account)); ibClient.OrderStatus += (orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld) => HandleMessage(new OrderStatusMessage(orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld)); ibClient.OpenOrder += (orderId, contract, order, orderState) => HandleMessage(new OpenOrderMessage(orderId, contract, order, orderState)); ibClient.OpenOrderEnd += () => HandleMessage(new OpenOrderEndMessage()); // Contracts, comission, fundamential data, historical data ibClient.ContractDetails += (reqId, contractDetails) => HandleMessage(new ContractDetailsMessage(reqId, contractDetails)); ibClient.ContractDetailsEnd += (reqId) => HandleMessage(new ContractDetailsEndMessage()); ibClient.ExecDetails += (reqId, contract, execution) => HandleMessage(new ExecutionMessage(reqId, contract, execution)); ibClient.ExecDetailsEnd += reqId => addTextToBox("ExecDetailsEnd. " + reqId + "\n"); ibClient.CommissionReport += commissionReport => HandleMessage(new CommissionMessage(commissionReport)); ibClient.FundamentalData += (reqId, data) => HandleMessage(new FundamentalsMessage(data)); ibClient.HistoricalData += (reqId, date, open, high, low, close, volume, count, WAP, hasGaps) => HandleMessage(new HistoricalDataMessage(reqId, date, open, high, low, close, volume, count, WAP, hasGaps)); ibClient.HistoricalDataEnd += (reqId, startDate, endDate) => HandleMessage(new HistoricalDataEndMessage(reqId, startDate, endDate)); ibClient.MarketDataType += (reqId, marketDataType) => addTextToBox("MarketDataType. " + reqId + ", Type: " + marketDataType + "\n"); ibClient.UpdateMktDepth += (tickerId, position, operation, side, price, size) => HandleMessage(new DeepBookMessage(tickerId, position, operation, side, price, size, "")); ibClient.UpdateMktDepthL2 += (tickerId, position, marketMaker, operation, side, price, size) => HandleMessage(new DeepBookMessage(tickerId, position, operation, side, price, size, marketMaker)); ibClient.UpdateNewsBulletin += (msgId, msgType, message, origExchange) => addTextToBox("News Bulletins. " + msgId + " - Type: " + msgType + ", Message: " + message + ", Exchange of Origin: " + origExchange + "\n"); // Positions ibClient.Position += (account, contract, pos, avgCost) => HandleMessage(new PositionMessage(account, contract, pos, avgCost)); ibClient.PositionEnd += () => addTextToBox("PositionEnd \n"); // Bars, scanners ibClient.RealtimeBar += (reqId, time, open, high, low, close, volume, WAP, count) => HandleMessage(new RealTimeBarMessage(reqId, time, open, high, low, close, volume, WAP, count)); ibClient.ScannerParameters += xml => HandleMessage(new ScannerParametersMessage(xml)); ibClient.ScannerData += (reqId, rank, contractDetails, distance, benchmark, projection, legsStr) => HandleMessage(new ScannerMessage(reqId, rank, contractDetails, distance, benchmark, projection, legsStr)); ibClient.ScannerDataEnd += reqId => addTextToBox("ScannerDataEnd. " + reqId + "\r\n"); ibClient.ReceiveFA += (faDataType, faXmlData) => HandleMessage(new AdvisorDataMessage(faDataType, faXmlData)); ibClient.BondContractDetails += (requestId, contractDetails) => addTextToBox("Receiving bond contract details."); ibClient.VerifyMessageAPI += apiData => addTextToBox("verifyMessageAPI: " + apiData); ibClient.VerifyCompleted += (isSuccessful, errorText) => addTextToBox("verifyCompleted. IsSuccessfule: " + isSuccessful + " - Error: " + errorText); ibClient.VerifyAndAuthMessageAPI += (apiData, xyzChallenge) => addTextToBox("verifyAndAuthMessageAPI: " + apiData + " " + xyzChallenge); ibClient.VerifyAndAuthCompleted += (isSuccessful, errorText) => addTextToBox("verifyAndAuthCompleted. IsSuccessfule: " + isSuccessful + " - Error: " + errorText); ibClient.DisplayGroupList += (reqId, groups) => addTextToBox("DisplayGroupList. Request: " + reqId + ", Groups" + groups); ibClient.DisplayGroupUpdated += (reqId, contractInfo) => addTextToBox("displayGroupUpdated. Request: " + reqId + ", ContractInfo: " + contractInfo); // Multi positions ibClient.PositionMulti += (reqId, account, modelCode, contract, pos, avgCost) => HandleMessage(new PositionMultiMessage(reqId, account, modelCode, contract, pos, avgCost)); ibClient.PositionMultiEnd += (reqId) => HandleMessage(new PositionMultiEndMessage(reqId)); ibClient.AccountUpdateMulti += (reqId, account, modelCode, key, value, currency) => HandleMessage(new AccountUpdateMultiMessage(reqId, account, modelCode, key, value, currency)); ibClient.AccountUpdateMultiEnd += (reqId) => HandleMessage(new AccountUpdateMultiEndMessage(reqId)); ibClient.SecurityDefinitionOptionParameter += (reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes) => HandleMessage(new SecurityDefinitionOptionParameterMessage(reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes)); ibClient.SecurityDefinitionOptionParameterEnd += (reqId) => HandleMessage(new SecurityDefinitionOptionParameterEndMessage(reqId)); // Soft dollar tires ibClient.SoftDollarTiers += (reqId, tiers) => HandleMessage(new SoftDollarTiersMessage(reqId, tiers)); }