diff --git a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/IBDataDownloader.cs b/QuantConnect.InteractiveBrokersBrokerage.ToolBox/IBDataDownloader.cs
deleted file mode 100644
index 08c0463..0000000
--- a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/IBDataDownloader.cs
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
- * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-
-using System;
-using System.Linq;
-using QuantConnect.Data;
-using QuantConnect.Util;
-using QuantConnect.Securities;
-using QuantConnect.Data.Market;
-using System.Collections.Generic;
-using QuantConnect.Configuration;
-using QuantConnect.Brokerages.InteractiveBrokers;
-
-namespace QuantConnect.ToolBox.IBDownloader
-{
- ///
- /// IB Downloader class
- ///
- public class IBDataDownloader : IDataDownloader, IDisposable
- {
- private readonly MarketHoursDatabase _marketHoursDatabase = MarketHoursDatabase.FromDataFolder();
- private readonly InteractiveBrokersBrokerage _brokerage;
-
- ///
- /// Initializes a new instance of the class
- ///
- public IBDataDownloader()
- {
- _brokerage = new InteractiveBrokersBrokerage(null, null, null,
- Config.Get("ib-account"),
- Config.Get("ib-host", "LOCALHOST"),
- Config.GetInt("ib-port", 4001),
- Config.Get("ib-tws-dir"),
- Config.Get("ib-version", InteractiveBrokersBrokerage.DefaultVersion),
- Config.Get("ib-user-name"),
- Config.Get("ib-password"),
- Config.Get("ib-trading-mode"),
- Config.GetValue("ib-agent-description", Brokerages.InteractiveBrokers.Client.AgentDescription.Individual),
- loadExistingHoldings: false);
-
- _brokerage.Message += (object _, Brokerages.BrokerageMessageEvent e) =>
- {
- if (e.Type == Brokerages.BrokerageMessageType.Error)
- {
- Logging.Log.Error(e.Message);
- }
- else
- {
- Logging.Log.Trace(e.Message);
- }
- };
-
- _brokerage.Connect();
- }
-
- ///
- /// Get historical data enumerable for a single symbol, type and resolution given this start and end time (in UTC).
- ///
- /// model class for passing in parameters for historical data
- /// Enumerable of base data for this symbol
- public IEnumerable Get(DataDownloaderGetParameters dataDownloaderGetParameters)
- {
- var symbol = dataDownloaderGetParameters.Symbol;
- var resolution = dataDownloaderGetParameters.Resolution;
- var startUtc = dataDownloaderGetParameters.StartUtc;
- var endUtc = dataDownloaderGetParameters.EndUtc;
- var tickType = dataDownloaderGetParameters.TickType;
-
- if (tickType != TickType.Quote || resolution == Resolution.Tick)
- {
- return null;
- }
-
- if (endUtc < startUtc)
- {
- return Enumerable.Empty();
- }
-
- var symbols = new List{ symbol };
- if (symbol.IsCanonical())
- {
- symbols = GetChainSymbols(symbol, true).ToList();
- }
-
- var exchangeHours = _marketHoursDatabase.GetExchangeHours(symbol.ID.Market, symbol, symbol.SecurityType);
- var dataTimeZone = _marketHoursDatabase.GetDataTimeZone(symbol.ID.Market, symbol, symbol.SecurityType);
-
- return symbols
- .Select(symbol =>
- {
- var request = new HistoryRequest(startUtc,
- endUtc,
- typeof(QuoteBar),
- symbol,
- resolution,
- exchangeHours: exchangeHours,
- dataTimeZone: dataTimeZone,
- resolution,
- includeExtendedMarketHours: true,
- false,
- DataNormalizationMode.Adjusted,
- TickType.Quote);
-
- var history = _brokerage.GetHistory(request);
-
- if (history == null)
- {
- Logging.Log.Trace($"IBDataDownloader.Get(): Ignoring history request for unsupported symbol {symbol}");
- }
-
- return history;
- })
- .Where(history => history != null)
- .SelectMany(history => history);
- }
-
- ///
- /// Returns an IEnumerable of Future/Option contract symbols for the given root ticker
- ///
- /// The Symbol to get futures/options chain for
- /// Include expired contracts
- public IEnumerable GetChainSymbols(Symbol symbol, bool includeExpired)
- {
- return _brokerage.LookupSymbols(symbol, includeExpired);
- }
-
- ///
- /// Downloads historical data from the brokerage and saves it in LEAN format.
- ///
- /// The list of symbols
- /// The tick type
- /// The resolution
- /// The security type
- /// The starting date/time (UTC)
- /// The ending date/time (UTC)
- public void DownloadAndSave(List 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);
- }
-
- ///
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- ///
- public void Dispose()
- {
- if (_brokerage != null)
- {
- _brokerage.Disconnect();
- _brokerage.Dispose();
- }
- }
- }
-}
diff --git a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/IBDownloaderProgram.cs b/QuantConnect.InteractiveBrokersBrokerage.ToolBox/IBDownloaderProgram.cs
deleted file mode 100644
index 96f961f..0000000
--- a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/IBDownloaderProgram.cs
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
- * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-using System;
-using System.Linq;
-using QuantConnect.Data;
-using QuantConnect.Util;
-using QuantConnect.Logging;
-using QuantConnect.Data.Market;
-using System.Collections.Generic;
-
-namespace QuantConnect.ToolBox.IBDownloader
-{
- public static class IBDownloaderProgram
- {
- ///
- /// Primary entry point to the program. This program only supports FOREX for now.
- ///
- public static void IBDownloader(IList tickers, string resolution, DateTime fromDate, DateTime toDate)
- {
- if (resolution.IsNullOrEmpty() || tickers.IsNullOrEmpty())
- {
- Console.WriteLine("IBDownloader ERROR: '--tickers=' or '--resolution=' parameter is missing");
- Console.WriteLine("--tickers=eg EURUSD,USDJPY");
- Console.WriteLine("--resolution=Second/Minute/Hour/Daily/All");
- Environment.Exit(1);
- }
- try
- {
- var allResolutions = resolution.ToLowerInvariant() == "all";
- var castResolution = allResolutions ? Resolution.Second : (Resolution)Enum.Parse(typeof(Resolution), resolution);
- var startDate = fromDate.ConvertToUtc(TimeZones.NewYork);
- var endDate = toDate.ConvertToUtc(TimeZones.NewYork);
-
- // fix end date
- endDate = new DateTime(Math.Min(endDate.Ticks, DateTime.Now.AddDays(-1).Ticks));
-
- // Max number of histoy days
- int maxDays = 1;
- if (!allResolutions)
- {
- switch (castResolution)
- {
- case Resolution.Daily:
- maxDays = 365;
- break;
- case Resolution.Hour:
- maxDays = 30;
- break;
- case Resolution.Minute:
- maxDays = 10;
- break;
- }
- }
-
- // Load settings from config.json
- var dataDirectory = Globals.DataFolder;
-
- // Only FOREX for now
- SecurityType securityType = SecurityType.Forex;
- string market = Market.FXCM;
-
-
- using (var downloader = new IBDataDownloader())
- {
- foreach (var ticker in tickers)
- {
- // Download the data
- var symbol = Symbol.Create(ticker, securityType, market);
-
- var auxEndDate = startDate.AddDays(maxDays);
- auxEndDate = new DateTime(Math.Min(auxEndDate.Ticks, endDate.Ticks));
-
- while (startDate < auxEndDate)
- {
- var data = downloader.Get(new DataDownloaderGetParameters(symbol, castResolution, startDate, auxEndDate, TickType.Quote));
- if (data == null)
- {
- break;
- }
- var bars = data.Cast().ToList();
-
- if (allResolutions)
- {
- // Save the data (second resolution)
- var writer = new LeanDataWriter(castResolution, symbol, dataDirectory);
- writer.Write(bars);
-
- // Save the data (other resolutions)
- foreach (var res in new[] { Resolution.Minute, Resolution.Hour, Resolution.Daily })
- {
- var resData = LeanData.AggregateQuoteBars(bars, symbol, res.ToTimeSpan());
-
- writer = new LeanDataWriter(res, symbol, dataDirectory);
- writer.Write(resData);
- }
- }
- else
- {
- // Save the data (single resolution)
- var writer = new LeanDataWriter(castResolution, symbol, dataDirectory);
- writer.Write(data);
- }
-
- startDate = auxEndDate;
- auxEndDate = auxEndDate.AddDays(maxDays);
- auxEndDate = new DateTime(Math.Min(auxEndDate.Ticks, endDate.Ticks));
- }
- }
-
- }
-
- }
- catch (Exception err)
- {
- Log.Error(err);
- }
- }
- }
-}
diff --git a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/Program.cs b/QuantConnect.InteractiveBrokersBrokerage.ToolBox/Program.cs
deleted file mode 100644
index 5317462..0000000
--- a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/Program.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
- * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-using QuantConnect.Configuration;
-using System;
-using static QuantConnect.Configuration.ApplicationParser;
-
-namespace QuantConnect.ToolBox.IBDownloader
-{
- public static class Program
- {
- public static void Main(string[] args)
- {
- var optionsObject = ToolboxArgumentParser.ParseArguments(args);
- if (optionsObject.Count == 0)
- {
- PrintMessageAndExit();
- }
-
- if (!optionsObject.TryGetValue("app", out var targetApp))
- {
- PrintMessageAndExit(1, "ERROR: --app value is required");
- }
-
- var targetAppName = targetApp.ToString();
- if (targetAppName.Contains("download") || targetAppName.Contains("dl"))
- {
- var fromDate = Parse.DateTimeExact(GetParameterOrExit(optionsObject, "from-date"), "yyyyMMdd-HH:mm:ss");
- var resolution = optionsObject.ContainsKey("resolution") ? optionsObject["resolution"].ToString() : "";
- var tickers = ToolboxArgumentParser.GetTickers(optionsObject);
- var toDate = optionsObject.ContainsKey("to-date")
- ? Parse.DateTimeExact(optionsObject["to-date"].ToString(), "yyyyMMdd-HH:mm:ss")
- : DateTime.UtcNow;
- IBDownloaderProgram.IBDownloader(tickers, resolution, fromDate, toDate);
- }
- else
- {
- PrintMessageAndExit(1, "ERROR: Unrecognized --app value");
- }
- }
- }
-}
\ No newline at end of file
diff --git a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/QuantConnect.InteractiveBrokersBrokerage.ToolBox.csproj b/QuantConnect.InteractiveBrokersBrokerage.ToolBox/QuantConnect.InteractiveBrokersBrokerage.ToolBox.csproj
deleted file mode 100644
index 083a62b..0000000
--- a/QuantConnect.InteractiveBrokersBrokerage.ToolBox/QuantConnect.InteractiveBrokersBrokerage.ToolBox.csproj
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
- Release
- AnyCPU
- Exe
- net6.0
- Copyright © 2021
- bin\$(Configuration)\
- QuantConnect.Brokerages.InteractiveBrokers.ToolBox
- QuantConnect.Brokerages.InteractiveBrokers.ToolBox
- QuantConnect.Brokerages.InteractiveBrokers.ToolBox
- QuantConnect.Brokerages.InteractiveBrokers.ToolBox
- false
- true
- false
- QuantConnect LEAN Template Brokerage: Brokerage Template toolbox plugin for Lean
-
-
- full
- bin\Debug\
-
-
- pdbonly
- bin\Release\
-
-
-
-
-
-
-
-
-