Beispiel #1
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);
        }
Beispiel #2
0
        public void ProcessAccountPositions(int accountId)
        {
            List <TradePosition> tpList = tpBll.GetOutstandingPositions(accountId);
            Account acc           = aBll.GetByID(accountId);
            int     dateToProcess = this.GetDateToProcess(acc);

            foreach (TradePosition tp in tpList)
            {
                int startDate = this.GetPositionStartDate(tp);


                List <Screen2.Entity.Indicator> iList = this.GetIndicatorsForTrade(tp, dateToProcess);
                Transaction tr = trBll.GetByID(tp.EntryTransactionId);

                if (iList != null && iList.Count > 0)
                {
                    foreach (Screen2.Entity.Indicator ind in iList)
                    {
                        if (ind.TradingDate > tr.TradingDate)
                        {
                            if (tp.Size > 0)
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value >= ind.Low && tp.Limit.Value <= ind.High)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                            else
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value <= ind.High && tp.Limit.Value >= ind.Low)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                        }

                        if (ind.TradingDate == tr.TradingDate)
                        {
                            if (tp.Size > 0)
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High &&
                                    ind.Close < ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value >= ind.Low && tp.Limit.Value <= ind.High &&
                                         ind.Close > ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                            else
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High &&
                                    ind.Close > ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value <= ind.High && tp.Limit.Value >= ind.Low &&
                                         ind.Close < ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                        }
                    }
                }
            }
        }