コード例 #1
0
        public ActionResult AccountDetails(AccountItem account)
        {
            if (!ModelState.IsValid) return RedirectToAction("AccountDetails", new { accountId = account.ID });

            var result = string.Format(accountRepository.SaveAccountChanges(account) ?
                                      Resource.MessageEditingMade + " (" + Resource.TitleAccount + "  {0})." :
                                      Resource.ErrorMessageSaveDataChanges + " ("+ Resource.TitleAccount + "  {0}).", account.ID);

            ViewData["listTickers"] = Utils.SelectAllValuesFromTable<COMMODITY>(x => new SelectListItem { Text = x.Title, Value = x.Title });
            ViewData["listGroups"] = Utils.SelectAllValuesFromTable<ACCOUNT_GROUP>(x => new SelectListItem { Text = x.Code, Value = x.Code });
            return RedirectToAction("Accounts", new { message = result });
        }
コード例 #2
0
        public AccountItem GetAccount(int id)
        {
            decimal brokerLeverage;
            AccountItem account;
            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var accountDb = ctx.ACCOUNT.FirstOrDefault(x => x.ID == id);
                    account = new AccountItem(accountDb)
                    {
                        CountOpenPosition = ctx.POSITION.Count(x => x.AccountID == id)
                    };

                    brokerLeverage = ctx.ACCOUNT_GROUP.Single(x => x.Code == account.Group).BrokerLeverage;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(String.Format("GetAccount() - Не удалось получить счет {0}", id), ex);
                return null;
            }

            // инициализация "расчётных" параметров счёта таких ка баланс и профит
            try
            {
                List<MarketOrder> marketOrders;

                TradeSharpAccount.Instance.proxy.GetMarketOrders(account.ID, out marketOrders);

                var quoteStorage = new QuoteStorageProxy("IQuoteStorageBinding");
                var currentQuotes = quoteStorage.GetQuoteData(); // актуальные значения катировок на текущий момент (всех катировок, зарегистрированных в терминале)

                account.Equity = account.Balance + (decimal)DalSpot.Instance.CalculateOpenedPositionsCurrentResult(marketOrders,
                    currentQuotes, account.Currency);

                var processingErrors = new List<string>();
                account.Exposure = DalSpot.Instance.CalculateExposure(marketOrders, currentQuotes, account.Currency, processingErrors);
                if (brokerLeverage != 0 && account.Exposure != 0)
                    account.UsedMargin = (account.Exposure / brokerLeverage);
            }
            catch (Exception ex)
            {
                Logger.Error("GetAccount() не удалось расчитать текущий profit по открытым сделкам", ex);
                return null;
            }
            return account;
        }