public IActionResult Index(int?acId) { ConnectAPI connect = ConnectAPI.GetConnectAPI(_identitycontext, _context, User.Identity.Name, acId); if (connect.AccountId == 0) { return(Redirect("/")); } var useraccounts = _identitycontext.AspNetUserForexAccount.Where(u => u.AppIdentityUserId == connect.UserId).ToList(); var accounts = _context.FrxAccount.Where(x => useraccounts.SingleOrDefault(s => s.AccountNumber == x.AccountNumber && s.Password == x.Password) != null).ToList(); return(View(Tuple.Create <ConnectAPI, List <FrxAccount> >(connect, accounts))); }
public async Task <IActionResult> Index(int?acId) { ConnectAPI connect = ConnectAPI.GetConnectAPI(_identitycontext, _context, User.Identity.Name, acId); if (connect.AccountId == 0) { return(Redirect("/")); } var useraccounts = _identitycontext.AspNetUserForexAccount.Where(u => u.AppIdentityUserId == connect.UserId).ToList(); var accounts = _context.FrxAccount.Where(x => useraccounts.SingleOrDefault(s => s.AccountNumber == x.AccountNumber && s.Password == x.Password) != null).ToList(); var symbols = _context.FrxSymbol.ToList(); #region GetCashflow var cashflow = CashflowHistory.GetCashflowHistory(connect.ApiUrl, connect.AccountId.ToString(), connect.AccessToken); foreach (var c in cashflow) { var fc = new FrxCashflow(); fc.Id = Convert.ToInt32(c.CashflowId); fc.AccountId = connect.AccountId; fc.Balance = c.Balance; fc.BalanceVersion = c.BalanceVersion; fc.ChangeTimestamp = c.ChangeTimestamp; fc.Type = c.Type; fc.Delta = c.Delta / 100; fc.Equity = c.Equity; var tempfc = _context.FrxCashflow.SingleOrDefault(x => x.Id == fc.Id); if (tempfc == null) { _context.FrxCashflow.Add(fc); await _context.SaveChangesAsync(); } } #endregion #region GetHistory long fromTimestamp; if (_context.FrxHistory.Count() != 0) { fromTimestamp = _context.FrxHistory.Select(x => x.ClosingTimestamp).Max() - 86400000; } else { fromTimestamp = connect.TraderRegistrationTimestamp - 86400000; } DateTime utcNow = DateTime.UtcNow; long toTimestamp = ConvertJson.DateTimeToStamp(utcNow.AddDays(1)); var deal = Deal.GetDeals(connect.ApiUrl, connect.AccountId.ToString(), connect.AccessToken, fromTimestamp.ToString(), toTimestamp.ToString()); var deal_history = new List <Deal>(); foreach (var d in deal) { if (d.PositionCloseDetails != null) { deal_history.Add(d); } } foreach (var h in deal_history) { FrxHistory fh = new FrxHistory(); fh.ClosingDealId = h.DealId; fh.AccountId = connect.AccountId; fh.Balance = h.PositionCloseDetails.Balance / 100; fh.BalanceVersion = h.PositionCloseDetails.BalanceVersion; fh.BaseToUSDConversionRate = h.BaseToUSDConversionRate; fh.ClosedToDepoitConversionRate = h.PositionCloseDetails.ClosedToDepositConversionRate; fh.ClosingTimestamp = h.ExecutionTimestamp; fh.ClosingPrice = h.ExecutionPrice; fh.Comment = h.Comment; fh.Commissions = h.PositionCloseDetails.Commission / 100; fh.EntryPrice = h.PositionCloseDetails.EntryPrice; long tempTimestamp = h.ExecutionTimestamp; foreach (var d in deal) { if (d.PositionId == h.PositionId) { if (d.ExecutionTimestamp < tempTimestamp) { tempTimestamp = d.ExecutionTimestamp; } } } fh.EntryTimestamp = tempTimestamp; fh.Equity = h.PositionCloseDetails.Equity / 100; fh.EquityBaseRoi = h.PositionCloseDetails.EquityBasedRoi / 100; fh.GrossProfit = h.PositionCloseDetails.Profit / 100; fh.Label = h.Label; fh.MarginRate = h.MarginRate; fh.Swap = h.PositionCloseDetails.Swap / 100; fh.NetProfit = fh.GrossProfit + fh.Swap + fh.Commissions; fh.Pips = h.PositionCloseDetails.ProfitInPips; fh.PositionId = h.PositionId; fh.SymbolCode = h.SymbolName; fh.Volume = h.PositionCloseDetails.ClosedVolume / 100; var symbol = symbols.SingleOrDefault(x => x.SymbolName == h.SymbolName); var minVolume = symbol.MinOrderVolume; var minLot = symbol.MinOrderLot; var pipPosition = symbol.PipPosition; fh.Lot = fh.Volume / minVolume * minLot; fh.QuoteToDepositConversionRate = h.PositionCloseDetails.QuoteToDepositConversionRate; fh.Roi = h.PositionCloseDetails.Roi; fh.TradeType = h.TradeSide == "BUY" ? TradeType.Sell : TradeType.Buy; fh.PipPosition = pipPosition; var result = _context.FrxHistory.SingleOrDefault(x => x.ClosingDealId == fh.ClosingDealId); if (result == null) { _context.Add(fh); await _context.SaveChangesAsync(); } } var histories = _context.FrxHistory.Where(x => x.AccountId == connect.AccountId).ToList(); #endregion return(View(Tuple.Create <ConnectAPI, List <FrxAccount> >(connect, accounts))); }