Merge pull request #588 from JackONeill12/master
Update to Support the new CMC Api
This commit is contained in:
commit
d73ebd8b73
|
@ -41,6 +41,7 @@ namespace Core.Main.DataObjects.PTMagicData {
|
|||
public string InstanceName { get; set; } = "PT Magic";
|
||||
public string TimezoneOffset { get; set; } = "+0:00";
|
||||
public string MainFiatCurrency { get; set; } = "USD";
|
||||
public string CoinMarketCapAPIKey { get; set; }
|
||||
}
|
||||
|
||||
public class Monitor {
|
||||
|
|
|
@ -534,7 +534,17 @@ namespace Core.Main {
|
|||
this.Log.DoLogError("Profit Trailer directory not found (" + this.PTMagicConfiguration.GeneralSettings.Application.ProfitTrailerPath + ")");
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Check for CoinMarketCap API Key
|
||||
if (!this.PTMagicConfiguration.GeneralSettings.Application.CoinMarketCapAPIKey.Equals("")) {
|
||||
this.Log.DoLogInfo("CoinMarketCap API KEY found");
|
||||
}
|
||||
else {
|
||||
this.Log.DoLogInfo("No CoinMarketCap API KEY specified! You can't use CoinMarketCap in your settings.analyzer.json");
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
this.Log.DoLogWarn("PTMagic disabled, shutting down...");
|
||||
result = false;
|
||||
}
|
||||
|
@ -956,8 +966,11 @@ namespace Core.Main {
|
|||
}
|
||||
|
||||
private void BuildMarketData() {
|
||||
|
||||
if (!this.PTMagicConfiguration.GeneralSettings.Application.CoinMarketCapAPIKey.Equals("")) {
|
||||
// Get most recent market data from CMC
|
||||
string cmcMarketDataResult = CoinMarketCap.GetMarketData(this.PTMagicConfiguration, this.Log);
|
||||
}
|
||||
|
||||
if (this.PTMagicConfiguration.GeneralSettings.Application.Exchange.Equals("Bittrex", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
|
||||
|
|
|
@ -11,10 +11,14 @@ using Core.Main.DataObjects.PTMagicData;
|
|||
|
||||
namespace Core.MarketAnalyzer {
|
||||
public class BaseAnalyzer {
|
||||
public static Dictionary<string, dynamic> GetJsonFromURL(string url, LogHelper log) {
|
||||
public static Dictionary<string, dynamic> GetJsonFromURL(string url, LogHelper log, string api) {
|
||||
Dictionary<string, dynamic> jsonObject = null;
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
if (api != ""){
|
||||
request.Headers.Add("X-CMC_PRO_API_KEY", api);
|
||||
}
|
||||
|
||||
request.ContentType = "application/json";
|
||||
request.UserAgent = "PTMagic.Import";
|
||||
request.KeepAlive = true;
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Core.MarketAnalyzer {
|
|||
string baseUrl = "https://bittrex.com/api/v1.1/public/getmarketsummary?market=USDT-" + mainMarket;
|
||||
|
||||
log.DoLogInfo("Bittrex - Getting main market price...");
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log);
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log, "");
|
||||
if (jsonObject.Count > 0) {
|
||||
if (jsonObject["success"]) {
|
||||
log.DoLogInfo("Bittrex - Market data received for USDT-" + mainMarket);
|
||||
|
@ -43,7 +43,7 @@ namespace Core.MarketAnalyzer {
|
|||
string baseUrl = "https://bittrex.com/api/v2.0/pub/markets/GetMarketSummaries";
|
||||
|
||||
log.DoLogInfo("Bittrex - Getting market data...");
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log);
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log, "");
|
||||
if (jsonObject.Count > 0) {
|
||||
if (jsonObject["success"]) {
|
||||
log.DoLogInfo("Bittrex - Market data received for " + jsonObject["result"].Count.ToString() + " currencies");
|
||||
|
@ -124,7 +124,7 @@ namespace Core.MarketAnalyzer {
|
|||
string baseUrl = "https://bittrex.com/Api/v2.0/pub/market/GetTicks?tickInterval=oneMin&marketName=" + marketName;
|
||||
|
||||
log.DoLogDebug("Bittrex - Getting ticks for '" + marketName + "'...");
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log);
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log, "");
|
||||
if (jsonObject.Count > 0) {
|
||||
if (jsonObject["success"]) {
|
||||
if (jsonObject["result"] != null) {
|
||||
|
|
|
@ -13,34 +13,33 @@ namespace Core.MarketAnalyzer {
|
|||
public static string GetMarketData(PTMagicConfiguration systemConfiguration, LogHelper log) {
|
||||
string result = "";
|
||||
try {
|
||||
string baseUrl = "https://api.coinmarketcap.com/v2/ticker/";
|
||||
string baseUrl = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?limit=200";
|
||||
string cmcAPI = systemConfiguration.GeneralSettings.Application.CoinMarketCapAPIKey;
|
||||
|
||||
log.DoLogInfo("CoinMarketCap - Getting market data...");
|
||||
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log);
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log, cmcAPI);
|
||||
|
||||
if (jsonObject.Count > 0) {
|
||||
if (jsonObject["data"] != null) {
|
||||
Newtonsoft.Json.Linq.JObject jsonDataObject = (Newtonsoft.Json.Linq.JObject)jsonObject["data"];
|
||||
log.DoLogInfo("CoinMarketCap - Market data received for " + jsonDataObject.Count.ToString() + " currencies");
|
||||
log.DoLogInfo("CoinMarketCap - Market data received for " + jsonObject["data"].Count + " currencies");
|
||||
|
||||
Dictionary<string, Market> markets = new Dictionary<string, Market>();
|
||||
foreach (Newtonsoft.Json.Linq.JToken currencyTicker in jsonDataObject.Children()) {
|
||||
|
||||
if (currencyTicker.First["quotes"] != null) {
|
||||
for (int i = 0; i < jsonObject["data"].Count; i++){
|
||||
|
||||
if (currencyTicker.First["quotes"]["USD"] != null) {
|
||||
if (jsonObject["data"][i]["quote"]["USD"] != null){
|
||||
Market market = new Market();
|
||||
market.Position = markets.Count + 1;
|
||||
market.Name = currencyTicker.First["name"].ToString();
|
||||
market.Symbol = currencyTicker.First["symbol"].ToString();
|
||||
market.Price = (double)currencyTicker.First["quotes"]["USD"]["price"];
|
||||
market.Volume24h = (double)currencyTicker.First["quotes"]["USD"]["volume_24h"];
|
||||
if (!String.IsNullOrEmpty(currencyTicker.First["quotes"]["USD"]["percent_change_24h"].ToString())) {
|
||||
market.TrendChange24h = (double)currencyTicker.First["quotes"]["USD"]["percent_change_24h"];
|
||||
market.Name = jsonObject["data"][i]["name"].ToString();
|
||||
market.Symbol = jsonObject["data"][i]["symbol"].ToString();
|
||||
market.Price = (double)jsonObject["data"][i]["quote"]["USD"]["price"];
|
||||
market.Volume24h = (double)jsonObject["data"][i]["quote"]["USD"]["volume_24h"];
|
||||
if (!String.IsNullOrEmpty(jsonObject["data"][i]["quote"]["USD"]["percent_change_24h"].ToString())) {
|
||||
market.TrendChange24h = (double)jsonObject["data"][i]["quote"]["USD"]["percent_change_24h"];
|
||||
}
|
||||
|
||||
markets.Add(market.Name, market);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Core.MarketAnalyzer {
|
|||
string baseUrl = "https://bittrex.com/api/v1.1/public/getmarketsummary?market=USDT-" + mainMarket;
|
||||
|
||||
log.DoLogInfo("Poloniex - Getting main market price...");
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log);
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log, "");
|
||||
if (jsonObject.Count > 0) {
|
||||
if (jsonObject["success"]) {
|
||||
log.DoLogInfo("Poloniex - Market data received for USDT_" + mainMarket);
|
||||
|
@ -43,7 +43,7 @@ namespace Core.MarketAnalyzer {
|
|||
string baseUrl = "https://poloniex.com/public?command=returnTicker";
|
||||
|
||||
log.DoLogInfo("Poloniex - Getting market data...");
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log);
|
||||
Dictionary<string, dynamic> jsonObject = GetJsonFromURL(baseUrl, log, "");
|
||||
if (jsonObject.Count > 0) {
|
||||
log.DoLogInfo("Poloniex - Market data received for " + jsonObject.Count.ToString() + " currencies");
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -7,7 +7,7 @@ using Core.Helper;
|
|||
using Core.Main.DataObjects.PTMagicData;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
[assembly: AssemblyVersion("2.0.4")]
|
||||
[assembly: AssemblyVersion("2.0.5")]
|
||||
[assembly: AssemblyProduct("PT Magic")]
|
||||
|
||||
namespace PTMagic {
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
"MainFiatCurrency": "USD", // Your main fiat currency that will be used in the monitor
|
||||
"AlwaysLoadDefaultBeforeSwitch": true, // If this is enabled, PTMagic will always load default settings before switching to another setting
|
||||
"FloodProtectionMinutes": 15, // If a price trend is just zig-zagging around its trigger, you may want to protect your settings from getting switched back and forth every minute
|
||||
"InstanceName": "PT Magic" // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"InstanceName": "PT Magic", // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"CoinMarketCapAPIKey": "" //CoinMarketCap Api
|
||||
},
|
||||
"Monitor": {
|
||||
"IsPasswordProtected": true, // Defines if your monitor will be asking to setup a password on its first start
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
"MainFiatCurrency": "USD", // Your main fiat currency that will be used in the monitor
|
||||
"AlwaysLoadDefaultBeforeSwitch": true, // If this is enabled, PTMagic will always load default settings before switching to another setting
|
||||
"FloodProtectionMinutes": 15, // If a price trend is just zig-zagging around its trigger, you may want to protect your settings from getting switched back and forth every minute
|
||||
"InstanceName": "PT Magic" // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"InstanceName": "PT Magic", // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"CoinMarketCapAPIKey": "" //CoinMarketCap Api
|
||||
},
|
||||
"Monitor": {
|
||||
"IsPasswordProtected": true, // Defines if your monitor will be asking to setup a password on its first start
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"MainFiatCurrency": "USD", // Your main fiat currency that will be used in the monitor
|
||||
"AlwaysLoadDefaultBeforeSwitch": true, // If this is enabled, PTMagic will always load default settings before switching to another setting
|
||||
"FloodProtectionMinutes": 15, // If a price trend is just zig-zagging around its trigger, you may want to protect your settings from getting switched back and forth every minute
|
||||
"InstanceName": "PT Magic" // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"InstanceName": "PT Magic", // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"CoinMarketCapAPIKey": "" //CoinMarketCap Api
|
||||
},
|
||||
"Monitor": {
|
||||
"IsPasswordProtected": true, // Defines if your monitor will be asking to setup a password on its first start
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"MainFiatCurrency": "USD", // Your main fiat currency that will be used in the monitor
|
||||
"AlwaysLoadDefaultBeforeSwitch": true, // If this is enabled, PTMagic will always load default settings before switching to another setting
|
||||
"FloodProtectionMinutes": 15, // If a price trend is just zig-zagging around its trigger, you may want to protect your settings from getting switched back and forth every minute
|
||||
"InstanceName": "PT Magic" // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"InstanceName": "PT Magic", // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"CoinMarketCapAPIKey": "" //CoinMarketCap Api
|
||||
},
|
||||
"Monitor": {
|
||||
"IsPasswordProtected": true, // Defines if your monitor will be asking to setup a password on its first start
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"MainFiatCurrency": "USD", // Your main fiat currency that will be used in the monitor
|
||||
"AlwaysLoadDefaultBeforeSwitch": true, // If this is enabled, PTMagic will always load default settings before switching to another setting
|
||||
"FloodProtectionMinutes": 15, // If a price trend is just zig-zagging around its trigger, you may want to protect your settings from getting switched back and forth every minute
|
||||
"InstanceName": "PT Magic Development" // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"InstanceName": "PT Magic Development", // The name of the instance of this bot. This will be used in your monitor and your Telegram messages. In case you are running more than one bot, you may set different names to separate them
|
||||
"CoinMarketCapAPIKey": "" //CoinMarketCap ApiKey
|
||||
},
|
||||
"Monitor": {
|
||||
"IsPasswordProtected": true, // Defines if your monitor will be asking to setup a password on its first start
|
||||
|
|
Loading…
Reference in New Issue