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 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();

            // Step 5 - Make any requests you need or want!
            var tickMessages = await lookupClient.Historical.GetHistoryTickDatapointsAsync("AAPL", 100);

            var intervalMessage = await lookupClient.Historical.GetHistoryIntervalDaysAsync("AAPL", 5, 10, 100);

            var dailyMessages = await lookupClient.Historical.GetHistoryDailyDatapointsAsync("AAPL", 100);

            Console.WriteLine($"Fetched {tickMessages.Count()} Tick messages");
            Console.WriteLine($"Fetched {intervalMessage.Count()} Interval messages");
            Console.WriteLine($"Fetched {dailyMessages.Count()} Daily messages");
        }
        /// <summary>
        /// Please note that Expired Options file is huge.
        /// It's about 600 MB so iterating through all rows
        /// will take a while, especially if you don't have SSD.
        /// </summary>
        public void Run()
        {
            var lookupClient = LookupClientFactory.CreateNew();

            Console.WriteLine("Downloading and Caching Expired Options file from IQFeed servers...");
            Console.WriteLine("*** This may take a while the first time... ***\n");

            // Getting the first 10000 expired options with Expiration date >= Today - 180 days
            var expiredOptionsGreaterThan180Days = lookupClient.Symbol.GetAllExpiredOptions()
                                                   .Select(x => x.EquityOption)
                                                   .Where(x => x.Expiration >= DateTime.Now.AddDays(-180))
                                                   .Take(10000) // COMMENT OUT THIS LINE TO GET THEM ALL
                                                   .ToList();

            Console.WriteLine($"Found {expiredOptionsGreaterThan180Days.Count} expired options matching Expiration date >= Today - 180 days");


            // Getting the first 10000 expired options for APPL stock
            var expiredOptionsForSpecificStock = lookupClient.Symbol.GetAllExpiredOptions()
                                                 .Select(x => x.EquityOption)
                                                 .Where(x => x.EquitySymbol == "AAPL")
                                                 .Take(10000) // COMMENT OUT THIS LINE TO GET THEM ALL
                                                 .ToList();

            Console.WriteLine($"Found {expiredOptionsForSpecificStock.Count} expired options for AAPL stock");
        }
Esempio n. 4
0
        public async Task RunAsync()
        {
            // Configure your credentials for IQConnect in user environment variable or app.config !!!
            // Check the documentation for more information.

            // Run IQConnect launcher
            IQFeedLauncher.Start();

            // Choose between 3 different handlers:
            // 1- HistoricalMessageDecimalHandler   (for decimal)
            // 2- HistoricalMessageDoubleHandler    (for double) - default one through CreateNew
            // 3- HistoricalMessageFloatHandler     (for float)
            var lookupClient = LookupClientFactory.CreateNew(
                IQFeedDefault.Hostname,
                IQFeedDefault.LookupPort,
                1,
                LookupDefault.Timeout,
                LookupDefault.BufferSize,
                new HistoricalMessageDecimalHandler());

            // Connect
            lookupClient.Connect();

            // retrieve IEnumerable<TickMessage<decimal>>
            var decimalTicks = (await lookupClient.Historical.GetHistoryTickDatapointsAsync("AAPL", 1000)).ToList();

            // convert TickMessage<decimal> to TickMessage<float>
            var floatTick = decimalTicks.First().ToFloat();

            // convert IEnumerable<TickMessage<decimal>> to IEnumerable<TickMessage<float>>
            var floatTicks = decimalTicks.ToFloat().ToList();
        }
        public async Task SetUp()
        {
            _lookupClient = LookupClientFactory.CreateNew();
            _lookupClient.Connect();
            var groupIds = await _lookupClient.Symbol.GetListedMarketsAsync("TEST"); // using ReqId as workaround for IQFeed 6.2 beta bug

            _groupId = groupIds.First(g => g.ShortName == "CME").ListedMarketId;
        }
Esempio n. 6
0
        public void SetUp()
        {
            var lookupClient = LookupClientFactory.CreateNew();

            lookupClient.Connect();

            _chainsFacade = lookupClient.Chains;
        }
Esempio n. 7
0
        public void SetUp()
        {
            RestTestDataDirectory();

            IQFeedLauncher.Start();
            _lookupClient = LookupClientFactory.CreateNew();
            _lookupClient.Connect();
        }
        public void SetUp()
        {
            var lookupClient = LookupClientFactory.CreateNew();

            lookupClient.Connect();

            _historicalRawFacade = lookupClient.Historical.Raw;
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            // example
            var lookupClient = LookupClientFactory.CreateNew();
            var symbol       = lookupClient.Symbol.GetAllMarketSymbols().First(x => x.Symbol == "AAPL");

            var fileReader = new FileReader(@"C:\data", symbol, new DateTime(2020, 03, 30), DataType.Tick);
            var rows       = fileReader.Parse().ToList();
        }
        public static Downloader CreateNew(string dataDirectory, int numberOfClients)
        {
            IQFeedLauncher.Start();
            var lookupClient = LookupClientFactory.CreateNew("localhost", IQFeedDefault.LookupPort, numberOfClients, TimeSpan.FromMinutes(20));

            lookupClient.Connect();

            var level1Client = Level1ClientFactory.CreateNew();

            level1Client.Connect();

            return(new Downloader(dataDirectory, lookupClient, level1Client, numberOfClients));
        }
        public void Run()
        {
            var lookupClient = LookupClientFactory.CreateNew();

            Console.WriteLine("Downloading and Caching Market Symbols file from IQFeed servers...");
            Console.WriteLine("Please note that this file is updated every day.");
            Console.WriteLine("*** This may take a while the first time... ***\n");

            var marketSymbols    = lookupClient.Symbol.GetAllMarketSymbols();
            var optionableStocks = OptionableStock.GetOptionableStocks(marketSymbols).ToList();

            foreach (var optionableStock in optionableStocks)
            {
                Console.WriteLine($"{optionableStock.MarketSymbol.Symbol} has {optionableStock.Options.Count()} options");
            }

            Console.WriteLine($"Found {optionableStocks.Count} stocks with options");
        }
        public static void LookupClient_can_connect_and_terminate_without_error_forceIpv4(bool forceIpv4)
        {
            // Arrange
            SocketClient.ForceIpv4 = forceIpv4;

            // Act
            IQFeedLauncher.Start();

            var client = LookupClientFactory.CreateNew();

            client.Connect();
            client.Disconnect();

            IQFeedLauncher.Terminate();

            // Assert
            Assert.Pass($"IQFeedLauncher and the lookup client were able to connect and disconnect/terminate without error with the 'SocketClient.ForceIpv4' value set to '{forceIpv4}'.");
        }
Esempio n. 13
0
        static async void RunHistoricalExample()
        {
            // *************************************

            // 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();

            // Step 5 - Make any requests you need or want!
            var ticksMessages = await lookupClient.Historical.ReqHistoryTickDatapointsAsync("AAPL", 100);

            var ticksFilename = await lookupClient.Historical.Raw.ReqHistoryTickDaysAsync("AAPL", 100);

            // *************************************
        }
Esempio n. 14
0
 public void SetUp()
 {
     _lookupClient = LookupClientFactory.CreateNew();
     _lookupClient.Connect();
 }
Esempio n. 15
0
 public ConcurrentFileHistoricalExample() : base(LookupClientFactory.CreateNew(NumberOfConcurrentClients), NumberOfConcurrentClients)
 {
     _basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DownloadBasePath, DateTime.Now.ToString("yyyyMMddHHmmss"));
 }
        /// <summary>
        /// Primary entry point to the program. This program only supports EQUITY for now.
        /// </summary>
        public static void IQFeedDownloader(IList <string> tickers, string resolution, DateTime fromDate, DateTime toDate)
        {
            if (resolution.IsNullOrEmpty() || tickers.IsNullOrEmpty())
            {
                Console.WriteLine("IQFeedDownloader ERROR: '--tickers=' or '--resolution=' parameter is missing");
                Console.WriteLine("--tickers=SPY,AAPL");
                Console.WriteLine("--resolution=Tick/Second/Minute/Hour/Daily/All");
                Environment.Exit(1);
            }
            try
            {
                // Load settings from command line
                var allResolution  = resolution.ToLowerInvariant() == "all";
                var castResolution = allResolution ? Resolution.Tick : (Resolution)Enum.Parse(typeof(Resolution), resolution);
                var startDate      = fromDate.ConvertToUtc(TimeZones.NewYork);
                var endDate        = toDate.ConvertToUtc(TimeZones.NewYork);
                endDate = endDate.AddDays(1).AddMilliseconds(-1);

                // Load settings from config.json
                var dataDirectory  = Config.Get("data-folder", "../../../Data");
                var userName       = Config.Get("iqfeed-username", "username");
                var password       = Config.Get("iqfeed-password", "password");
                var productName    = Config.Get("iqfeed-productName", "productname");
                var productVersion = Config.Get("iqfeed-version", "productversion");

                // Create an instance of the downloader
                const string market = Market.USA;

                // Connect to IQFeed
                IQFeedLauncher.Start(userName, password, productName, productVersion);
                var lookupClient = LookupClientFactory.CreateNew(NumberOfClients);
                lookupClient.Connect();

                // Create IQFeed downloader instance
                var universeProvider = new IQFeedDataQueueUniverseProvider();
                var historyProvider  = new IQFeedFileHistoryProvider(lookupClient, universeProvider, MarketHoursDatabase.FromDataFolder());
                var downloader       = new IQFeedDataDownloader(historyProvider);
                var quoteDownloader  = new IQFeedDataDownloader(historyProvider);

                var resolutions = allResolution ? new List <Resolution> {
                    Resolution.Tick, Resolution.Second, Resolution.Minute, Resolution.Hour, Resolution.Daily
                } : new List <Resolution> {
                    castResolution
                };
                var requests = resolutions.SelectMany(r => tickers.Select(t => new { Ticker = t, Resolution = r })).ToList();

                var sw = Stopwatch.StartNew();
                Parallel.ForEach(requests, new ParallelOptions {
                    MaxDegreeOfParallelism = NumberOfClients
                }, request =>
                {
                    // Download the data
                    var symbol = Symbol.Create(request.Ticker, SecurityType.Equity, market);
                    var data   = downloader.Get(new DataDownloaderGetParameters(symbol, request.Resolution, startDate, endDate));

                    // Write the data
                    var writer = new LeanDataWriter(request.Resolution, symbol, dataDirectory);
                    writer.Write(data);

                    if (request.Resolution == Resolution.Tick)
                    {
                        var quotes      = quoteDownloader.Get(new DataDownloaderGetParameters(symbol, request.Resolution, startDate, endDate, TickType.Quote));
                        var quoteWriter = new LeanDataWriter(request.Resolution, symbol, dataDirectory, TickType.Quote);
                        quoteWriter.Write(quotes);
                    }
                });
                sw.Stop();

                Log.Trace($"IQFeedDownloader: Completed successfully in {sw.Elapsed}!");
            }
            catch (Exception err)
            {
                Log.Error(err);
            }
        }
 public ConcurrentHistoricalExample() : base(LookupClientFactory.CreateNew(NumberOfConcurrentClients), NumberOfConcurrentClients)
 {
     _dailyMessagesBySymbol = new ConcurrentDictionary <string, List <DailyWeeklyMonthlyMessage <double> > >();
 }
        public void SetUp()
        {
            var lookupClient = LookupClientFactory.CreateNew();

            _symbolFacade = lookupClient.Symbol;
        }