Exemple #1
0
        /// <summary>
        /// Преобразовать <see cref="OrderMessage"/> в <see cref="ExecutionMessage"/>.
        /// </summary>
        /// <param name="message"><see cref="OrderMessage"/></param>
        /// <returns><see cref="ExecutionMessage"/></returns>
        public static ExecutionMessage ToExecutionMessage(this OrderMessage message)
        {
            switch (message.Type)
            {
            case MessageTypes.OrderRegister:
                return(((OrderRegisterMessage)message).ToExecutionMessage());

            case MessageTypes.OrderCancel:
                return(((OrderCancelMessage)message).ToExecutionMessage());

            case MessageTypes.OrderGroupCancel:
                return(((OrderGroupCancelMessage)message).ToExecutionMessage());

            case MessageTypes.OrderReplace:
                return(((OrderReplaceMessage)message).ToExecutionMessage());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
		private void ProcessOrderMessage(OrderMessage message)
		{
			switch (message.Type)
			{
				case MessageTypes.OrderRegister:
					var regMsg = (OrderRegisterMessage)message;
					RegisterTransaction(regMsg.CreateRegisterTransaction(_depoNames.TryGetValue(regMsg.PortfolioName), _securityClassInfo), message.Type, regMsg.TransactionId, regMsg.OrderType);
					break;

				case MessageTypes.OrderReplace:
					var replMsg = (OrderReplaceMessage)message;
					RegisterTransaction(replMsg.CreateMoveTransaction(_securityClassInfo), message.Type, replMsg.TransactionId, replMsg.OrderType);
					break;

				case MessageTypes.OrderCancel:
					var cancelMsg = (OrderCancelMessage)message;
					RegisterTransaction(cancelMsg.CreateCancelTransaction(_securityClassInfo), message.Type, cancelMsg.TransactionId, cancelMsg.OrderType);
					break;

				case MessageTypes.OrderGroupCancel:
					var cancelGroupMsg = (OrderGroupCancelMessage)message;
					RegisterTransaction(cancelGroupMsg.CreateCancelFuturesTransaction(_securityClassInfo), message.Type, cancelGroupMsg.TransactionId, cancelGroupMsg.OrderType);
					break;

				default:
					throw new ArgumentOutOfRangeException();
			}
		}
		/// <summary>
		/// Convert transaction.
		/// </summary>
		/// <param name="message">Transaction.</param>
		/// <param name="quotesVolume">Order book volume.</param>
		/// <returns>Stream <see cref="ExecutionMessage"/>.</returns>
		public IEnumerable<ExecutionMessage> ToExecutionLog(OrderMessage message, decimal quotesVolume)
		{
			if (message == null)
				throw new ArgumentNullException(nameof(message));

			var serverTime = _getServerTime(message.LocalTime);

			switch (message.Type)
			{
				case MessageTypes.OrderRegister:
				{
					var regMsg = (OrderRegisterMessage)message;

					if (_settings.IncreaseDepthVolume && NeedCheckVolume(regMsg.Side, regMsg.Price) && quotesVolume < regMsg.Volume)
					{
						foreach (var executionMessage in IncreaseDepthVolume(regMsg.LocalTime, serverTime, regMsg.Side, regMsg.Volume - quotesVolume))
							yield return executionMessage;
					}

					yield return new ExecutionMessage
					{
						LocalTime = regMsg.LocalTime,
						ServerTime = serverTime,
						SecurityId = regMsg.SecurityId,
						ExecutionType = ExecutionTypes.Order,
						TransactionId = regMsg.TransactionId,
						OrderPrice = regMsg.Price,
						Volume = regMsg.Volume,
						Side = regMsg.Side,
						PortfolioName = regMsg.PortfolioName,
						OrderType = regMsg.OrderType,
						UserOrderId = regMsg.UserOrderId
					};

					yield break;
				}
				case MessageTypes.OrderReplace:
				{
					var replaceMsg = (OrderReplaceMessage)message;

					if (_settings.IncreaseDepthVolume && NeedCheckVolume(replaceMsg.Side, replaceMsg.Price) && quotesVolume < replaceMsg.Volume)
					{
						foreach (var executionMessage in IncreaseDepthVolume(replaceMsg.LocalTime, serverTime, replaceMsg.Side, replaceMsg.Volume - quotesVolume))
							yield return executionMessage;
					}

					yield return new ExecutionMessage
					{
						LocalTime = replaceMsg.LocalTime,
						ServerTime = serverTime,
						SecurityId = replaceMsg.SecurityId,
						ExecutionType = ExecutionTypes.Order,
						IsCancelled = true,
						OrderId = replaceMsg.OldOrderId,
						OriginalTransactionId = replaceMsg.OldTransactionId,
						TransactionId = replaceMsg.TransactionId,
						PortfolioName = replaceMsg.PortfolioName,
						OrderType = replaceMsg.OrderType,
						// для старой заявки пользовательский идентификатор менять не надо
						//UserOrderId = replaceMsg.UserOrderId
					};

					yield return new ExecutionMessage
					{
						LocalTime = replaceMsg.LocalTime,
						ServerTime = serverTime,
						SecurityId = replaceMsg.SecurityId,
						ExecutionType = ExecutionTypes.Order,
						TransactionId = replaceMsg.TransactionId,
						OrderPrice = replaceMsg.Price,
						Volume = replaceMsg.Volume,
						Side = replaceMsg.Side,
						PortfolioName = replaceMsg.PortfolioName,
						OrderType = replaceMsg.OrderType,
						UserOrderId = replaceMsg.UserOrderId
					};

					yield break;
				}
				case MessageTypes.OrderCancel:
				{
					var cancelMsg = (OrderCancelMessage)message;

					yield return new ExecutionMessage
					{
						ExecutionType = ExecutionTypes.Order,
						IsCancelled = true,
						OrderId = cancelMsg.OrderId,
						TransactionId = cancelMsg.TransactionId,
						OriginalTransactionId = cancelMsg.OrderTransactionId,
						PortfolioName = cancelMsg.PortfolioName,
						SecurityId = cancelMsg.SecurityId,
						LocalTime = cancelMsg.LocalTime,
						ServerTime = serverTime,
						OrderType = cancelMsg.OrderType,
						// при отмене заявки пользовательский идентификатор не меняется
						//UserOrderId = cancelMsg.UserOrderId
					};

					yield break;
				}

				case MessageTypes.OrderPairReplace:
				case MessageTypes.OrderGroupCancel:
					throw new NotSupportedException();

				default:
					throw new ArgumentOutOfRangeException();
			}
		}
		private static Transaction SetSecurity(this Transaction transaction, OrderMessage message, IDictionary<string, RefPair<SecurityTypes, string>> securityClassInfo)
		{
			return
				transaction
					.SetClassCode(securityClassInfo.GetSecurityClass(message.SecurityId))
					.SetSecurityCode(message.SecurityId.SecurityCode);
		}
		private static long GetExpiryTime(OrderMessage message)
		{
			return (message.ExpiryDate ?? DateTime.UtcNow.EndOfDay().ApplyTimeZone(TimeZoneInfo.Utc)).ToOanda();
		}