Esempio n. 1
0
        public static decimal CalculateAccountEquityWithShares(TradeSharpConnection ctx,
                                                               ACCOUNT account,
                                                               int accountOwnerId,
                                                               Dictionary <string, QuoteData> quotes,
                                                               out List <AccountShare> accountShares,
                                                               out bool noQuoteError)
        {
            accountShares = new List <AccountShare>();
            var orders = ctx.POSITION.Where(p => p.AccountID == account.ID &&
                                            p.State == (int)PositionState.Opened).ToList().Select(LinqToEntity.DecorateOrder).ToList();

            var curProfit = DalSpot.Instance.CalculateOpenedPositionsCurrentResult(orders,
                                                                                   quotes, account.Currency, out noQuoteError);

            if (noQuoteError)
            {
                return(account.Balance);
            }

            var equity = (decimal)curProfit + account.Balance;

            // паи владельцев
            accountShares = ctx.ACCOUNT_SHARE.Where(s => s.Account == account.ID).ToList().Select(s =>
            {
                var sh        = LinqToEntity.DecorateAccountShare(s);
                sh.ShareMoney = sh.SharePercent * equity / 100;
                return(sh);
            }).ToList();

            if (accountShares.Count == 0)
            {
                // прописать долю владельца
                accountShares.Add(new AccountShare
                {
                    ShareMoney   = equity,
                    SharePercent = 100,
                    UserId       = accountOwnerId
                });
            }

            return(equity);
        }