protected void btnTradingAccountDetails_Click(object sender, EventArgs e) { if (ddlTradingAccounts.SelectedValue != null && Session["Token"] != null) { var accountID = ddlTradingAccounts.SelectedValue; var token = Session["Token"].ToString(); dgvDeals.DataSource = Deal.GetDeals(_apiUrl, accountID, token); dgvDeals.DataBind(); dgvCashflowHistory.DataSource = CashflowHistory.GetCashflowHistory(_apiUrl, accountID, token); dgvCashflowHistory.DataBind(); dgvPendingOrders.DataSource = PendingOrder.GetPendingOrders(_apiUrl, accountID, token); dgvPendingOrders.DataBind(); dgvPositions.DataSource = Position.GetPositions(_apiUrl, accountID, token); dgvPositions.DataBind(); dgvSymbols.DataSource = Symbols.GetSymbols(_apiUrl, accountID, token); dgvSymbols.DataBind(); var date = new DateTime(2017, 01, 12); var tickDataBid = TickData.GetTickData(_apiUrl, accountID, token, "EURUSD", TickData.TickDataType.Bid, date, 07, 13, 46, 07, 15, 26); var tickDataAsk = TickData.GetTickData(_apiUrl, accountID, token, "EURUSD", TickData.TickDataType.Ask, date, 07, 13, 46, 07, 15, 26); chrTickData.Series[0].Points.Clear(); foreach (var td in tickDataBid) { var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Math.Round(Convert.ToDouble(td.Timestamp) / 1000d)); chrTickData.Series[0].Points.Add(new DataPoint(dt.ToOADate(), Convert.ToDouble(td.Tick))); } chrTickData.Series[1].Points.Clear(); foreach (var td in tickDataAsk) { var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Math.Round(Convert.ToDouble(td.Timestamp) / 1000d)); chrTickData.Series[1].Points.Add(new DataPoint(dt.ToOADate(), Convert.ToDouble(td.Tick))); } chrTickData.ChartAreas[0].AxisY.Minimum = chrTickData.Series[0].Points.Min(x => x.YValues[0]); chrTickData.ChartAreas[0].AxisY.Maximum = chrTickData.Series[0].Points.Max(x => x.YValues[0]); var dateFrom = new DateTime(2017, 01, 11, 00, 00, 00); var dateTo = new DateTime(2017, 01, 13, 00, 00, 00); var trendBarH1 = TrendBar.GetTrendBar(_apiUrl, accountID, token, "EURUSD", TrendBar.TrendBarType.Hour, dateFrom, dateTo); dateFrom = new DateTime(2017, 01, 12, 23, 00, 00); dateTo = new DateTime(2017, 01, 13, 00, 00, 00); var trendBarM1 = TrendBar.GetTrendBar(_apiUrl, accountID, token, "EURUSD", TrendBar.TrendBarType.Minute, dateFrom, dateTo); chrTrendChartH1.Series[0].Points.Clear(); foreach (var tb in trendBarH1) { var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Math.Round(Convert.ToDouble(tb.Timestamp) / 1000d)); chrTrendChartH1.Series[0].Points.Add(new DataPoint(dt.ToOADate(), new double[] { Convert.ToDouble(tb.High), Convert.ToDouble(tb.Low), Convert.ToDouble(tb.Open), Convert.ToDouble(tb.Close) })); } chrTrendChartH1.ChartAreas[0].AxisY.Minimum = chrTrendChartH1.Series[0].Points.Min(x => x.YValues.Min()); chrTrendChartH1.ChartAreas[0].AxisY.Maximum = chrTrendChartH1.Series[0].Points.Max(x => x.YValues.Max()); chrTrendChartM1.Series[0].Points.Clear(); foreach (var tb in trendBarM1) { var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Math.Round(Convert.ToDouble(tb.Timestamp) / 1000d)); chrTrendChartM1.Series[0].Points.Add(new DataPoint(dt.ToOADate(), new double[] { Convert.ToDouble(tb.High), Convert.ToDouble(tb.Low), Convert.ToDouble(tb.Open), Convert.ToDouble(tb.Close) })); } chrTrendChartM1.ChartAreas[0].AxisY.Minimum = chrTrendChartM1.Series[0].Points.Min(x => x.YValues.Min()); chrTrendChartM1.ChartAreas[0].AxisY.Maximum = chrTrendChartM1.Series[0].Points.Max(x => x.YValues.Max()); } }
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))); }