PTMagic/Monitor/Pages/ManageSMS.cshtml.cs

68 lines
2.2 KiB
C#
Raw Normal View History

2018-05-22 10:11:50 +02:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Core.Main;
using Core.Main.DataObjects.PTMagicData;
using Newtonsoft.Json;
namespace Monitor.Pages
{
public class ManageSMSModel : _Internal.BasePageModelSecure
{
2018-05-22 10:11:50 +02:00
public List<SingleMarketSettingSummary> SingleMarketSettingSummaries = new List<SingleMarketSettingSummary>();
public void OnGet()
{
2018-05-22 10:11:50 +02:00
base.Init();
BindData();
}
private void BindData()
{
if (System.IO.File.Exists(PTMagicBasePath + Constants.PTMagicPathData + Path.DirectorySeparatorChar + "SingleMarketSettingSummary.json"))
{
try
{
2018-05-22 10:11:50 +02:00
SingleMarketSettingSummaries = JsonConvert.DeserializeObject<List<SingleMarketSettingSummary>>(System.IO.File.ReadAllText(PTMagicBasePath + Constants.PTMagicPathData + Path.DirectorySeparatorChar + "SingleMarketSettingSummary.json"));
}
catch { }
2018-05-22 10:11:50 +02:00
}
string notification = GetStringParameter("n", "");
if (notification.Equals("SettingReset"))
{
2018-05-22 10:11:50 +02:00
NotifyHeadline = "Setting Reset!";
NotifyMessage = "The setting will get reset on the next interval!";
NotifyType = "success";
}
}
public double GetTrendChange(string marketTrend, MarketPairSummary mps, TriggerSnapshot ts, string marketTrendRelation)
{
2018-05-22 10:11:50 +02:00
double result = 0;
if (mps.MarketTrendChanges.ContainsKey(marketTrend))
{
2018-05-22 10:11:50 +02:00
result = mps.MarketTrendChanges[marketTrend];
double averageMarketTrendChange = Summary.MarketTrendChanges[marketTrend].OrderByDescending(mtc => mtc.TrendDateTime).First().TrendChange;
if (marketTrendRelation.Equals(Constants.MarketTrendRelationAbsolute, StringComparison.InvariantCulture))
{
2018-05-22 10:11:50 +02:00
result = result - averageMarketTrendChange;
}
else if (marketTrendRelation.Equals(Constants.MarketTrendRelationRelativeTrigger, StringComparison.InvariantCulture))
{
2018-05-22 10:11:50 +02:00
double currentPrice = mps.LatestPrice;
double triggerPrice = ts.LastPrice;
double triggerTrend = (currentPrice - triggerPrice) / triggerPrice * 100;
result = triggerTrend;
}
}
return result;
}
}
}