Fixed KeyNotFoundException when building trends

This commit is contained in:
djbadders 2020-11-08 12:45:31 +00:00
parent a225f59c78
commit cb578b1449
1 changed files with 29 additions and 14 deletions

View File

@ -335,25 +335,34 @@ namespace Core.MarketAnalyzer
} }
} }
Market recentMarket = recentMarkets[recentMarketPair.Key]; Market recentMarket;
List<string> ignoredMarkets = SystemHelper.ConvertTokenStringToList(marketTrend.IgnoredMarkets, ","); if (recentMarkets.TryGetValue(recentMarketPair.Key, out recentMarket))
if (ignoredMarkets.Contains(recentMarketPair.Value.Symbol))
{ {
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' is ignored in this trend."); List<string> ignoredMarkets = SystemHelper.ConvertTokenStringToList(marketTrend.IgnoredMarkets, ",");
if (ignoredMarkets.Contains(recentMarketPair.Value.Symbol))
{
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' is ignored in this trend.");
continue;
}
List<string> allowedMarkets = SystemHelper.ConvertTokenStringToList(marketTrend.AllowedMarkets, ",");
if (allowedMarkets.Count > 0 && !allowedMarkets.Contains(recentMarketPair.Value.Symbol))
{
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' is not allowed in this trend.");
continue;
}
}
else
{
// No recent market data
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' has no recent market trend data.");
continue; continue;
} }
List<string> allowedMarkets = SystemHelper.ConvertTokenStringToList(marketTrend.AllowedMarkets, ","); Market trendMarket;
if (allowedMarkets.Count > 0 && !allowedMarkets.Contains(recentMarketPair.Value.Symbol))
{
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' is not allowed in this trend.");
continue;
}
Market trendMarket = trendMarkets[recentMarketPair.Key]; if (trendMarkets.TryGetValue(recentMarketPair.Key, out trendMarket))
if (trendMarket != null)
{ {
double recentMarketPrice = recentMarket.Price; double recentMarketPrice = recentMarket.Price;
double trendMarketPrice = trendMarket.Price; double trendMarketPrice = trendMarket.Price;
@ -384,6 +393,12 @@ namespace Core.MarketAnalyzer
marketCount++; marketCount++;
} }
else
{
// No data market trend data
log.DoLogDebug(platform + " - Market trend '" + marketTrend.Name + "' for '" + recentMarketPair.Key + "' has no market trend data.");
continue;
}
} }
} }