예제 #1
0
		public ClosePositionCommand(Position position)
		{
			if (position == null)
				throw new ArgumentNullException("position");

			Position = position;
		}
예제 #2
0
		public RevertPositionCommand(Position position)
		{
			if (position == null)
				throw new ArgumentNullException(nameof(position));

			Position = position;
		}
예제 #3
0
		/// <summary>
		/// To copy fields of the current position to <paramref name="destination" />.
		/// </summary>
		/// <param name="destination">The position in which you should to copy fields.</param>
		public void CopyTo(Position destination)
		{
			base.CopyTo(destination);

			destination.Portfolio = Portfolio;
			destination.Security = Security;
			destination.DepoName = DepoName;
			destination.LimitType = LimitType;
		}
예제 #4
0
		public PositionCommand(DateTimeOffset time, Position position, bool isNew)
		{
			if (position == null)
				throw new ArgumentNullException("position" +
												"");
			Time = time;
			Position = position;
			IsNew = isNew;
		}
예제 #5
0
		private void ClosePosition(Position position, decimal volume)
		{
			var side = position.CurrentValue > 0 ? Sides.Sell : Sides.Buy;
			var security = position.Security;

			var order = new Order
			{
				Security = security,
				Portfolio = position.Portfolio,
				Direction = side,
				Volume = volume,
				Type = position.Portfolio.Board.IsSupportMarketOrders ? OrderTypes.Market : OrderTypes.Limit,
			};

			if (order.Type == OrderTypes.Limit)
				order.Price = security.GetMarketPrice(SafeGetConnector(), side) ?? 0;

			RegisterOrder(order);
		}
예제 #6
0
		private void OnStrategyNewPosition(Position position)
		{
			PositionGrid.Positions.Add(position);
		}
예제 #7
0
		private void RaisePositionChanged(Position position)
		{
			PositionChanged.SafeInvoke(position);

			var multiEvt = PositionsChanged;

			if (multiEvt == null)
				return;

			multiEvt.SafeInvoke(new[] { position });
		}
예제 #8
0
		private void RaiseNewPosition(Position position)
		{
			NewPosition.SafeInvoke(position);

			var multiEvt = NewPositions;

			if (multiEvt == null)
				return;

			multiEvt.SafeInvoke(new[] { position });
		}
예제 #9
0
		/// <summary>
		/// Create a copy of <see cref="Position"/>.
		/// </summary>
		/// <returns>Copy.</returns>
		public Position Clone()
		{
			var clone = new Position();
			CopyTo(clone);
			return clone;
		}
예제 #10
0
		private void ClosePosition(Position position, decimal vol)
		{
			if(position.CurrentValue == 0)
				return;

			var side = position.CurrentValue > 0 ? Sides.Sell : Sides.Buy;
			var security = position.Security;
			var supportMarket = position.Portfolio.Board?.IsSupportMarketOrders ?? false;

			var order = new Order
			{
				Security = security,
				Portfolio = position.Portfolio,
				Direction = side,
				Volume = vol,
				Type = supportMarket ? OrderTypes.Market : OrderTypes.Limit,
			};

			if (order.Type == OrderTypes.Limit)
			{
				order.Price = security.GetMarketPrice(_connector, side) ?? 0;

				if (order.Price == 0)
				{
					OnErrorEvent("Unable to determine market price!", "Error");
					return;
				}
			}

			_connector.RegisterOrder(order);
		}
예제 #11
0
        // возвращает строку позиции
		private static string PositionToString(Position position)
        {
            return "{0};{1};{2};{3}".Put(
                                position.Security.Id,
                                position.Portfolio.Name,
                                position.CurrentValue,
                                position.AveragePrice);
        }