public OperationResult NewTrade(NewTrade trade)
        {
            return(InvokeOperations.InvokeOperation(() =>
            {
                var account = context.TradeAccounts
                              .Include(x => x.Trades)
                              .Include(x => x.Charts)
                              .FirstOrDefault(x => x.Id == trade.TradeAccountId);
                if (account == null)
                {
                    return;
                }

                var t = new Trades
                {
                    Id = Guid.NewGuid(),
                    TradeAccountId = account.Id,
                    Date = trade.Date,
                    Direction = trade.Direction,
                    Entry = trade.Entry,
                    Price = trade.Price,
                    Profit = trade.Profit,
                    Symbol = trade.Symbol,
                    Ticket = trade.Ticket,
                    Volume = trade.Volume
                };
                context.Add(t);

                if (trade.Entry != TradeEntry.In)
                {
                    account.OrdersCount += 1;
                    account.TotalProfit += trade.Profit;
                    account.TotalProfitInPercent = account.TotalProfit / account.StartBalance * 100m;
                }

                context.SaveChanges();

                var trades = GetTradeHistory(account);
                if (trades.IsSuccess)
                {
                    var ipfsHash = ipfsService.WriteIpfsText(trades.Data);
                    if (ipfsHash.IsSuccess)
                    {
                        account.IpfsHash = ipfsHash.Data;
                        context.SaveChanges();
                    }
                }

                statisticService.RecalculateChart(account);
                statisticService.RecalculatePlaces();
            }));
        }
Exemplo n.º 2
0
        private OperationResult <string> UpdateInvestmentInIpfs(Guid investmentId)
        {
            var investmentProgram = context.InvestmentPrograms
                                    .Include(x => x.ManagerAccount)
                                    .ThenInclude(x => x.ManagersAccountsTrades)
                                    .Include(x => x.ManagerAccount.ManagersAccountsStatistics)
                                    .Include(x => x.Token)
                                    .Include(x => x.Periods)
                                    .Include(x => x.InvestmentRequests)
                                    .First(x => x.Id == investmentId);

            var json = JsonConvert.SerializeObject(investmentProgram.ToInvestmentProgram(null, null));

            return(ipfsService.WriteIpfsText(json));
        }