Пример #1
0
 public TradeManager(IUnitWork unit) : base(unit)
 {
     aBll  = new AccountBLL(_unit);
     toBll = new TradeOrderBLL(_unit);
     abBll = new AccountBalanceBLL(_unit);
     trBll = new TransactionBLL(_unit);
     tpBll = new TradePositionBLL(_unit);
     tsBll = new TradeSetBLL(_unit);
 }
        public void PopulateReview(TradeReview review)
        {
            TransactionBLL   tBLL  = new TransactionBLL(_unit);
            TradePositionBLL tpBll = new TradePositionBLL(_unit);
            IndicatorBLL     iBll  = new IndicatorBLL(_unit);
            TickerBLL        tkBll = new TickerBLL(_unit);

            OutPosition pos = tpBll.GetOutPositionById(review.TradePositionId);

            Transaction entryTr = tBLL.GetByID(pos.EntryTransactionId);

            Entity.Indicator entryInd = iBll.GetIndicatorByShareDate(pos.ShareId, entryTr.TradingDate);
            Ticker           entryT   = tkBll.GetTickerByDate(pos.ShareId, entryTr.TradingDate);

            iBll.PopulateIndicatorWithTicker(entryInd, entryT);

            review.IsEntryLong = pos.Size > 0 ? true : false;

            if (entryInd.BB_Low.HasValue && entryInd.BB_High.HasValue)
            {
                review.BBEntryPercent = 100 * (entryTr.Price - entryInd.BB_Low.Value) / (entryInd.BB_High.Value - entryInd.BB_Low.Value);
            }

            review.EntryPercent = 100 * (entryTr.Price - entryInd.Low.Value) / (entryInd.High.Value - entryInd.Low.Value);

            if (pos.ExitTransactionId.HasValue)
            {
                Transaction      exitTr  = new TransactionBLL(_unit).GetByID(pos.ExitTransactionId.Value);
                Entity.Indicator exitInd = new IndicatorBLL(_unit).GetIndicatorByShareDate(pos.ShareId, exitTr.TradingDate);
                Ticker           exitT   = tkBll.GetTickerByDate(pos.ShareId, exitTr.TradingDate);
                iBll.PopulateIndicatorWithTicker(exitInd, exitT);

                if (exitInd.BB_Low.HasValue && exitInd.BB_High.HasValue)
                {
                    review.BBExitPercent = 100 * (exitTr.Price - exitInd.BB_Low.Value) / (exitInd.BB_High.Value - exitInd.BB_Low.Value);
                }

                review.ExitPercent = 100 * (exitTr.Price - exitInd.Low.Value) / (exitInd.High.Value - exitInd.Low.Value);

                review.DaysSpan = pos.Days;
                review.Diff     = pos.Diff;
                review.Diff_Per = pos.Diff_Per;
            }
        }
Пример #3
0
        public AccountSummary GetAccountSummary(int accountId)
        {
            AccountBLL        aBLL        = new AccountBLL(_unit);
            AccountBalanceBLL abBll       = new AccountBalanceBLL(_unit);
            TradeOrderBLL     orderBLL    = new TradeOrderBLL(_unit);
            TradePositionBLL  positionBLL = new TradePositionBLL(_unit);

            AccountSummary aSummary = new AccountSummary();

            aSummary.Account          = aBLL.GetByID(accountId);
            aSummary.Balance          = abBll.GetAccountBalanceByAccount(accountId);
            aSummary.OpenOrders       = orderBLL.GetListByAccountStatus(accountId, "open");
            aSummary.CurrentPositions = positionBLL.GetOutstandingPositions(accountId);

            aSummary.Balance.Margin        = aSummary.PositionMarginSum;
            aSummary.Balance.Reserve       = aSummary.OrderReserveSum;
            aSummary.Balance.PositionValue = aSummary.PositionValueSum;

            return(aSummary);
        }