From 031613c778771e219219aeed057acd8204606b7c Mon Sep 17 00:00:00 2001 From: HojouFotytu <36724681+HojouFotytu@users.noreply.github.com> Date: Sun, 17 Feb 2019 23:45:00 +0900 Subject: [PATCH] CurrencyConverterAPI & ASPNetCore Update --- Core/DataObjects/PTMagicData.cs | 1 + Core/Main/PTMagic.cs | 12 +++++++++++- Core/MarketAnalyzer/BaseAnalyzer.cs | 4 ++-- Monitor/Monitor.csproj | 8 ++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Core/DataObjects/PTMagicData.cs b/Core/DataObjects/PTMagicData.cs index 1f2dd55..8a16385 100644 --- a/Core/DataObjects/PTMagicData.cs +++ b/Core/DataObjects/PTMagicData.cs @@ -48,6 +48,7 @@ namespace Core.Main.DataObjects.PTMagicData public string TimezoneOffset { get; set; } = "+0:00"; public string MainFiatCurrency { get; set; } = "USD"; public string CoinMarketCapAPIKey { get; set; } + public string FreeCurrencyConverterAPIKey { get; set; } } public class Monitor diff --git a/Core/Main/PTMagic.cs b/Core/Main/PTMagic.cs index 5e3ef98..f66faad 100644 --- a/Core/Main/PTMagic.cs +++ b/Core/Main/PTMagic.cs @@ -670,6 +670,16 @@ namespace Core.Main { this.Log.DoLogInfo("No CoinMarketCap API KEY specified! You can't use CoinMarketCap in your settings.analyzer.json"); } + + // Check for CurrencyConverterApi Key + if (!this.PTMagicConfiguration.GeneralSettings.Application.FreeCurrencyConverterAPIKey.Equals("")) + { + this.Log.DoLogInfo("FreeCurrencyConverterApi KEY found"); + } + else + { + this.Log.DoLogInfo("No FreeCurrencyConverterApi KEY specified! You can't use non USD Currencies!"); + } } else @@ -1021,7 +1031,7 @@ namespace Core.Main try { this.LastRuntimeSummary.MainFiatCurrency = this.PTMagicConfiguration.GeneralSettings.Application.MainFiatCurrency; - this.LastRuntimeSummary.MainFiatCurrencyExchangeRate = BaseAnalyzer.GetMainFiatCurrencyRate(this.PTMagicConfiguration.GeneralSettings.Application.MainFiatCurrency, this.Log); + this.LastRuntimeSummary.MainFiatCurrencyExchangeRate = BaseAnalyzer.GetMainFiatCurrencyRate(this.PTMagicConfiguration.GeneralSettings.Application.MainFiatCurrency, this.PTMagicConfiguration.GeneralSettings.Application.FreeCurrencyConverterAPIKey, this.Log); this.LastMainFiatCurrency = this.LastRuntimeSummary.MainFiatCurrency; this.LastMainFiatCurrencyExchangeRate = this.LastRuntimeSummary.MainFiatCurrencyExchangeRate; diff --git a/Core/MarketAnalyzer/BaseAnalyzer.cs b/Core/MarketAnalyzer/BaseAnalyzer.cs index f20d2e5..520150d 100644 --- a/Core/MarketAnalyzer/BaseAnalyzer.cs +++ b/Core/MarketAnalyzer/BaseAnalyzer.cs @@ -195,11 +195,11 @@ namespace Core.MarketAnalyzer return result; } - public static double GetMainFiatCurrencyRate(string currency, LogHelper log) + public static double GetMainFiatCurrencyRate(string currency, string FreeCurrencyAPI, LogHelper log) { double result = 1; - string baseUrl = "http://free.currencyconverterapi.com/api/v5/convert?q=USD_" + currency + "&compact=y"; + string baseUrl = "http://free.currencyconverterapi.com/api/v5/convert?q=USD_" + currency + "&compact=y&apiKey="+FreeCurrencyAPI; log.DoLogDebug("http://free.currencyconverterapi.com - Getting latest exchange rates..."); Newtonsoft.Json.Linq.JObject jsonObject = GetSimpleJsonObjectFromURL(baseUrl, log, false); diff --git a/Monitor/Monitor.csproj b/Monitor/Monitor.csproj index f81b5e1..4aa31e8 100644 --- a/Monitor/Monitor.csproj +++ b/Monitor/Monitor.csproj @@ -22,10 +22,10 @@ - - - - + + + +