private void ProcessPositionChangeMessage(PositionChangeMessage message)
		{
			var security = LookupSecurity(message.SecurityId);
			var portfolio = GetPortfolio(message.PortfolioName);

			var valueInLots = message.Changes.TryGetValue(PositionChangeTypes.CurrentValueInLots);
			if (valueInLots != null)
			{
				if (!message.Changes.ContainsKey(PositionChangeTypes.CurrentValue))
				{
					var currValue = (decimal)valueInLots / (security.VolumeStep ?? 1);
					message.Add(PositionChangeTypes.CurrentValue, currValue);
				}

				message.Changes.Remove(PositionChangeTypes.CurrentValueInLots);
			}

			var position = GetPosition(portfolio, security, message.ClientCode, message.DepoName, message.LimitType, message.Description);
			position.ApplyChanges(message);

			RaisePositionChanged(position);
		}
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override bool?OnRead(IFixReader reader, string msgType, Action <Message> messageHandler)
        {
            switch (msgType)
            {
            // reading custom CFH message (not compatible with FIX standard)
            case CfhFixMessages.AccountInfo:
            {
                string        account     = null;
                var           sendingTime = default(DateTimeOffset);
                decimal?      closedPnL   = null;
                decimal?      openPnL     = null;
                decimal?      balance     = null;
                CurrencyTypes?currency    = null;

                var isOk = reader.ReadMessage(tag =>
                    {
                        switch (tag)
                        {
                        case FixTags.Account:
                            account = reader.ReadString();
                            return(true);

                        case FixTags.SendingTime:
                            sendingTime = reader.ReadUtc(TimeStampParser);
                            return(true);

                        case CfhFixTags.ClosedPnL:
                            closedPnL = reader.ReadDecimal();
                            return(true);

                        case CfhFixTags.OpenPnL:
                            openPnL = reader.ReadDecimal();
                            return(true);

                        case CfhFixTags.Balance:
                            balance = reader.ReadDecimal();
                            return(true);

                        case FixTags.Currency:
                            currency = reader.ReadString().FromMicexCurrencyName(this.AddErrorLog);
                            return(true);

                        default:
                            return(false);
                        }
                    });

                if (!isOk)
                {
                    return(null);
                }

                var msg = new PositionChangeMessage
                {
                    SecurityId    = SecurityId.Money,
                    PortfolioName = account,
                    ServerTime    = sendingTime
                }
                .TryAdd(PositionChangeTypes.RealizedPnL, closedPnL, true)
                .TryAdd(PositionChangeTypes.UnrealizedPnL, openPnL, true)
                .TryAdd(PositionChangeTypes.CurrentValue, balance, true);

                if (currency != null)
                {
                    msg.Add(PositionChangeTypes.Currency, currency.Value);
                }

                messageHandler(msg);
                return(true);
            }

            default:
                return(base.OnRead(reader, msgType, messageHandler));
            }
        }