private void BindData() { DCAMarket = GetStringParameter("m", ""); PTData = new ProfitTrailerData(PTMagicBasePath, PTMagicConfiguration); DCALogData = PTData.DCALog.Find(d => d.Market == DCAMarket); // Convert local offset time to UTC TimeSpan offsetTimeSpan = TimeSpan.Parse(PTMagicConfiguration.GeneralSettings.Application.TimezoneOffset.Replace("+", "")); DateTimeNow = DateTimeOffset.UtcNow.ToOffset(offsetTimeSpan); }
// 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 = 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.Leverage = pair.leverage == null ? 0 : pair.leverage; dcaLogData.BuyStrategy = pair.buyStrategy == null ? "" : pair.buyStrategy; dcaLogData.SellStrategy = pair.sellStrategy == null ? "" : pair.sellStrategy; dcaLogData.IsTrailing = false; // See if they are using PT 2.5 (buyStrategiesData) or 2.4 (buyStrategies) var buyStrats = pair.buyStrategies != null ? pair.buyStrategies : pair.buyStrategiesData.data; if (buyStrats != null && processBuyStrategies) { foreach (var bs in buyStrats) { Strategy buyStrategy = new Strategy(); buyStrategy.Type = bs.type; buyStrategy.Name = bs.name; buyStrategy.EntryValue = bs.entryValue; buyStrategy.EntryValueLimit = bs.entryValueLimit; buyStrategy.TriggerValue = bs.triggerValue; buyStrategy.CurrentValue = bs.currentValue; buyStrategy.CurrentValuePercentage = bs.currentValuePercentage; buyStrategy.Decimals = bs.decimals; buyStrategy.IsTrailing = bs.trailing; buyStrategy.IsTrue = bs.strategyResult; dcaLogData.BuyStrategies.Add(buyStrategy); } } // See if they are using PT 2.5 (sellStrategiesData) or 2.4 (sellStrategies) var sellStrats = pair.sellStrategies != null ? pair.sellStrategies : pair.sellStrategiesData.data; if (sellStrats != null) { foreach (var ss in sellStrats) { 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 = ss.trailing; sellStrategy.IsTrue = ss.strategyResult; 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; } } } } // Calculate current value dcaLogData.CurrentValue = dcaLogData.CurrentPrice * dcaLogData.Amount; // Convert Unix Timestamp to Datetime System.DateTime rdldDateTime = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); rdldDateTime = rdldDateTime.AddSeconds((double)pair.firstBoughtDate).ToUniversalTime(); // Profit Trailer bought times are saved in UTC 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); // 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 BuildDCALogData(List <dcaLogData> rawDCALogData, List <dcaLogData> rawPairsLogData, PTMagicConfiguration systemConfiguration) { foreach (dcaLogData rdld in rawDCALogData) { DCALogData dcaLogData = new DCALogData(); dcaLogData.Amount = rdld.averageCalculator.totalAmount; dcaLogData.BoughtTimes = rdld.boughtTimes; dcaLogData.Market = rdld.market; dcaLogData.ProfitPercent = rdld.profit; dcaLogData.AverageBuyPrice = rdld.averageCalculator.avgPrice; dcaLogData.TotalCost = rdld.averageCalculator.totalCost; dcaLogData.BuyTriggerPercent = rdld.buyProfit; dcaLogData.CurrentLowBBValue = rdld.BBLow; dcaLogData.CurrentHighBBValue = rdld.highbb; dcaLogData.BBTrigger = rdld.BBTrigger; dcaLogData.CurrentPrice = rdld.currentPrice; dcaLogData.SellTrigger = rdld.triggerValue; dcaLogData.PercChange = rdld.percChange; dcaLogData.BuyStrategy = rdld.buyStrategy; if (dcaLogData.BuyStrategy == null) { dcaLogData.BuyStrategy = ""; } dcaLogData.SellStrategy = rdld.sellStrategy; if (dcaLogData.SellStrategy == null) { dcaLogData.SellStrategy = ""; } if (rdld.positive != null) { dcaLogData.IsTrailing = rdld.positive.IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1; dcaLogData.IsTrue = rdld.positive.IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1; } else { if (rdld.buyStrategies != null) { foreach (PTStrategy bs in rdld.buyStrategies) { Strategy buyStrategy = new Strategy(); buyStrategy.Type = bs.type; buyStrategy.Name = bs.name; buyStrategy.EntryValue = bs.entryValue; buyStrategy.EntryValueLimit = bs.entryValueLimit; buyStrategy.TriggerValue = bs.triggerValue; buyStrategy.CurrentValue = bs.currentValue; buyStrategy.CurrentValuePercentage = bs.currentValuePercentage; buyStrategy.Decimals = bs.decimals; buyStrategy.IsTrailing = bs.positive.IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1; buyStrategy.IsTrue = bs.positive.IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1; dcaLogData.BuyStrategies.Add(buyStrategy); } } if (rdld.sellStrategies != null) { foreach (PTStrategy ss in rdld.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 = ss.positive.IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1; sellStrategy.IsTrue = ss.positive.IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1; dcaLogData.SellStrategies.Add(sellStrategy); } } } // Profit Trailer bought times are saved in UTC if (rdld.averageCalculator.firstBoughtDate != null) { DateTimeOffset ptFirstBoughtDate = DateTimeOffset.Parse(rdld.averageCalculator.firstBoughtDate.date.year.ToString() + "-" + rdld.averageCalculator.firstBoughtDate.date.month.ToString("00") + "-" + rdld.averageCalculator.firstBoughtDate.date.day.ToString("00") + "T" + rdld.averageCalculator.firstBoughtDate.time.hour.ToString("00") + ":" + rdld.averageCalculator.firstBoughtDate.time.minute.ToString("00") + ":" + rdld.averageCalculator.firstBoughtDate.time.second.ToString("00"), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); // Convert UTC bought time to local offset time TimeSpan offsetTimeSpan = TimeSpan.Parse(systemConfiguration.GeneralSettings.Application.TimezoneOffset.Replace("+", "")); ptFirstBoughtDate = ptFirstBoughtDate.ToOffset(offsetTimeSpan); dcaLogData.FirstBoughtDate = ptFirstBoughtDate.DateTime; } else { dcaLogData.FirstBoughtDate = Constants.confMinDate; } _dcaLog.Add(dcaLogData); } foreach (dcaLogData rpld in rawPairsLogData) { DCALogData dcaLogData = new DCALogData(); dcaLogData.Amount = rpld.averageCalculator.totalAmount; dcaLogData.BoughtTimes = 0; dcaLogData.Market = rpld.market; dcaLogData.ProfitPercent = rpld.profit; dcaLogData.AverageBuyPrice = rpld.averageCalculator.avgPrice; dcaLogData.TotalCost = rpld.averageCalculator.totalCost; dcaLogData.BuyTriggerPercent = rpld.buyProfit; dcaLogData.CurrentPrice = rpld.currentPrice; dcaLogData.SellTrigger = rpld.triggerValue; dcaLogData.PercChange = rpld.percChange; dcaLogData.BuyStrategy = rpld.buyStrategy; if (dcaLogData.BuyStrategy == null) { dcaLogData.BuyStrategy = ""; } dcaLogData.SellStrategy = rpld.sellStrategy; if (dcaLogData.SellStrategy == null) { dcaLogData.SellStrategy = ""; } dcaLogData.IsTrailing = false; if (rpld.sellStrategies != null) { foreach (PTStrategy 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 = ss.positive.IndexOf("trailing", StringComparison.InvariantCultureIgnoreCase) > -1; sellStrategy.IsTrue = ss.positive.IndexOf("true", StringComparison.InvariantCultureIgnoreCase) > -1; dcaLogData.SellStrategies.Add(sellStrategy); } } // Profit Trailer bought times are saved in UTC if (rpld.averageCalculator.firstBoughtDate != null) { DateTimeOffset ptFirstBoughtDate = DateTimeOffset.Parse(rpld.averageCalculator.firstBoughtDate.date.year.ToString() + "-" + rpld.averageCalculator.firstBoughtDate.date.month.ToString("00") + "-" + rpld.averageCalculator.firstBoughtDate.date.day.ToString("00") + "T" + rpld.averageCalculator.firstBoughtDate.time.hour.ToString("00") + ":" + rpld.averageCalculator.firstBoughtDate.time.minute.ToString("00") + ":" + rpld.averageCalculator.firstBoughtDate.time.second.ToString("00"), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); // Convert UTC bought time to local offset time TimeSpan offsetTimeSpan = TimeSpan.Parse(systemConfiguration.GeneralSettings.Application.TimezoneOffset.Replace("+", "")); ptFirstBoughtDate = ptFirstBoughtDate.ToOffset(offsetTimeSpan); dcaLogData.FirstBoughtDate = ptFirstBoughtDate.DateTime; } else { dcaLogData.FirstBoughtDate = Constants.confMinDate; } _dcaLog.Add(dcaLogData); } }