private void ValidateCommon(Order order) { var instrument = order.Owner.TradingInstrument; var settingInstrument = order.Owner.SettingInstrument(); if (!instrument.IsTrading) { throw new TransactionServerException(TransactionError.TimingIsNotAcceptable); } var tradePolicyDetail = order.Owner.TradePolicyDetail(); BOPolicy binaryOptionPolicy = null; BOPolicyDetail binaryOptionPolicyDetail = null; if (tradePolicyDetail.BinaryOptionPolicyID == null) { throw new TransactionServerException(TransactionError.OrderTypeIsNotAcceptable); } if (!BOPolicyRepository.TryGet(tradePolicyDetail.BinaryOptionPolicyID.Value, out binaryOptionPolicy) || !BOPolicyDetailRepository.Default.TryGet(new BOPolicyDetailKey(tradePolicyDetail.BinaryOptionPolicyID.Value, order.BetTypeId, order.Frequency), out binaryOptionPolicyDetail)) { throw new TransactionServerException(TransactionError.OrderTypeIsNotAcceptable); } if (binaryOptionPolicyDetail.BetType.Option == BOOption.Instance) { BOBetType betType = BOBetTypeRepository.Get(order.BetTypeId); TimeSpan acceptSpan = TimeSpan.FromSeconds(order.Frequency * betType.HitCount); DateTime acceptTime = instrument.CurrentTradingSession.AcceptEndTime - acceptSpan; if (Market.MarketManager.Now >= acceptTime) { throw new TransactionServerException(TransactionError.TimingIsNotAcceptable); } } else { if (binaryOptionPolicyDetail.BetType.HitCount > 1) { this.Logger.WarnFormat("Hit count must be 1 when BOSettleTime is filled, order id = {0}", order.Id); throw new TransactionServerException(TransactionError.OrderTypeIsNotAcceptable); } DateTime now = Market.MarketManager.Now; TimeSpan acceptVariation = TimeSpan.Zero; if (binaryOptionPolicyDetail.BetType.Option == BOOption.Settle) { acceptVariation = binaryOptionPolicyDetail.BetType.LastPlaceOrderTimeSpan; } else if (binaryOptionPolicyDetail.BetType.Option == BOOption.IntegralMinute) { acceptVariation = TimeSpan.FromMinutes(order.Frequency); } if (order.SettleTime.Value > instrument.CurrentTradingSession.AcceptEndTime || now > (order.SettleTime.Value - acceptVariation)) { throw new TransactionServerException(TransactionError.TimingIsNotAcceptable); } } }
internal override void Validate(Order order) { base.Validate(order); var settingInstrument = order.Owner.SettingInstrument(); if (!settingInstrument.AllowBinaryOptionOrder || order.SetPrice != null) { throw new TransactionServerException(TransactionError.OrderTypeIsNotAcceptable); } BOPolicy binaryOptionPolicy = null; BOPolicyDetail binaryOptionPolicyDetail = null; BOPolicyRepository.TryGet(order.Owner.TradePolicyDetail().BinaryOptionPolicyID.Value, out binaryOptionPolicy); BOPolicyDetailRepository.Default.TryGet(new BOPolicyDetailKey(order.Owner.TradePolicyDetail().BinaryOptionPolicyID.Value, order.BetTypeId, order.Frequency), out binaryOptionPolicyDetail); if (order.Lot < binaryOptionPolicyDetail.MinBet || order.Lot > binaryOptionPolicyDetail.MaxBet) { throw new TransactionServerException(TransactionError.OrderLotExceedMaxLot); } var tradePolicy = order.Owner.TradePolicy; bool needCheck = tradePolicy.BinaryOptionBetLimit > 0 || binaryOptionPolicy.MaxOrderCount != null || binaryOptionPolicy.TotalBetLimit != null || binaryOptionPolicyDetail.MaxOrderCount != null || binaryOptionPolicyDetail.TotalBetLimit != null; if (needCheck) { decimal totalBetAmount, totalBetAmountByPolicy, totalBetAmountByPolicyDetail; int totalBetOrderByPolicy, totalBetOrderByPolicyDetail; this.SumBetAfterPlace(order, out totalBetAmount, out totalBetAmountByPolicy, out totalBetOrderByPolicy, out totalBetAmountByPolicyDetail, out totalBetOrderByPolicyDetail); bool exceeded = false; if (tradePolicy.BinaryOptionBetLimit > 0) { exceeded |= totalBetAmount > tradePolicy.BinaryOptionBetLimit; } if (binaryOptionPolicy.MaxOrderCount != null) { exceeded |= totalBetOrderByPolicy > binaryOptionPolicy.MaxOrderCount.Value; } if (binaryOptionPolicy.TotalBetLimit != null) { exceeded |= totalBetAmountByPolicy > binaryOptionPolicy.TotalBetLimit.Value; } if (binaryOptionPolicyDetail.MaxOrderCount != null) { exceeded |= totalBetOrderByPolicyDetail > binaryOptionPolicyDetail.MaxOrderCount.Value; } if (binaryOptionPolicyDetail.TotalBetLimit != null) { exceeded |= totalBetAmountByPolicyDetail > binaryOptionPolicyDetail.TotalBetLimit.Value; } if (exceeded) { throw new TransactionServerException(TransactionError.ExceedMaxPhysicalValue); } } }