Files
quantconnect--lean/ToolBox/ExchangeInfoUpdater.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

89 lines
3.2 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 System;
using System.IO;
using System.Linq;
namespace QuantConnect.ToolBox
{
/// <summary>
/// Base tool for pulling data from a remote source and updating existing csv file.
/// </summary>
public class ExchangeInfoUpdater
{
private readonly IExchangeInfoDownloader _eidl;
public ExchangeInfoUpdater(IExchangeInfoDownloader eidl)
{
_eidl = eidl;
}
/// <summary>
/// Update existing symbol properties database
/// </summary>
public void Run()
{
var directory = Path.Combine(Globals.DataFolder, "symbol-properties");
var file = Path.Combine(directory, "symbol-properties-database.csv");
var baseOutputDirectory = Config.Get("temp-output-directory", "/temp-output-directory");
var tempOutputDirectory = Directory.CreateDirectory(Path.Combine(baseOutputDirectory, "symbol-properties"));
var tmp = Path.Combine(tempOutputDirectory.FullName, "symbol-properties-database.csv");
if (File.Exists(tmp))
{
file = tmp;
}
else if (!File.Exists(file))
{
throw new FileNotFoundException("Unable to locate symbol properties file: " + file);
}
// Read file data before to escape from clash if file == tmp
// Dispose off enumerator to free up resource
var fileLines = File.ReadLines(file).ToList();
using (var writer = new StreamWriter(tmp))
{
var fetch = false;
// skip the first header line, also skip #'s as these are comment lines
foreach (var line in fileLines)
{
if (!line.StartsWithInvariant(_eidl.Market, true))
{
writer.WriteLine(line);
}
else if (!fetch)
{
foreach (var upd in _eidl.Get())
{
writer.WriteLine(upd);
}
fetch = true;
}
}
if (!fetch)
{
writer.WriteLine(Environment.NewLine);
foreach (var upd in _eidl.Get())
{
writer.WriteLine(upd);
}
}
}
}
}
}