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 OutAccount TransferFund(int accountId, string operation, double amount) { OutAccount outAcc = null; Transaction ts = null; AccountBalanceBLL abBll = new AccountBalanceBLL(_unit); TransactionBLL tBLL = new TransactionBLL(_unit); Account acc = GetByID(accountId); AccountBalance existAB = abBll.TransferFund(accountId, operation, amount); outAcc = GetOutAccountFromObjs(acc, existAB); return(outAcc); }
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; } }
public TradePosition UpdateExitPosition(TradePosition position, Transaction trans, TradeOrder order, Entity.Indicator ind) { position.ExistFee = trans.Fee; position.ExistPrice = trans.Price; position.ExitTransactionId = trans.Id; position.LastProcessedDate = ind.TradingDate; position.UpdateDT = DateTime.Now; double diff = (position.ExistPrice - position.EntryPrice) * trans.Size * position.Flag; position.Margin = position.EntryPrice * position.Size * Global.MarginRate * position.Flag + diff; Transaction en = new TransactionBLL(_unit).GetByID(position.EntryTransactionId); position.days = new TickerBLL(_unit).GetTradesDaySpan(position.ShareId, en.TradingDate, trans.TradingDate); this.Update(position); return(position); }