Files
quantconnect--lean/ToolBox/BitfinexDownloader/BitfinexDownloaderProgram.cs
T
Ronit Jain f129ab1a09
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Feature implement ExchangeInfoDownloader (#6213)
* add gdax exchange info downloader

* add downloader method to program]

* fetch currency description

* change definition to include headers

* use extension method to make request

* remove log from test

* replace WebRequest

* cleanup

* use relevant name

* implement IExchangeInfoDownloader for bitfinex, initial commit

* add default values

* use default market value

* use correct attribute for lotsize

* don't skip missing values

* handle multiple downloaders

* add gdax and bitfinex exchange downloader

* follow LEAN data directory structure

* update SPDB

* order tickers

* order tickers

* add exchange info downloader test template

* delete files

* update SPDB

* use currency mapping

* update bitfinex symbols

* update currency mapping

* sort result after old currency symbols are used

* use market of the respective brokerage

* no more unknown symbol

* change minimum order size value

* direct conversion possible

* update bitfinex symbols

* change user-agent

* add test for indirect conversion

* update stats
2022-02-22 13:00:54 -03:00

82 lines
3.1 KiB
C#

/*
* 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 QuantConnect.Data;
using QuantConnect.Logging;
using QuantConnect.Util;
using System;
using System.Collections.Generic;
namespace QuantConnect.ToolBox.BitfinexDownloader
{
public static class BitfinexDownloaderProgram
{
/// <summary>
/// Primary entry point to the program.
/// </summary>
public static void BitfinexDownloader(IList<string> tickers, string resolution, DateTime fromDate, DateTime toDate)
{
if (resolution.IsNullOrEmpty() || tickers.IsNullOrEmpty())
{
Console.WriteLine("BitfinexDownloader ERROR: '--tickers=' or '--resolution=' parameter is missing");
Console.WriteLine("--tickers=eg BTCUSD");
Console.WriteLine("--resolution=Second/Minute/Hour/Daily/All");
Environment.Exit(1);
}
try
{
var allResolutions = resolution.ToLowerInvariant() == "all";
var resolutions = allResolutions ?
new[] { Resolution.Minute, Resolution.Hour, Resolution.Daily } :
new[] { (Resolution)Enum.Parse(typeof(Resolution), resolution) };
// Load settings from config.json
var dataDirectory = Config.Get("data-folder", "../../../Data");
using (var downloader = new BitfinexDataDownloader())
{
foreach (var ticker in tickers)
{
// Download the data
var symbol = downloader.GetSymbol(ticker);
foreach (var castResolution in resolutions)
{
var data = downloader.Get(new DataDownloaderGetParameters(symbol, castResolution, fromDate, toDate));
// Save the data (single resolution)
var writer = new LeanDataWriter(castResolution, symbol, dataDirectory);
writer.Write(data);
}
}
}
}
catch (Exception err)
{
Log.Error(err);
}
}
/// <summary>
/// Endpoint for downloading exchange info
/// </summary>
public static void ExchangeInfoDownloader()
{
new ExchangeInfoUpdater(new BitfinexExchangeInfoDownloader())
.Run();
}
}
}