/// <summary>
		/// Создать копию объекта <see cref="OrderReplaceMessage"/>.
		/// </summary>
		/// <returns>Копия.</returns>
		public override Message Clone()
		{
			var clone = new OrderReplaceMessage
			{
				Comment = Comment,
				Condition = Condition,
				TillDate = TillDate,
				OrderType = OrderType,
				PortfolioName = PortfolioName,
				Price = Price,
				RepoInfo = RepoInfo,
				RpsInfo = RpsInfo,
				SecurityId = SecurityId,
				Side = Side,
				TimeInForce = TimeInForce,
				TransactionId = TransactionId,
				VisibleVolume = VisibleVolume,
				Volume = Volume,
				OldOrderId = OldOrderId,
				OldOrderStringId = OldOrderStringId,
				OldTransactionId = OldTransactionId,
				UserOrderId = UserOrderId,
				ClientCode = ClientCode,
				BrokerCode = BrokerCode,
			};

			CopyTo(clone);

			return clone;
		}
		private void ProcessOrderReplaceMessage(OrderReplaceMessage replaceMsg)
		{
			var condition = (SterlingOrderCondition)replaceMsg.Condition;

			var replaceOrder = new STIOrder
			{
				Account = replaceMsg.PortfolioName, 
				Quantity = (int) replaceMsg.Volume,
				Display = (int)(replaceMsg.VisibleVolume ?? replaceMsg.Volume), 
				ClOrderID = replaceMsg.TransactionId.To<string>(), 
				LmtPrice = (double) replaceMsg.Price, 
				Symbol = replaceMsg.SecurityId.SecurityCode, 
				Destination = replaceMsg.SecurityId.BoardCode, 
				Tif = replaceMsg.TimeInForce.ToSterlingTif(replaceMsg.TillDate), 
				PriceType = replaceMsg.OrderType.ToSterlingPriceType(condition), 
				User = replaceMsg.Comment
			};

			if (replaceMsg.TillDate != null && replaceMsg.TillDate != DateTimeOffset.MaxValue)
				replaceOrder.EndTime = replaceMsg.TillDate.Value.ToString("yyyyMMdd");

			if (replaceMsg.Currency != null)
				replaceOrder.Currency = replaceMsg.Currency.ToString();

			replaceOrder.ReplaceOrder(0, replaceMsg.OldTransactionId.To<string>());
		}
Example #3
0
        /// <summary>
        /// Создать копию объекта <see cref="OrderReplaceMessage"/>.
        /// </summary>
        /// <returns>Копия.</returns>
        public override Message Clone()
        {
            var clone = new OrderReplaceMessage
            {
                Comment          = Comment,
                Condition        = Condition,
                TillDate         = TillDate,
                OrderType        = OrderType,
                PortfolioName    = PortfolioName,
                Price            = Price,
                RepoInfo         = RepoInfo,
                RpsInfo          = RpsInfo,
                SecurityId       = SecurityId,
                Side             = Side,
                TimeInForce      = TimeInForce,
                TransactionId    = TransactionId,
                VisibleVolume    = VisibleVolume,
                Volume           = Volume,
                OldOrderId       = OldOrderId,
                OldOrderStringId = OldOrderStringId,
                OldTransactionId = OldTransactionId,
                UserOrderId      = UserOrderId
            };

            CopyTo(clone);

            return(clone);
        }
Example #4
0
        /// <summary>
        /// Create a copy of <see cref="OrderReplaceMessage"/>.
        /// </summary>
        /// <returns>Copy.</returns>
        public override Message Clone()
        {
            var clone = new OrderReplaceMessage();

            CopyTo(clone);

            return(clone);
        }
Example #5
0
        /// <summary>
        /// Copy the message into the <paramref name="destination" />.
        /// </summary>
        /// <param name="destination">The object, to which copied information.</param>
        public void CopyTo(OrderReplaceMessage destination)
        {
            base.CopyTo(destination);

            destination.OldOrderId       = OldOrderId;
            destination.OldOrderStringId = OldOrderStringId;
            destination.OldOrderPrice    = OldOrderPrice;
            destination.OldOrderVolume   = OldOrderVolume;
        }
Example #6
0
        /// <summary>
        /// Create a copy of <see cref="OrderReplaceMessage"/>.
        /// </summary>
        /// <returns>Copy.</returns>
        public override Message Clone()
        {
            var clone = new OrderReplaceMessage
            {
                OldOrderId       = OldOrderId,
                OldOrderStringId = OldOrderStringId,
            };

            CopyTo(clone);

            return(clone);
        }
Example #7
0
 /// <summary>
 /// Преобразовать <see cref="OrderReplaceMessage"/> в <see cref="ExecutionMessage"/>.
 /// </summary>
 /// <param name="message"><see cref="OrderReplaceMessage"/></param>
 /// <returns><see cref="ExecutionMessage"/></returns>
 public static ExecutionMessage ToExecutionMessage(this OrderReplaceMessage message)
 {
     return(new ExecutionMessage
     {
         SecurityId = message.SecurityId,
         OriginalTransactionId = message.TransactionId,
         OrderType = message.OrderType,
         Price = message.Price,
         Volume = message.Volume,
         Side = message.Side,
         PortfolioName = message.PortfolioName,
         ExecutionType = ExecutionTypes.Order,
         Condition = message.Condition,
         UserOrderId = message.UserOrderId,
     });
 }
		private void SendReplaceOrderError(OrderReplaceMessage replaceMessage, Exception error)
		{
			SendOutMessage(new ExecutionMessage
			{
				SecurityId = replaceMessage.SecurityId,
				OriginalTransactionId = replaceMessage.OldTransactionId,
				OrderId = replaceMessage.OldOrderId,
				ExecutionType = ExecutionTypes.Order,
				OrderState = OrderStates.Failed,
				IsCancelled = true,
				Error = error
			});

			SendOutMessage(new ExecutionMessage
			{
				SecurityId = replaceMessage.SecurityId,
				OriginalTransactionId = replaceMessage.TransactionId,
				ExecutionType = ExecutionTypes.Order,
				OrderState = OrderStates.Failed,
				Error = error
			});
		}
		private void SendReplaceOrderError(OrderReplaceMessage replaceMessage, Exception error)
		{
			SendOutMessage(new ExecutionMessage
			{
				SecurityId = replaceMessage.SecurityId,
				OriginalTransactionId = replaceMessage.TransactionId,
				//OrderId = replaceMessage.OldOrderId,
				ExecutionType = ExecutionTypes.Transaction,
				OrderState = OrderStates.Failed,
				//IsCancelled = true,
				Error = error,
				HasOrderInfo = true,
				ServerTime = CurrentTime,
			});

			//SendOutMessage(new ExecutionMessage
			//{
			//	SecurityId = replaceMessage.SecurityId,
			//	OriginalTransactionId = replaceMessage.TransactionId,
			//	ExecutionType = ExecutionTypes.Transaction,
			//	OrderState = OrderStates.Failed,
			//	Error = error,
			//	HasOrderInfo = true,
			//	ServerTime = CurrentTime,
			//});
		}
		private void ProcessReplaceMessage(OrderReplaceMessage replaceMsg)
		{
			//this.AddOrderInfoLog(newOrder, "ReRegisterOrder", () => "ReRegisterOrder(FORTS), old tid={0}, id={1}, sid={2}".Put(oldOrder.TransactionId, oldOrder.Id, oldOrder.GetSmartId()));

			_wrapper.ReRegisterOrder(replaceMsg.PortfolioName, (double)replaceMsg.Price, replaceMsg.OldOrderStringId);
		}
		private void ProcessOrderReplaceMessage(OrderReplaceMessage message)
		{
			var condition = (OandaOrderCondition)message.Condition;

			if (message.OldOrderId == null)
				throw new InvalidOperationException(LocalizedStrings.Str2252Params.Put(message.OldTransactionId));

			var response = _restClient.ModifyOrder(GetAccountId(message.PortfolioName),
				message.OldOrderId.Value,
				(int)message.Volume,
				GetExpiryTime(message),
				message.Price,
				condition == null ? null : condition.LowerBound,
				condition == null ? null : condition.UpperBound,
				condition == null ? null : condition.StopLossOffset,
				condition == null ? null : condition.TakeProfitOffset,
				condition == null ? null : condition.TrailingStopLossOffset);

			SendOutMessage(new ExecutionMessage
			{
				ExecutionType = ExecutionTypes.Order,
				OriginalTransactionId = message.TransactionId,
				OrderId = message.OldOrderId,
				OrderState = OrderStates.Done,
				ServerTime = response.Time.FromOanda(),
				PortfolioName = message.PortfolioName,
			});

			SendOutMessage(new ExecutionMessage
			{
				ExecutionType = ExecutionTypes.Order,
				OriginalTransactionId = message.TransactionId,
				OrderId = response.Id,
				OrderState = OrderStates.Active,
				ServerTime = response.Time.FromOanda(),
				PortfolioName = message.PortfolioName,
			});
		}
		private void ProcessReplaceMessage(OrderReplaceMessage replaceMsg)
		{
			var id = _orders.TryGetKey(replaceMsg.OldTransactionId);

			if (id == 0)
				throw new InvalidOperationException(LocalizedStrings.Str3551Params.Put(replaceMsg.OldTransactionId));

			var result = SendCommand(new MoveOrderMessage
			{
				TransactionId = id,
				Price = replaceMsg.Price,
				Quantity = (int)replaceMsg.Volume,
				MoveFlag = replaceMsg.Volume == 0 ? MoveOrderFlag.ChangeQuantity : MoveOrderFlag.DontChangeQuantity,
			});

			_orders.Add(result.TransactionId, replaceMsg.TransactionId);
			_ordersTypes.Add(replaceMsg.TransactionId, OrderTypes.Limit);
		}
		private void ProcessOrderReplace(OrderReplaceMessage message)
		{
			var draft = _client.CreateDraft(_orderTransactions[message.OldTransactionId]);

			draft.Price = (double)message.Price;
			draft.Quantity = (int)message.Volume;

			var invalid = draft.GetInvalidParts();
			if (invalid != OrderParts.None)
				throw new OpenECryException(LocalizedStrings.Str2556Params.Put(invalid));

			var newOrder = _client.ModifyOrder(draft);
			_orderTransactions.Add(newOrder, message.TransactionId);
			ProcessOrder(newOrder, message.TransactionId);
		}
		private ModifyOrderParams FillModifyOrderParams(ModifyOrderParams orderParams, OrderReplaceMessage replaceMsg)
		{
			orderParams.Symbol = replaceMsg.SecurityId.SecurityCode;
			orderParams.Exchange = replaceMsg.SecurityId.BoardCode;
			orderParams.Account = _accounts[replaceMsg.PortfolioName];
			orderParams.UserMsg = replaceMsg.Comment;
			//orderParams.UserTag = replaceMsg.UserOrderId;
			orderParams.Qty = (int)replaceMsg.Volume;
			orderParams.EntryType = Constants.ORDER_ENTRY_TYPE_AUTO;
			orderParams.OrderNum = replaceMsg.OldOrderStringId;

			return orderParams;
		}
		private void ProcessReplaceMessage(OrderReplaceMessage replaceMsg)
		{
			ModifyOrderParams orderParams;

			switch (replaceMsg.OrderType)
			{
				case OrderTypes.Limit:
				{
					orderParams = FillModifyOrderParams(new ModifyOrderParams
					{
						Price = (double)replaceMsg.Price,
						OrderType = Constants.ORDER_TYPE_LIMIT,
					}, replaceMsg);

					break;
				}

				case OrderTypes.Conditional:
				{
					var condition = (RithmicOrderCondition)replaceMsg.Condition;

					var triggerPrice = condition.TriggerPrice;

					if (triggerPrice == null)
						throw new InvalidOperationException(LocalizedStrings.Str3494Params.Put(replaceMsg.TransactionId));

					if (replaceMsg.Price == 0)
					{
						orderParams = FillModifyOrderParams(new ModifyOrderParams
						{
							TriggerPrice = (double)triggerPrice,
							OrderType = Constants.ORDER_TYPE_STOP_MARKET,
						}, replaceMsg);
					}
					else
					{
						orderParams = FillModifyOrderParams(new ModifyOrderParams
						{
							Price = (double)replaceMsg.Price,
							TriggerPrice = (double)triggerPrice,
							OrderType = Constants.ORDER_TYPE_STOP_LIMIT,
						}, replaceMsg);
					}

					break;
				}

				case OrderTypes.Market:
				case OrderTypes.Repo:
				case OrderTypes.ExtRepo:
				case OrderTypes.Rps:
				case OrderTypes.Execute:
					throw new NotSupportedException(LocalizedStrings.Str3495Params.Put(replaceMsg.TransactionId, replaceMsg.OrderType));
				default:
					throw new ArgumentOutOfRangeException();
			}

			_client.Session.modifyOrderList(new List<ModifyOrderParams> { orderParams }.AsReadOnly());
		}