Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="game"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Order CreateOrder(OpenOrderInfo dto, Game game, string user)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            if (game == null)
            {
                throw new ArgumentNullException(nameof(game));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            _logger.LogDebug("创建订单");
            try
            {
                ValidateOpenOrderRule(dto, game, user);
                _notify.OnCreating(dto);

                var openPrice = GetOpenPrice(dto, game, user);
                var order     = CreateOrder(dto, user);
                order.Open(openPrice, game);

                _orderContext.UncloseOrders.Add(order);
                _orderStore.Add(order);

                _notify.OnCreated(order);
                return(order);
            }
            catch (Exception ex)
            {
                throw new OrderCreatingException("建仓失败", ex);
            }
        }
Пример #2
0
        /// <summary>
        /// </summary>
        /// <param name="openOrderInfo"></param>
        /// <param name="game"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        private Quotation GetOpenPrice(OpenOrderInfo openOrderInfo, Game game, string user)
        {
            if (game == null)
            {
                throw new ArgumentNullException(nameof(game));
            }

            var       openPricePolicies = _pricePolicyStore.GetOpenPricePolicies(user);
            Quotation openPrice;

            foreach (var policy in openPricePolicies)
            {
                if (policy.TryGetPrice(_qutationContext, openOrderInfo, game, out openPrice))
                {
                    return(openPrice);
                }
            }

            if (DefaultOpenOpenPricePolicy.TryGetPrice(_qutationContext, openOrderInfo, game, out openPrice))
            {
                return(openPrice);
            }

            throw new OrderException("暂时无报价,请联系管理员.");
        }
Пример #3
0
        /// <summary>
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="game"></param>
        /// <param name="user"></param>
        private void ValidateOpenOrderRule(OpenOrderInfo dto, Game game, string user)
        {
            var openOrderPolicies = _orderPolicyStore.GetOpenOrderPolicies(user);

            foreach (var policy in openOrderPolicies)
            {
                if (!policy.IsPass(dto, game, user, _orderContext))
                {
                    throw new OrderCreatingException(policy.Message);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="user"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        private Order CreateOrder(OpenOrderInfo dto, string user)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var order = new Order(dto.Volume, dto.Direction, user)
            {
                Id = _orderIdGenerator.Next()
            };

            order.OpenInfo.ClientPostTime = dto.ClientPostTime;


            return(order);
        }