public async Task RunAsync() { // ************************************* // Step 1 - !!! Configure your credentials for IQConnect in user environment variable or app.config !!! // Check the documentation for more information. // Step 2 - Run IQConnect launcher IQFeedLauncher.Start(); // Step 3 - Use the appropriate factory to create the client var lookupClient = LookupClientFactory.CreateNew(); // Step 4 - Connect it lookupClient.Connect(); var tmpFilename = await lookupClient.Historical.File.GetHistoryTickDatapointsAsync(Symbol, 1000); // Step 5 - Make file request! // Step 6 - Move the file var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DownloadBasePath); var fullPath = Path.Combine(basePath, $"{DateTime.Now:yyyyMMddHHmmss}-{Symbol}.csv"); Directory.CreateDirectory(basePath); File.Move(tmpFilename, fullPath); // Step 7 - Parse TickMessages from saved file var ticks = TickMessage.ParseFromFile(fullPath).ToList(); Console.WriteLine($"Saved {Symbol} ticks in {fullPath}"); }
public void Should_Resample_Bars_From_Ticks() { // Arrange var ticks = TickMessage.ParseFromFile(TestData.TestData.GetFileName(TestDataType.Ticks, DataDirection.Oldest)).ToList(); var intervals = IntervalMessage.ParseFromFile(TestData.TestData.GetFileName(TestDataType.Intervals_1s, DataDirection.Oldest)).ToList(); // Act var bars = ticks.ToHistoricalBars(TimeSpan.FromSeconds(1), DataDirection.Oldest).ToList().ToList(); // Assert Assert.IsNotEmpty(intervals); Assert.AreEqual(intervals.Count, bars.Count); for (var i = 0; i < intervals.Count; i++) { var interval = intervals[i]; var bar = bars[i]; // TODO: create comparable if (interval.Timestamp == bar.Timestamp && interval.Open == bar.Open && interval.High == bar.High && interval.Low == bar.Low && interval.Close == bar.Close && interval.PeriodVolume == bar.PeriodVolume && interval.TotalVolume == bar.TotalVolume) { continue; } throw new Exception(); } }
public void Should_Load_And_Parse_Protocol60_Data_From_File() { // Arrange var ticks = TickMessage.ParseFromFile(TestData.TestData.GetFileName(TestDataType.Ticks, DataDirection.Oldest, true)).ToList(); // Assert Assert.IsNotEmpty(ticks); }
/// <summary> /// Stream IQFeed TickMessages from disk to Lean Tick /// </summary> /// <param name="filename"></param> /// <param name="request"></param> /// <param name="tickFunc"></param> /// <param name="delete"></param> /// <returns>Converted Tick</returns> private IEnumerable <BaseData> GetDataFromTickMessages(string filename, HistoryRequest request, Func <DateTime, Symbol, TickMessage, Tick> tickFunc, bool delete) { var dataTimeZone = _marketHoursDatabase.GetDataTimeZone(request.Symbol.ID.Market, request.Symbol, request.Symbol.SecurityType); // We need to discard ticks which are not impacting the price, i.e those having BasisForLast = O // To get a better understanding how IQFeed is resampling ticks, have a look to this algorithm: // https://github.com/mathpaquette/IQFeed.CSharpApiClient/blob/1b33250e057dfd6cd77e5ee35fa16aebfc8fbe79/src/IQFeed.CSharpApiClient.Extensions/Lookup/Historical/Resample/TickMessageExtensions.cs#L41 foreach (var tick in TickMessage.ParseFromFile(filename).Where(t => t.BasisForLast != 'O')) { var timestamp = tick.Timestamp.ConvertTo(TimeZones.NewYork, dataTimeZone); yield return(tickFunc(timestamp, request.Symbol, tick)); } if (delete) { File.Delete(filename); } }
/// <summary> /// Stream IQFeed TickMessages from disk to Lean Tick /// </summary> /// <param name="filename"></param> /// <param name="request"></param> /// <param name="isEquity"></param> /// <returns>Converted Tick</returns> private IEnumerable <BaseData> GetDataFromTickMessages(string filename, HistoryRequest request) { var dataTimeZone = _marketHoursDatabase.GetDataTimeZone(request.Symbol.ID.Market, request.Symbol, request.Symbol.SecurityType); // We need to discard ticks which are not impacting the price, i.e those having BasisForLast = O // To get a better understanding how IQFeed is resampling ticks, have a look to this algorithm: // https://github.com/mathpaquette/IQFeed.CSharpApiClient/blob/1b33250e057dfd6cd77e5ee35fa16aebfc8fbe79/src/IQFeed.CSharpApiClient.Extensions/Lookup/Historical/Resample/TickMessageExtensions.cs#L41 foreach (var tick in TickMessage.ParseFromFile(filename).Where(t => t.BasisForLast != 'O')) { var timestamp = tick.Timestamp.ConvertTo(TimeZones.NewYork, dataTimeZone); // trade yield return(new Tick( timestamp, request.Symbol, tick.TradeConditions, tick.TradeMarketCenter.ToStringInvariant(), tick.LastSize, (decimal)tick.Last )); // quote yield return(new Tick( timestamp, request.Symbol, tick.TradeConditions, tick.TradeMarketCenter.ToStringInvariant(), 0, // not provided by IQFeed on history (decimal)tick.Bid, 0, // not provided by IQFeed on history (decimal)tick.Ask )); } File.Delete(filename); }