Ejemplo n.º 1
0
		private void ProcessTransactionReply(ExecutionMessage orderMessage, Transaction builder, long orderId, string message, Codes replyCode, Exception exception)
		{
			switch (builder.TransactionType)
			{
				case TransactionTypes.Register:
					if (exception != null || orderId == 0)
					{
						if (exception == null)
							exception = new ApiException(replyCode, message);

						SendOrderError(orderMessage, exception);
					}
					else
						TrySendFokOrder(orderMessage, orderId, message);

					break;

				case TransactionTypes.ReRegister:
					if (exception == null)
					{
						orderId = GetReplacedOrderId(orderMessage.OriginalTransactionId, message, out exception);

						if (orderId == 0)
						{
							if (exception == null)
								exception = new ApiException(replyCode, message);

							SendReplaceOrderError((OrderReplaceMessage)builder.Message, exception);
						}
						else
							TrySendFokOrder(orderMessage, orderId, message);
					}
					else
						SendReplaceOrderError((OrderReplaceMessage)builder.Message, exception);

					break;

				case TransactionTypes.Cancel:
					if (exception != null)
					{
						SendOrderError(orderMessage, exception);
					}
					break;

				default:
					throw new NotSupportedException(LocalizedStrings.Str1840Params.Put(builder.TransactionType));
			}
		}
Ejemplo n.º 2
0
		private void OnConnectionStatusCallback(int connectionEvent, int extendedErrorCode, string infoMessage)
		{
			Exception error = null;

			var errorCode = extendedErrorCode.ToCode();

			if (errorCode != Codes.Success)
				error = new ApiException(errorCode, infoMessage);

			ConnectionChanged.SafeInvoke((Codes)connectionEvent, error, infoMessage);
		}
Ejemplo n.º 3
0
		private void OnTransactionReply(uint transactionId, Codes replyCode, Codes extendedCode, OrderStatus status, long orderId, string message)
		{
			this.AddDebugLog("Order: transId {0} replyCode {1} extendedCode {2} status {3} orderId {4} message {5}", transactionId, replyCode, extendedCode, status, orderId, message);

			if (!IsAsyncMode)
				return;

			try
			{
				var builder = _transactions.TryGetValue(transactionId);

				if (builder == null)
					throw new InvalidOperationException(LocalizedStrings.Str1839Params.Put(transactionId));

				if (builder.TransactionType == TransactionTypes.CancelGroup)
				{
					if (replyCode != Codes.Success || status != OrderStatus.Accepted)
						SendOutError(new ApiException(replyCode, message));

					return;
				}

				if (builder.TransactionType == TransactionTypes.Register && extendedCode == Codes.Success && orderId == 0)
					extendedCode = Codes.Failed;

				var isCancelFailed = builder.TransactionType == TransactionTypes.Cancel && status != OrderStatus.Accepted;

				if (isCancelFailed)
					extendedCode = Codes.Failed;

				ApiException exception = null;

				if (extendedCode != Codes.Success)
					exception = new ApiException(extendedCode, message);

				var orderMessage = builder.Message.ToExecutionMessage();

				orderMessage.SystemComment = message;

				if (!isCancelFailed)
					orderMessage.OrderStatus = status;

				ProcessTransactionReply(orderMessage, builder, orderId, message, replyCode, exception);
			}
			catch (Exception ex)
			{
				SendOutError(ex);
			}
		}