Target profit column introduced in the dashboard
This commit is contained in:
parent
5a0db4d766
commit
a5faee8603
|
@ -456,6 +456,7 @@ namespace Core.Main.DataObjects.PTMagicData
|
|||
public double AverageBuyPrice { get; set; }
|
||||
public double TotalCost { get; set; }
|
||||
public double CurrentValue { get; set; }
|
||||
public double? TargetGainValue { get; set; }
|
||||
public double Amount { get; set; }
|
||||
public double CurrentPrice { get; set; }
|
||||
public double SellTrigger { get; set; }
|
||||
|
|
|
@ -338,35 +338,48 @@ namespace Core.Main.DataObjects
|
|||
|
||||
private void BuildDCALogData(dynamic rawDCALogData, dynamic rawPairsLogData, dynamic rawPendingLogData, dynamic rawWatchModeLogData)
|
||||
{
|
||||
foreach (var rdld in rawDCALogData)
|
||||
// Parse DCA data
|
||||
_dcaLog.AddRange(ParsePairsData(rawDCALogData, true));
|
||||
|
||||
// Parse Pairs data
|
||||
_dcaLog.AddRange(ParsePairsData(rawPairsLogData, false));
|
||||
|
||||
// Parse pending pairs data
|
||||
_dcaLog.AddRange(ParsePairsData(rawPendingLogData, false));
|
||||
|
||||
// Parse watch only pairs data
|
||||
_dcaLog.AddRange(ParsePairsData(rawWatchModeLogData, false));
|
||||
|
||||
}
|
||||
|
||||
// Parse the pairs data from PT to our own common data structure.
|
||||
private List<DCALogData> ParsePairsData(dynamic pairsData, bool processBuyStrategies)
|
||||
{
|
||||
List<DCALogData> pairs = new List<DCALogData>();
|
||||
|
||||
foreach (var pair in pairsData)
|
||||
{
|
||||
DCALogData dcaLogData = new DCALogData();
|
||||
dcaLogData.Amount = rdld.totalAmount;
|
||||
dcaLogData.BoughtTimes = rdld.boughtTimes;
|
||||
dcaLogData.Market = rdld.market;
|
||||
dcaLogData.ProfitPercent = rdld.profit;
|
||||
dcaLogData.AverageBuyPrice = rdld.avgPrice;
|
||||
dcaLogData.TotalCost = rdld.totalCost;
|
||||
dcaLogData.BuyTriggerPercent = rdld.buyProfit;
|
||||
dcaLogData.CurrentLowBBValue = rdld.bbLow == null ? 0 : rdld.bbLow;
|
||||
dcaLogData.CurrentHighBBValue = rdld.highBb == null ? 0 : rdld.highBb;
|
||||
dcaLogData.BBTrigger = rdld.bbTrigger == null ? 0 : rdld.bbTrigger;
|
||||
dcaLogData.CurrentPrice = rdld.currentPrice;
|
||||
dcaLogData.SellTrigger = rdld.triggerValue == null ? 0 : rdld.triggerValue;
|
||||
dcaLogData.PercChange = rdld.percChange;
|
||||
dcaLogData.BuyStrategy = rdld.buyStrategy == null ? "" : rdld.buyStrategy;
|
||||
dcaLogData.SellStrategy = rdld.sellStrategy == null ? "" : rdld.sellStrategy;
|
||||
dcaLogData.Amount = pair.totalAmount;
|
||||
dcaLogData.BoughtTimes = pair.boughtTimes;
|
||||
dcaLogData.Market = pair.market;
|
||||
dcaLogData.ProfitPercent = pair.profit;
|
||||
dcaLogData.AverageBuyPrice = pair.avgPrice;
|
||||
dcaLogData.TotalCost = pair.totalCost;
|
||||
dcaLogData.BuyTriggerPercent = pair.buyProfit;
|
||||
dcaLogData.CurrentLowBBValue = pair.bbLow == null ? 0 : pair.bbLow;
|
||||
dcaLogData.CurrentHighBBValue = pair.highBb == null ? 0 : pair.highBb;
|
||||
dcaLogData.BBTrigger = pair.bbTrigger == null ? 0 : pair.bbTrigger;
|
||||
dcaLogData.CurrentPrice = pair.currentPrice;
|
||||
dcaLogData.SellTrigger = pair.triggerValue == null ? 0 : pair.triggerValue;
|
||||
dcaLogData.PercChange = pair.percChange;
|
||||
dcaLogData.BuyStrategy = pair.buyStrategy == null ? "" : pair.buyStrategy;
|
||||
dcaLogData.SellStrategy = pair.sellStrategy == null ? "" : pair.sellStrategy;
|
||||
dcaLogData.IsTrailing = false;
|
||||
|
||||
if (rdld.positive != null)
|
||||
if (pair.buyStrategies != null && processBuyStrategies)
|
||||
{
|
||||
dcaLogData.IsTrailing = ((string)rdld.positive).IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
dcaLogData.IsTrue = ((string)rdld.positive).IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rdld.buyStrategies != null)
|
||||
{
|
||||
foreach (var bs in rdld.buyStrategies)
|
||||
foreach (var bs in pair.buyStrategies)
|
||||
{
|
||||
Strategy buyStrategy = new Strategy();
|
||||
buyStrategy.Type = bs.type;
|
||||
|
@ -384,9 +397,9 @@ namespace Core.Main.DataObjects
|
|||
}
|
||||
}
|
||||
|
||||
if (rdld.sellStrategies != null)
|
||||
if (pair.sellStrategies != null)
|
||||
{
|
||||
foreach (var ss in rdld.sellStrategies)
|
||||
foreach (var ss in pair.sellStrategies)
|
||||
{
|
||||
Strategy sellStrategy = new Strategy();
|
||||
sellStrategy.Type = ss.type;
|
||||
|
@ -401,6 +414,15 @@ namespace Core.Main.DataObjects
|
|||
sellStrategy.IsTrue = ((string)ss.positive).IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
|
||||
dcaLogData.SellStrategies.Add(sellStrategy);
|
||||
|
||||
// Find the target percentage gain to sell.
|
||||
if (sellStrategy.Name.Contains("GAIN", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
if (!dcaLogData.TargetGainValue.HasValue || dcaLogData.TargetGainValue.Value > sellStrategy.EntryValue)
|
||||
{
|
||||
// Set the target sell percentage
|
||||
dcaLogData.TargetGainValue = sellStrategy.EntryValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -410,10 +432,10 @@ namespace Core.Main.DataObjects
|
|||
|
||||
// Convert Unix Timestamp to Datetime
|
||||
System.DateTime rdldDateTime = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
|
||||
rdldDateTime = rdldDateTime.AddSeconds((double)rdld.firstBoughtDate).ToUniversalTime();
|
||||
rdldDateTime = rdldDateTime.AddSeconds((double)pair.firstBoughtDate).ToUniversalTime();
|
||||
|
||||
// Profit Trailer bought times are saved in UTC
|
||||
if (rdld.firstBoughtDate > 0)
|
||||
if (pair.firstBoughtDate > 0)
|
||||
{
|
||||
DateTimeOffset ptFirstBoughtDate = DateTimeOffset.Parse(rdldDateTime.Year.ToString() + "-" + rdldDateTime.Month.ToString("00") + "-" + rdldDateTime.Day.ToString("00") + "T" + rdldDateTime.Hour.ToString("00") + ":" + rdldDateTime.Minute.ToString("00") + ":" + rdldDateTime.Second.ToString("00"), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
|
||||
|
||||
|
@ -430,182 +452,7 @@ namespace Core.Main.DataObjects
|
|||
_dcaLog.Add(dcaLogData);
|
||||
}
|
||||
|
||||
foreach (var rpld in rawPairsLogData)
|
||||
{
|
||||
DCALogData dcaLogData = new DCALogData();
|
||||
dcaLogData.Amount = rpld.totalAmount;
|
||||
dcaLogData.BoughtTimes = 0;
|
||||
dcaLogData.Market = rpld.market;
|
||||
dcaLogData.ProfitPercent = rpld.profit;
|
||||
dcaLogData.AverageBuyPrice = rpld.avgPrice;
|
||||
dcaLogData.TotalCost = rpld.totalCost;
|
||||
dcaLogData.BuyTriggerPercent = rpld.buyProfit;
|
||||
dcaLogData.CurrentPrice = rpld.currentPrice;
|
||||
dcaLogData.SellTrigger = rpld.triggerValue == null ? 0 : rpld.triggerValue;
|
||||
dcaLogData.PercChange = rpld.percChange;
|
||||
dcaLogData.BuyStrategy = rpld.buyStrategy == null ? "" : rpld.buyStrategy;
|
||||
dcaLogData.SellStrategy = rpld.sellStrategy == null ? "" : rpld.sellStrategy;
|
||||
dcaLogData.IsTrailing = false;
|
||||
|
||||
if (rpld.sellStrategies != null)
|
||||
{
|
||||
foreach (var ss in rpld.sellStrategies)
|
||||
{
|
||||
Strategy sellStrategy = new Strategy();
|
||||
sellStrategy.Type = ss.type;
|
||||
sellStrategy.Name = ss.name;
|
||||
sellStrategy.EntryValue = ss.entryValue;
|
||||
sellStrategy.EntryValueLimit = ss.entryValueLimit;
|
||||
sellStrategy.TriggerValue = ss.triggerValue;
|
||||
sellStrategy.CurrentValue = ss.currentValue;
|
||||
sellStrategy.CurrentValuePercentage = ss.currentValuePercentage;
|
||||
sellStrategy.Decimals = ss.decimals;
|
||||
sellStrategy.IsTrailing = ((string)ss.positive).IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
sellStrategy.IsTrue = ((string)ss.positive).IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
|
||||
dcaLogData.SellStrategies.Add(sellStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
//Convert Unix Timestamp to Datetime
|
||||
System.DateTime rpldDateTime = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
|
||||
rpldDateTime = rpldDateTime.AddSeconds((double)rpld.firstBoughtDate).ToUniversalTime();
|
||||
|
||||
// Profit Trailer bought times are saved in UTC
|
||||
if (rpld.firstBoughtDate > 0)
|
||||
{
|
||||
DateTimeOffset ptFirstBoughtDate = DateTimeOffset.Parse(rpldDateTime.Year.ToString() + "-" + rpldDateTime.Month.ToString("00") + "-" + rpldDateTime.Day.ToString("00") + "T" + rpldDateTime.Hour.ToString("00") + ":" + rpldDateTime.Minute.ToString("00") + ":" + rpldDateTime.Second.ToString("00"), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
|
||||
|
||||
// Convert UTC bought time to local offset time
|
||||
ptFirstBoughtDate = ptFirstBoughtDate.ToOffset(OffsetTimeSpan);
|
||||
|
||||
dcaLogData.FirstBoughtDate = ptFirstBoughtDate.DateTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
dcaLogData.FirstBoughtDate = Constants.confMinDate;
|
||||
}
|
||||
|
||||
_dcaLog.Add(dcaLogData);
|
||||
}
|
||||
|
||||
foreach (var rpld in rawPendingLogData)
|
||||
{
|
||||
DCALogData dcaLogData = new DCALogData();
|
||||
dcaLogData.Amount = rpld.totalAmount;
|
||||
dcaLogData.BoughtTimes = 0;
|
||||
dcaLogData.Market = rpld.market;
|
||||
dcaLogData.ProfitPercent = rpld.profit;
|
||||
dcaLogData.AverageBuyPrice = rpld.avgPrice;
|
||||
dcaLogData.TotalCost = rpld.totalCost;
|
||||
dcaLogData.BuyTriggerPercent = rpld.buyProfit;
|
||||
dcaLogData.CurrentPrice = rpld.currentPrice;
|
||||
dcaLogData.SellTrigger = rpld.triggerValue == null ? 0 : rpld.triggerValue;
|
||||
dcaLogData.PercChange = rpld.percChange;
|
||||
dcaLogData.BuyStrategy = rpld.buyStrategy == null ? "" : rpld.buyStrategy;
|
||||
dcaLogData.SellStrategy = rpld.sellStrategy == null ? "" : rpld.sellStrategy;
|
||||
dcaLogData.IsTrailing = false;
|
||||
|
||||
if (rpld.sellStrategies != null)
|
||||
{
|
||||
foreach (var ss in rpld.sellStrategies)
|
||||
{
|
||||
Strategy sellStrategy = new Strategy();
|
||||
sellStrategy.Type = ss.type;
|
||||
sellStrategy.Name = ss.name;
|
||||
sellStrategy.EntryValue = ss.entryValue;
|
||||
sellStrategy.EntryValueLimit = ss.entryValueLimit;
|
||||
sellStrategy.TriggerValue = ss.triggerValue;
|
||||
sellStrategy.CurrentValue = ss.currentValue;
|
||||
sellStrategy.CurrentValuePercentage = ss.currentValuePercentage;
|
||||
sellStrategy.Decimals = ss.decimals;
|
||||
sellStrategy.IsTrailing = ((string)ss.positive).IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
sellStrategy.IsTrue = ((string)ss.positive).IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
|
||||
dcaLogData.SellStrategies.Add(sellStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
//Convert Unix Timestamp to Datetime
|
||||
System.DateTime rpldDateTime = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
|
||||
rpldDateTime = rpldDateTime.AddSeconds((double)rpld.firstBoughtDate).ToUniversalTime();
|
||||
|
||||
// Profit Trailer bought times are saved in UTC
|
||||
if (rpld.firstBoughtDate > 0)
|
||||
{
|
||||
DateTimeOffset ptFirstBoughtDate = DateTimeOffset.Parse(rpldDateTime.Year.ToString() + "-" + rpldDateTime.Month.ToString("00") + "-" + rpldDateTime.Day.ToString("00") + "T" + rpldDateTime.Hour.ToString("00") + ":" + rpldDateTime.Minute.ToString("00") + ":" + rpldDateTime.Second.ToString("00"), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
|
||||
|
||||
// Convert UTC bought time to local offset time
|
||||
ptFirstBoughtDate = ptFirstBoughtDate.ToOffset(OffsetTimeSpan);
|
||||
|
||||
dcaLogData.FirstBoughtDate = ptFirstBoughtDate.DateTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
dcaLogData.FirstBoughtDate = Constants.confMinDate;
|
||||
}
|
||||
|
||||
_dcaLog.Add(dcaLogData);
|
||||
}
|
||||
|
||||
foreach (var rpld in rawWatchModeLogData)
|
||||
{
|
||||
DCALogData dcaLogData = new DCALogData();
|
||||
dcaLogData.Amount = rpld.totalAmount;
|
||||
dcaLogData.BoughtTimes = 0;
|
||||
dcaLogData.Market = rpld.market;
|
||||
dcaLogData.ProfitPercent = rpld.profit;
|
||||
dcaLogData.AverageBuyPrice = rpld.avgPrice;
|
||||
dcaLogData.TotalCost = rpld.totalCost;
|
||||
dcaLogData.BuyTriggerPercent = rpld.buyProfit;
|
||||
dcaLogData.CurrentPrice = rpld.currentPrice;
|
||||
dcaLogData.SellTrigger = rpld.triggerValue == null ? 0 : rpld.triggerValue;
|
||||
dcaLogData.PercChange = rpld.percChange;
|
||||
dcaLogData.BuyStrategy = rpld.buyStrategy == null ? "" : rpld.buyStrategy;
|
||||
dcaLogData.SellStrategy = rpld.sellStrategy == null ? "" : rpld.sellStrategy;
|
||||
dcaLogData.IsTrailing = false;
|
||||
|
||||
if (rpld.sellStrategies != null)
|
||||
{
|
||||
foreach (var ss in rpld.sellStrategies)
|
||||
{
|
||||
Strategy sellStrategy = new Strategy();
|
||||
sellStrategy.Type = ss.type;
|
||||
sellStrategy.Name = ss.name;
|
||||
sellStrategy.EntryValue = ss.entryValue;
|
||||
sellStrategy.EntryValueLimit = ss.entryValueLimit;
|
||||
sellStrategy.TriggerValue = ss.triggerValue;
|
||||
sellStrategy.CurrentValue = ss.currentValue;
|
||||
sellStrategy.CurrentValuePercentage = ss.currentValuePercentage;
|
||||
sellStrategy.Decimals = ss.decimals;
|
||||
sellStrategy.IsTrailing = ((string)ss.positive).IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
sellStrategy.IsTrue = ((string)ss.positive).IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1;
|
||||
|
||||
dcaLogData.SellStrategies.Add(sellStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
//Convert Unix Timestamp to Datetime
|
||||
System.DateTime rpldDateTime = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
|
||||
rpldDateTime = rpldDateTime.AddSeconds((double)rpld.firstBoughtDate).ToUniversalTime();
|
||||
|
||||
// Profit Trailer bought times are saved in UTC
|
||||
if (rpld.firstBoughtDate > 0)
|
||||
{
|
||||
DateTimeOffset ptFirstBoughtDate = DateTimeOffset.Parse(rpldDateTime.Year.ToString() + "-" + rpldDateTime.Month.ToString("00") + "-" + rpldDateTime.Day.ToString("00") + "T" + rpldDateTime.Hour.ToString("00") + ":" + rpldDateTime.Minute.ToString("00") + ":" + rpldDateTime.Second.ToString("00"), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
|
||||
|
||||
// Convert UTC bought time to local offset time
|
||||
ptFirstBoughtDate = ptFirstBoughtDate.ToOffset(OffsetTimeSpan);
|
||||
|
||||
dcaLogData.FirstBoughtDate = ptFirstBoughtDate.DateTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
dcaLogData.FirstBoughtDate = Constants.confMinDate;
|
||||
}
|
||||
|
||||
_dcaLog.Add(dcaLogData);
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
private void BuildBuyLogData(dynamic rawBuyLogData)
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Core.Main;
|
||||
using Core.Helper;
|
||||
using Core.Main.DataObjects.PTMagicData;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Core.ProfitTrailer
|
||||
|
@ -582,6 +575,7 @@ namespace Core.ProfitTrailer
|
|||
public static string GetStrategyText(Summary summary, List<Strategy> strategies, string strategyText, bool isTrue, bool isTrailingBuyActive)
|
||||
{
|
||||
bool isValidStrategy = false;
|
||||
Regex regx = new Regex(@"[ABCDEFGHIJKLMNOPQRSTUVWXYZ]", RegexOptions.Compiled);
|
||||
|
||||
if (strategies.Count > 0)
|
||||
{
|
||||
|
@ -598,10 +592,11 @@ namespace Core.ProfitTrailer
|
|||
{
|
||||
string expression = strategy.Name.Remove(0, 10);
|
||||
expression = expression.Replace("<span class=\"tdgreen\">", "true").Replace("<span class=\"red\">", "false").Replace("</span>", "").Replace("&&", "and").Replace("||", "or");
|
||||
expression = Regex.Replace(expression, @"[ABCDEFGHIJKLMNOPQRSTUVWXYZ]", String.Empty);
|
||||
expression = regx.Replace(expression, String.Empty);
|
||||
var tokens = new Tokenizer(expression).Tokenize();
|
||||
var parser = new Parser(tokens);
|
||||
if (parser.Parse()) {
|
||||
if (parser.Parse())
|
||||
{
|
||||
strategyText += "<span class=\"label label-success\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"CONDITIONAL FORMULA\">(FORM)</span> ";
|
||||
}
|
||||
else
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
<th></th>
|
||||
<th class="text-left" data-toggle="tooltip" data-placement="top" title="Active buy strategies">DCA Buy Strats</th>
|
||||
<th class="text-left" data-toggle="tooltip" data-placement="top" title="Active sell strategies">Sell Strats</th>
|
||||
<th class="text-left" data-toggle="tooltip" data-placement="top" title="Target Profit for sale">Target Profit</th>
|
||||
<th class="text-left" data-toggle="tooltip" data-placement="top" title="Current Profit">Profit</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
@ -201,6 +202,8 @@
|
|||
|
||||
<td>@Html.Raw(sellStrategyText)</td>
|
||||
|
||||
<td class="@Html.Raw((dcaLogEntry.TargetGainValue.HasValue && (dcaLogEntry.ProfitPercent > dcaLogEntry.TargetGainValue.Value)) ? "text-success" : "text-danger")">@Html.Raw(dcaLogEntry.TargetGainValue.HasValue ? dcaLogEntry.TargetGainValue.Value.ToString("#,#0.00", new System.Globalization.CultureInfo("en-US")) + "%" : " ")</td>
|
||||
|
||||
@if(!@lostValue)
|
||||
{
|
||||
<td class="text-autocolor">@dcaLogEntry.ProfitPercent.ToString("#,#0.00", new System.Globalization.CultureInfo("en-US"))%</td>
|
||||
|
@ -214,9 +217,13 @@
|
|||
</tr>
|
||||
}
|
||||
|
||||
<td>Totals:</td><td></td>
|
||||
<td>Totals:</td>
|
||||
<td></td>
|
||||
<td>@Html.Raw(Model.TotalBagCost.ToString("#,#0.000000", new System.Globalization.CultureInfo("en-US")))</td>
|
||||
<td></td><td></td><td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="text-autocolor">@Html.Raw((((Model.TotalBagValue - Model.TotalBagCost) / Model.TotalBagCost) * 100).ToString("#,#0.00", new System.Globalization.CultureInfo("en-US")))%</td>
|
||||
|
||||
</tbody>
|
||||
|
|
|
@ -6,7 +6,7 @@ using Core.Helper;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
||||
[assembly: AssemblyVersion("2.4.3")]
|
||||
[assembly: AssemblyVersion("2.4.4")]
|
||||
[assembly: AssemblyProduct("PT Magic")]
|
||||
|
||||
namespace PTMagic
|
||||
|
|
Loading…
Reference in New Issue