Performance improvements using parallelism
This commit is contained in:
parent
62f2636a69
commit
56a29b6745
|
@ -5,6 +5,8 @@ using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
@ -30,10 +32,10 @@ namespace Core.Main.DataObjects
|
||||||
string html = "";
|
string html = "";
|
||||||
string url = systemConfiguration.GeneralSettings.Application.ProfitTrailerMonitorURL + "api/data?token=" + systemConfiguration.GeneralSettings.Application.ProfitTrailerServerAPIToken;
|
string url = systemConfiguration.GeneralSettings.Application.ProfitTrailerMonitorURL + "api/data?token=" + systemConfiguration.GeneralSettings.Application.ProfitTrailerServerAPIToken;
|
||||||
|
|
||||||
try
|
// Get the data from PT
|
||||||
{
|
|
||||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
request.AutomaticDecompression = DecompressionMethods.GZip;
|
request.AutomaticDecompression = DecompressionMethods.GZip;
|
||||||
|
request.KeepAlive = true;
|
||||||
|
|
||||||
WebResponse response = request.GetResponse();
|
WebResponse response = request.GetResponse();
|
||||||
Stream dataStream = response.GetResponseStream();
|
Stream dataStream = response.GetResponseStream();
|
||||||
|
@ -42,27 +44,30 @@ namespace Core.Main.DataObjects
|
||||||
reader.Close();
|
reader.Close();
|
||||||
response.Close();
|
response.Close();
|
||||||
|
|
||||||
}
|
// Parse the JSON and build the data sets
|
||||||
catch (System.Exception)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
PTData rawPTData = JsonConvert.DeserializeObject<PTData>(html);
|
PTData rawPTData = JsonConvert.DeserializeObject<PTData>(html);
|
||||||
|
|
||||||
|
Parallel.Invoke(() =>
|
||||||
|
{
|
||||||
if (rawPTData.SellLogData != null)
|
if (rawPTData.SellLogData != null)
|
||||||
{
|
{
|
||||||
this.BuildSellLogData(rawPTData.SellLogData, _systemConfiguration);
|
this.BuildSellLogData(rawPTData.SellLogData, _systemConfiguration);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
() =>
|
||||||
|
{
|
||||||
if (rawPTData.bbBuyLogData != null)
|
if (rawPTData.bbBuyLogData != null)
|
||||||
{
|
{
|
||||||
this.BuildBuyLogData(rawPTData.bbBuyLogData, _systemConfiguration);
|
this.BuildBuyLogData(rawPTData.bbBuyLogData, _systemConfiguration);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
() =>
|
||||||
|
{
|
||||||
if (rawPTData.DCALogData != null)
|
if (rawPTData.DCALogData != null)
|
||||||
{
|
{
|
||||||
this.BuildDCALogData(rawPTData.DCALogData, rawPTData.GainLogData, _systemConfiguration);
|
this.BuildDCALogData(rawPTData.DCALogData, rawPTData.GainLogData, _systemConfiguration);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Convert local offset time to UTC
|
// Convert local offset time to UTC
|
||||||
TimeSpan offsetTimeSpan = TimeSpan.Parse(systemConfiguration.GeneralSettings.Application.TimezoneOffset.Replace("+", ""));
|
TimeSpan offsetTimeSpan = TimeSpan.Parse(systemConfiguration.GeneralSettings.Application.TimezoneOffset.Replace("+", ""));
|
||||||
|
|
|
@ -9,6 +9,8 @@ using Core.Main.DataObjects.PTMagicData;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Core.ProfitTrailer;
|
using Core.ProfitTrailer;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Core.MarketAnalyzer
|
namespace Core.MarketAnalyzer
|
||||||
{
|
{
|
||||||
|
@ -358,7 +360,10 @@ namespace Core.MarketAnalyzer
|
||||||
// Get Ticks for all markets
|
// Get Ticks for all markets
|
||||||
log.DoLogDebug("Binance - Getting ticks for '" + markets.Count + "' markets");
|
log.DoLogDebug("Binance - Getting ticks for '" + markets.Count + "' markets");
|
||||||
Dictionary<string, List<MarketTick>> marketTicks = new Dictionary<string, List<MarketTick>>();
|
Dictionary<string, List<MarketTick>> marketTicks = new Dictionary<string, List<MarketTick>>();
|
||||||
foreach (string key in markets.Keys)
|
|
||||||
|
Parallel.ForEach( markets.Keys,
|
||||||
|
new ParallelOptions { MaxDegreeOfParallelism = 5 },
|
||||||
|
(key) =>
|
||||||
{
|
{
|
||||||
marketTicks.Add(key, Binance.GetMarketTicks(key, totalTicks, systemConfiguration, log));
|
marketTicks.Add(key, Binance.GetMarketTicks(key, totalTicks, systemConfiguration, log));
|
||||||
|
|
||||||
|
@ -366,7 +371,7 @@ namespace Core.MarketAnalyzer
|
||||||
{
|
{
|
||||||
log.DoLogInfo("Binance - No worries, I am still alive... " + marketTicks.Count + "/" + markets.Count + " markets done...");
|
log.DoLogInfo("Binance - No worries, I am still alive... " + marketTicks.Count + "/" + markets.Count + " markets done...");
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
log.DoLogInfo("Binance - Ticks completed.");
|
log.DoLogInfo("Binance - Ticks completed.");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue