diff --git a/QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloader.cs b/QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloader.cs deleted file mode 100644 index dad8b45..0000000 --- a/QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloader.cs +++ /dev/null @@ -1,101 +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 NodaTime; -using QuantConnect.Data; -using QuantConnect.Securities; -using QuantConnect.Data.Market; -using QuantConnect.Configuration; -using System.Collections.Generic; - -namespace QuantConnect.Brokerages.Coinbase.ToolBox -{ - /// - /// Coinbase Data Downloader class - /// - public class CoinbaseDownloader : IDataDownloader - { - /// - /// 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; - - Type type; - if (resolution == Resolution.Tick) - { - type = typeof(Tick); - } - else if(tickType == TickType.Trade) - { - type = typeof(TradeBar); - } - else - { - type = typeof(OpenInterest); - } - - var historyRequest = new HistoryRequest( - startUtc, - endUtc, - type, - symbol, - resolution, - SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc), - DateTimeZone.Utc, - resolution, - false, - false, - DataNormalizationMode.Raw, - tickType); - - var brokerage = CreateBrokerage(); - return brokerage.GetHistory(historyRequest); - } - - /// - /// Creates and initializes a new instance of the class for Coinbase integration. - /// - /// - /// This method retrieves necessary configuration values such as API key, API secret, and API URL from the application configuration. - /// - /// - /// A new instance of the class configured for Coinbase integration. - /// - /// - /// - /// - /// - /// var coinbaseBrokerage = CreateBrokerage(); - /// // Use the coinbaseBrokerage instance for trading and other operations. - /// - /// - private Brokerage CreateBrokerage() - { - var name = Config.Get("coinbase-api-name", ""); - var privateKey = Config.Get("coinbase-api-private-key", ""); - var restApiUrl = Config.Get("coinbase-rest-api", "https://api.coinbase.com"); - return new CoinbaseBrokerage(string.Empty, name, privateKey, restApiUrl, null, null, null); - } - } -} diff --git a/QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloaderProgram.cs b/QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloaderProgram.cs index 998f773..84ba0fa 100644 --- a/QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloaderProgram.cs +++ b/QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloaderProgram.cs @@ -12,79 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -using System; -using System.Linq; -using System.Threading; -using QuantConnect.Data; -using QuantConnect.Util; -using QuantConnect.Logging; -using System.Globalization; using QuantConnect.ToolBox; -using System.Collections.Generic; namespace QuantConnect.Brokerages.Coinbase.ToolBox { public static class CoinbaseDownloaderProgram { - /// - /// Coinbase Downloader Toolbox Project For LEAN Algorithmic Trading Engine. - /// - public static void CoinbaseDownloader(IList tickers, string resolution, DateTime fromDate, DateTime toDate) - { - Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); - - if (resolution.IsNullOrEmpty() || tickers.IsNullOrEmpty()) - { - Console.WriteLine($"{nameof(CoinbaseDownloader)}:ERROR: '--tickers=' or '--resolution=' parameter is missing"); - Console.WriteLine("--tickers=ETHUSD,ETHBTC,BTCUSD,etc."); - Console.WriteLine("--resolution=Second/Minute/Hour/Daily"); - Environment.Exit(1); - } - var castResolution = (Resolution) Enum.Parse(typeof(Resolution), resolution); - try - { - // Load settings from config.json - var dataDirectory = Globals.DataFolder; - //todo: will download any exchange but always save as coinbase - // Create an instance of the downloader - const string market = Market.Coinbase; - var downloader = new CoinbaseDownloader(); - foreach (var ticker in tickers) - { - // Download the data - var symbolObject = Symbol.Create(ticker, SecurityType.Crypto, market); - var data = downloader.Get(new DataDownloaderGetParameters(symbolObject, castResolution, fromDate, toDate)); - if (data == null) - { - continue; - } - - // Save the data - var writer = new LeanDataWriter(castResolution, symbolObject, dataDirectory, TickType.Trade); - var distinctData = data.GroupBy(i => i.Time, (key, group) => group.First()).ToArray(); - - writer.Write(distinctData); - } - - Log.Trace("Finish data download. Press any key to continue.."); - - } - catch (Exception err) - { - Log.Error(err); - Log.Trace(err.Message); - Log.Trace(err.StackTrace); - } - Console.ReadLine(); - } - /// /// Endpoint for downloading exchange info /// public static void ExchangeInfoDownloader() { - new ExchangeInfoUpdater(new CoinbaseExchangeInfoDownloader()) - .Run(); + new ExchangeInfoUpdater(new CoinbaseExchangeInfoDownloader()).Run(); } } } diff --git a/QuantConnect.CoinbaseBrokerage.ToolBox/Program.cs b/QuantConnect.CoinbaseBrokerage.ToolBox/Program.cs index fc98c68..e92b90d 100644 --- a/QuantConnect.CoinbaseBrokerage.ToolBox/Program.cs +++ b/QuantConnect.CoinbaseBrokerage.ToolBox/Program.cs @@ -13,7 +13,6 @@ * limitations under the License. */ -using System; using QuantConnect.Configuration; using static QuantConnect.Configuration.ApplicationParser; @@ -34,23 +33,13 @@ private static void Main(string[] args) PrintMessageAndExit(1, "ERROR: --app value is required"); } - if(string.IsNullOrEmpty(Config.GetValue("coinbase-api-name")) || string.IsNullOrEmpty(Config.GetValue("coinbase-api-private-key"))) + if (string.IsNullOrEmpty(Config.GetValue("coinbase-api-name")) || string.IsNullOrEmpty(Config.GetValue("coinbase-api-private-key"))) { PrintMessageAndExit(1, "ERROR: check configs: 'coinbase-api-key' or 'coinbase-api-secret'"); } 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; - CoinbaseDownloaderProgram.CoinbaseDownloader(tickers, resolution, fromDate, toDate); - } - else if (targetAppName.Contains("updater") || targetAppName.EndsWith("spu")) + if (targetAppName.Contains("updater") || targetAppName.EndsWith("spu")) { CoinbaseDownloaderProgram.ExchangeInfoDownloader(); }