Beispiel #1
0
        /// <summary>
        /// Create a copy of <see cref="PortfolioLookupMessage"/>.
        /// </summary>
        /// <returns>Copy.</returns>
        public override Message Clone()
        {
            var clone = new PortfolioLookupMessage();

            CopyTo(clone);
            return(clone);
        }
        /// <summary>
        /// Copy the message into the <paramref name="destination" />.
        /// </summary>
        /// <param name="destination">The object, to which copied information.</param>
        protected virtual void CopyTo(PortfolioLookupMessage destination)
        {
            base.CopyTo(destination);

            destination.SecurityId = SecurityId;
            destination.StrategyId = StrategyId;
        }
        /// <summary>
        /// Create a copy of <see cref="PortfolioLookupMessage"/>.
        /// </summary>
        /// <returns>Copy.</returns>
        public override Message Clone()
        {
            var clone = new PortfolioLookupMessage {
                SecurityId = SecurityId
            };

            CopyTo(clone);
            return(clone);
        }
		private void ProcessPortolioLookupMessage(PortfolioLookupMessage pfMsg)
		{
			if (_lookupPortfoliosId == 0)
			{
				_lookupPortfoliosId = pfMsg.TransactionId;
				_wrapper.LookupPortfolios();
			}
			else
				SendOutError(LocalizedStrings.Str1868);
		}
		//private static string GetOECAccountName(string localPortfolioName)
		//{
		//	return localPortfolioName.Split(new[] { '-' })[0];
		//}

		private void ProcessPortfolioLookupMessage(PortfolioLookupMessage message)
		{
			foreach (var account in _client.Accounts)
			{
				ProcessAccount(account, null);

				foreach (var list in account.DetailedPositions)
				{
					foreach (var position in list)
						ProcessPosition(position);
				}
			}

			SendOutMessage(new PortfolioLookupResultMessage { OriginalTransactionId = message.TransactionId });
		}
		private void ProcessPortfolioLookup(PortfolioLookupMessage message)
		{
			//SendOutMessage(new PortfolioMessage
			//{
			//	PortfolioName = GetPortfolioName()
			//});

			ProcessBalance(_httpClient.RequestBalance());

			if (message != null)
				SendOutMessage(new PortfolioLookupResultMessage { OriginalTransactionId = message.TransactionId });
		}
		private void ProcessPortfolioLookupMessage(PortfolioLookupMessage message)
		{
			var portfolios = _client.GetPortfolios();

			foreach (var portfolio in portfolios)
			{
				SendOutMessage(new PortfolioMessage
				{
					PortfolioName = portfolio.bstrAcct,
					State = PortfolioStates.Active, // ???
					OriginalTransactionId = message.TransactionId,
				});
			}

			var pos = _client.GetPositions();

			foreach (var position in pos)
			{
				var m = new PositionMessage
				{
					PortfolioName = position.bstrAcct,
					SecurityId = new SecurityId { SecurityCode = position.bstrSym, BoardCode = AssociatedBoardCode, SecurityType = position.bstrInstrument.ToSecurityType() },
					OriginalTransactionId = message.TransactionId,
				};

				SendOutMessage(m);

				var changeMsg = new PositionChangeMessage
				{
					PortfolioName = position.bstrAcct,
					SecurityId = new SecurityId { SecurityCode = position.bstrSym, BoardCode = AssociatedBoardCode, SecurityType = position.bstrInstrument.ToSecurityType() },
					ServerTime = CurrentTime
				};

				changeMsg.TryAdd(PositionChangeTypes.RealizedPnL, (decimal)position.fReal);
				changeMsg.TryAdd(PositionChangeTypes.BeginValue, (decimal)position.nOpeningPosition);
				changeMsg.TryAdd(PositionChangeTypes.CurrentValue, (decimal)(position.nOpeningPosition + (position.nSharesBot - position.nSharesSld)));
				changeMsg.TryAdd(PositionChangeTypes.Commission, (decimal)position.fPositionCost);

				SendOutMessage(message);
			}

			SendOutMessage(new PortfolioLookupResultMessage { OriginalTransactionId = message.TransactionId });
		}
		private void ProcessPortfolioLookup(PortfolioLookupMessage message)
		{
			var reply = _client.GetInfo();
			ProcessFunds(reply.State.Funds);

			SendOutMessage(new PortfolioMessage
			{
				PortfolioName = GetPortfolioName(),
				State = reply.State.Rights.CanTrade ? PortfolioStates.Active : PortfolioStates.Blocked,
				OriginalTransactionId = message == null ? 0 : message.TransactionId
			});

			if (message != null)
				SendOutMessage(new PortfolioLookupResultMessage { OriginalTransactionId = message.TransactionId });
		}
		private void ProcessPortfolioLookupMessage(PortfolioLookupMessage message)
		{
			foreach (var account in _restClient.GetAccounts())
			{
				_accountIds[account.Name] = account.Id;

				SendOutMessage(new PortfolioMessage
				{
					PortfolioName = account.Name,
					Currency = account.Currency.To<CurrencyTypes>(),
				});

				var details = _restClient.GetAccountDetails(account.Id);

				SendOutMessage(new PortfolioChangeMessage { PortfolioName = account.Name }
					.TryAdd(PositionChangeTypes.RealizedPnL, (decimal)details.RealizedPnL)
					.TryAdd(PositionChangeTypes.UnrealizedPnL, (decimal)details.UnrealizedPnL)
					.TryAdd(PositionChangeTypes.CurrentPrice, (decimal)details.Balance)
					.TryAdd(PositionChangeTypes.BlockedValue, (decimal)details.MarginUsed)
					.TryAdd(PositionChangeTypes.CurrentValue, (decimal)details.MarginAvailable));

				foreach (var position in _restClient.GetPositions(account.Id))
				{
					SendOutMessage(new PositionChangeMessage
					{
						PortfolioName = account.Name,
						SecurityId = position.Instrument.ToSecurityId(),
					}
					.TryAdd(PositionChangeTypes.CurrentValue, (decimal)(position.Side.To<Sides>() == Sides.Buy ? position.Units : -position.Units))
					.TryAdd(PositionChangeTypes.AveragePrice, (decimal)position.AveragePrice));		
				}
			}

			SendOutMessage(new PortfolioLookupResultMessage { OriginalTransactionId = message.TransactionId });
		}