public void UpdateAccount() { if (!ForexAuthentication.Connected || !ForexRates.Loaded || (DataAccount.IsValid && DataAccount.UpdateSpan < 1000)) { return; } Margin marg = null; try { marg = CEDTS_TradingService.GetMarginBlotter(ForexAuthentication.Token).Output[0]; } catch (Exception e) { Exceptions.Add(e); return; } Account current = AccountInfo.ToAccount(marg); current.MarginOrigin = TickTime.Now; if (DataAccount.Count <= 0) { if (current.OpenPosition == 0) { current.ClosedBalance = current.MarginBalance; current.OriginBalance = current.MarginBalance; } else { throw new Exception("Archive log must contain at least one closed record !"); } } else { current.ClosedBalance = this.GetClosedMarginBalance(); current.OriginBalance = this.GetOriginMarginBalance(); } if (DataAccount.Count <= 0 || (current.OpenPosition == 0 && !AccountInfo.EqualsPosition(current, AccountLog))) { lock (DataAccount) { DataAccount.IsValid = false; DataAccount.Add(current.MarginOrigin, current); //only closed position should be saved DataAccount.SaveFile(false); } } current.LiveProfit = this.GetLiveProfit(); Account = current; //Account.LiveOrigin = TickTime.Now; DataAccount.IsValid = true; }