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; } }
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 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); }