public void AddJourneyOrder(AccountBalance accB, string action, TradeOrder order) { AccountSummary aSummary = new AccountBLL(_unit).GetAccountSummary(accB.AccountId); AccountBalanceJourney abj = new AccountBalanceJourney { FundAmount = aSummary.Balance.FundAmount, AvailableFund = aSummary.Balance.AvailableFund, Margin = aSummary.PositionMarginSum, Reserve = aSummary.OrderReserveSum, FeeSum = aSummary.Balance.FeeSum, PositionValue = aSummary.PositionValueSum, TotalBalance = aSummary.Balance.TotalBalance, Action = action, AccountId = accB.AccountId, UpdateDT = DateTime.Now }; if (order != null) { abj.OrderId = order.Id; abj.TradingDate = order.TradingOrderDate; } if (aSummary != null) { string aSummaryString = XMLHelper.SerializeObject(aSummary); abj.AccountSummaryXML = aSummaryString; } base.Create(abj); }
private void CalculateOrder(TradeOrder order, TradePosition position) { var account = new AccountBLL(_unit).GetByID(order.AccountId); var broker = new BrokerBLL(_unit).GetByID(account.BrokerId); if (IsReverse(order, position)) { if (IsReverseExceed(order, position)) { int sizeDiff = GetSizeDiff(order, position); order.Fee = GetFee(order.Size * order.OrderPrice, broker); order.Reserve = sizeDiff * order.OrderPrice * Global.MarginRate + order.Fee; } else { order.Fee = GetFee(order.OrderValue, broker); order.Reserve = 0; } } else { order.Fee = GetFee(order.OrderValue, broker); order.Reserve = order.OrderValue * Global.MarginRate + order.Fee; } }
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); }
private void CalculateOrder(TradeOrder order) { var account = new AccountBLL(_unit).GetByID(order.AccountId); var broker = new BrokerBLL(_unit).GetByID(account.BrokerId); order.Fee = GetFee(order.OrderValue, broker); order.Reserve = order.OrderValue * Global.MarginRate + order.Fee; }
public void ProcessAccountsByZone(string userId, int zoneId) { AccountBLL aBll = new AccountBLL(_unit); List <Account> aList = aBll.GetAccountListByUser(userId, zoneId); foreach (var a in aList) { this.ProcessAccountOrders(a.Id); this.ProcessAccountPositions(a.Id); } }
public TradeOrder CreateExitOrder(TradePosition position, Entity.Indicator ind, bool isStop) { TradeOrder to = new TradeOrder(); Account acc = new AccountBLL(_unit).GetByID(position.AccountId); Broker broker = new BrokerBLL(_unit).GetByID(acc.BrokerId); AccountBalance ab = new AccountBalanceBLL(_unit).GetAccountBalanceByAccount(acc.Id); to.AccountId = position.AccountId; if (position.Size > 0) { to.Direction = "Short"; } else { to.Direction = "Long"; } to.Size = Math.Abs(position.Size); if (isStop) { to.OrderPrice = position.Stop.Value; } else { to.OrderPrice = position.Limit.Value; } to.Fee = this.GetFee(to.OrderValue, broker); to.ShareId = position.ShareId; to.Source = OrderSource.Stop.ToString(); to.UpdateDate = DateTime.Now; to.ProcessedTradingDate = ind.TradingDate; to.LatestTradingDate = ind.TradingDate; to.Status = "Fulfilled"; to.UpdatedBy = "System"; to.TradingOrderDate = ind.TradingDate; to.OrderType = "Exit"; this.Create(to); new AccountBalanceJourneyBLL(_unit).AddJourneyOrder(ab, "O." + to.Direction, to); return(to); }
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); }
public void InitCreate(AccountBalance ab) { AccountBalanceJourney abj = new AccountBalanceJourney { AvailableFund = 0, Margin = 0, PositionValue = 0, TotalBalance = 0, Action = "AccountInit", AccountId = ab.AccountId, UpdateDT = DateTime.Now }; AccountSummary aSummary = new AccountBLL(_unit).GetAccountSummary(ab.AccountId); if (aSummary != null) { string aSummaryString = XMLHelper.SerializeObject(aSummary); abj.AccountSummaryXML = aSummaryString; } base.Create(abj); }