private static ExecutionMessage CreateTrade(string smartId, DateTime time, decimal?price, decimal?volume, long tradeId, SmartOrderAction action)
 {
     return(new ExecutionMessage
     {
         SecurityId = new SecurityId {
             Native = smartId
         },
         TradeId = tradeId,
         TradePrice = price,
         TradeVolume = volume,
         OriginSide = action.ToSide(),
         ServerTime = time.ApplyTimeZone(TimeHelper.Moscow),
         ExecutionType = ExecutionTypes.Tick,
     });
 }
		private static ExecutionMessage CreateTrade(string smartId, DateTime time, decimal price, decimal volume, long tradeId, SmartOrderAction action)
		{
			return new ExecutionMessage
			{
				SecurityId = new SecurityId { Native = smartId },
				TradeId = tradeId,
				TradePrice = price,
				Volume = volume,
				OriginSide = action.ToSide(),
				ServerTime = time.ApplyTimeZone(TimeHelper.Moscow),
				ExecutionType = ExecutionTypes.Tick,
			};
		}
Exemple #3
0
        private void OnOrderChanged(string portfolioName, string secSmartId, SmartOrderState state, SmartOrderAction action, SmartOrderType smartType, bool isOneDay,
                                    decimal?price, int volume, decimal?stop, int balance, DateTime time, string smartOrderId, long orderId, int status, int transactionId)
        {
            this.AddInfoLog(() => "SmartTrader.UpdateOrder: id {0} smartId {1} type {2} direction {3} price {4} volume {5} balance {6} time {7} security {8} state {9}"
                            .Put(orderId, smartOrderId, smartType, action, price, volume, balance, time, secSmartId, state));

            var side = action.ToSide();

            if (side == null)
            {
                throw new InvalidOperationException(LocalizedStrings.Str1872Params.Put(action, orderId, transactionId));
            }

            // http://stocksharp.com/forum/yaf_postsm28324_Oshibka-pri-vystavlienii-ili-sniatii-zaiavki.aspx#post28324
            if (transactionId == 0)
            {
                return;
            }

            if (state.IsReject())
            {
                // заявка была ранее зарегистрирована через SmartTrader
                //if (_smartIdOrders.ContainsKey(smartOrderId))
                //{
                // замечены SystemCancel приходящие в процессе Move после которых приходит Active
                if (state != SmartOrderState.SystemCancel)
                {
                    //var trId = GetTransactionBySmartId(smartOrderId);

                    SendOutMessage(new ExecutionMessage
                    {
                        ExecutionType         = ExecutionTypes.Transaction,
                        OriginalTransactionId = transactionId,
                        OrderStringId         = smartOrderId,
                        ServerTime            = time.ApplyTimeZone(TimeHelper.Moscow),
                        OrderState            = OrderStates.Failed,
                        Error        = new InvalidOperationException(LocalizedStrings.Str1873Params.Put(transactionId)),
                        HasOrderInfo = true,
                    });
                }
                //}

                return;
            }

            var orderType = smartType.ToOrderType();

            var orderState  = OrderStates.Active;
            var orderStatus = OrderStatus.Accepted;

            switch (state)
            {
            case SmartOrderState.ContragentReject:
                orderStatus = OrderStatus.NotAcceptedByManager;
                orderState  = OrderStates.Failed;
                break;

            // Принята ТС
            case SmartOrderState.Submited:
                orderStatus = OrderStatus.SentToServer;
                break;

            // Зарегистрирована в ТС
            case SmartOrderState.Pending:
                orderStatus = OrderStatus.ReceiveByServer;

                if (orderType == OrderTypes.Conditional)
                {
                    orderState = OrderStates.Active;
                }

                break;

            // Выведена на рынок
            case SmartOrderState.Open:
                orderStatus = OrderStatus.Accepted;

                if (orderType == OrderTypes.Conditional && orderId != 0)
                {
                    orderState = OrderStates.Done;
                }
                else
                {
                    orderState = OrderStates.Active;
                }
                break;

            // Снята по окончанию торгового дня
            case SmartOrderState.Expired:
                orderState = OrderStates.Done;
                break;

            // Отменёна
            case SmartOrderState.Cancel:
                orderState = OrderStates.Done;
                break;

            // Исполнена
            case SmartOrderState.Filled:
                orderState = OrderStates.Done;
                break;

            // Частично исполнена
            case SmartOrderState.Partial:
                if (orderState == OrderStates.None)
                {
                    orderState = OrderStates.Active;
                }
                break;

            // Отклонена биржей
            case SmartOrderState.ContragentCancel:
                orderStatus = OrderStatus.CanceledByManager;
                orderState  = OrderStates.Failed;
                break;

            // Отклонена биржей
            case SmartOrderState.SystemReject:
                orderStatus = OrderStatus.NotDone;
                orderState  = OrderStates.Failed;
                break;

            // Отклонена биржей
            case SmartOrderState.SystemCancel:
                orderStatus = OrderStatus.GateError;
                orderState  = OrderStates.Failed;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SendOutMessage(new ExecutionMessage
            {
                SecurityId = new SecurityId {
                    Native = secSmartId
                },
                PortfolioName         = portfolioName,
                Side                  = (Sides)side,
                OrderPrice            = price ?? 0,
                OrderVolume           = volume,
                ServerTime            = time.ApplyTimeZone(TimeHelper.Moscow),
                Balance               = balance,
                OrderId               = orderId == 0 ? (long?)null : orderId,
                OrderType             = orderType,
                OrderState            = orderState,
                OrderStatus           = orderStatus,
                OriginalTransactionId = transactionId,
                OrderStringId         = smartOrderId,
                ExpiryDate            = isOneDay ? DateTimeOffset.Now.Date.ApplyTimeZone(TimeHelper.Moscow) : (DateTimeOffset?)null,
                Condition             = orderType == OrderTypes.Conditional ? new SmartComOrderCondition {
                    StopPrice = stop
                } : null,
                ExecutionType = ExecutionTypes.Transaction,
                HasOrderInfo  = true,
            });
        }
		private void OnOrderChanged(string portfolioName, string secSmartId, SmartOrderState state, SmartOrderAction action, SmartOrderType smartType, bool isOneDay,
			decimal? price, int volume, decimal? stop, int balance, DateTime time, string smartOrderId, long orderId, int status, int transactionId)
		{
			this.AddInfoLog(() => "SmartTrader.UpdateOrder: id {0} smartId {1} type {2} direction {3} price {4} volume {5} balance {6} time {7} security {8} state {9}"
				.Put(orderId, smartOrderId, smartType, action, price, volume, balance, time, secSmartId, state));

			var side = action.ToSide();

			if (side == null)
				throw new InvalidOperationException(LocalizedStrings.Str1872Params.Put(action, orderId, transactionId));

			// http://stocksharp.com/forum/yaf_postsm28324_Oshibka-pri-vystavlienii-ili-sniatii-zaiavki.aspx#post28324
			if (transactionId == 0)
				return;

			if (state.IsReject())
			{
				// заявка была ранее зарегистрирована через SmartTrader
				//if (_smartIdOrders.ContainsKey(smartOrderId))
				//{
				// замечены SystemCancel приходящие в процессе Move после которых приходит Active
				if (state != SmartOrderState.SystemCancel)
				{
					//var trId = GetTransactionBySmartId(smartOrderId);

					SendOutMessage(new ExecutionMessage
					{
						ExecutionType = ExecutionTypes.Order,
						OriginalTransactionId = transactionId,
						OrderStringId = smartOrderId,
						ServerTime = time.ApplyTimeZone(TimeHelper.Moscow),
						OrderState = OrderStates.Failed,
						Error = new InvalidOperationException(LocalizedStrings.Str1873Params.Put(transactionId)),
					});
				}
				//}

				return;
			}

			var orderType = smartType.ToOrderType();

			var orderState = OrderStates.Active;
			var orderStatus = OrderStatus.Accepted;

			switch (state)
			{
				case SmartOrderState.ContragentReject:
					orderStatus = OrderStatus.NotAcceptedByManager;
					orderState = OrderStates.Failed;
					break;
				// Принята ТС
				case SmartOrderState.Submited:
					orderStatus = OrderStatus.SentToServer;
					break;
				// Зарегистрирована в ТС
				case SmartOrderState.Pending:
					orderStatus = OrderStatus.ReceiveByServer;

					if (orderType == OrderTypes.Conditional)
						orderState = OrderStates.Active;

					break;
				// Выведена на рынок
				case SmartOrderState.Open:
					orderStatus = OrderStatus.Accepted;

					if (orderType == OrderTypes.Conditional && orderId != 0)
						orderState = OrderStates.Done;
					else
						orderState = OrderStates.Active;
					break;
				// Снята по окончанию торгового дня
				case SmartOrderState.Expired:
					orderState = OrderStates.Done;
					break;
				// Отменёна
				case SmartOrderState.Cancel:
					orderState = OrderStates.Done;
					break;
				// Исполнена
				case SmartOrderState.Filled:
					orderState = OrderStates.Done;
					break;
				// Частично исполнена
				case SmartOrderState.Partial:
					if (orderState == OrderStates.None)
						orderState = OrderStates.Active;
					break;
				// Отклонена биржей
				case SmartOrderState.ContragentCancel:
					orderStatus = OrderStatus.CanceledByManager;
					orderState = OrderStates.Failed;
					break;
				// Отклонена биржей
				case SmartOrderState.SystemReject:
					orderStatus = OrderStatus.NotDone;
					orderState = OrderStates.Failed;
					break;
				// Отклонена биржей
				case SmartOrderState.SystemCancel:
					orderStatus = OrderStatus.GateError;
					orderState = OrderStates.Failed;
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}

			SendOutMessage(new ExecutionMessage
			{
				SecurityId = new SecurityId { Native = secSmartId },
				PortfolioName = portfolioName,
				Side = (Sides)side,
				OrderPrice = price ?? 0,
				Volume = volume,
				ServerTime = time.ApplyTimeZone(TimeHelper.Moscow),
				Balance = balance,
				OrderId = orderId == 0 ? (long?)null : orderId,
				OrderType = orderType,
				OrderState = orderState,
				OrderStatus = orderStatus,
				OriginalTransactionId = transactionId,
				OrderStringId = smartOrderId,
				ExpiryDate = isOneDay ? DateTimeOffset.Now.Date.ApplyTimeZone(TimeHelper.Moscow) : (DateTimeOffset?)null,
				Condition = orderType == OrderTypes.Conditional ? new SmartComOrderCondition { StopPrice = stop } : null,
				ExecutionType = ExecutionTypes.Order,
			});
		}