コード例 #1
0
        private void OnConnectorPositionReceived(Subscription subscription, Position position)
        {
            if (_pfSubscription != subscription)
            {
                return;
            }

            if (position.StrategyId != EnsureGetId())
            {
                this.AddWarningLog("Position {0} has StrategyId '{1}' instead of '{2}'.", position, position.StrategyId, EnsureGetId());
                return;
            }

            _positions.SafeAdd(CreateKey(position.Security, position.Portfolio), k => position, out var isNew);

            if (isNew)
            {
                _newPosition?.Invoke(position);
            }
            else
            {
                _positionChanged?.Invoke(position);
            }

            RaisePositionChanged();

            PositionReceived?.Invoke(subscription, position);
        }
コード例 #2
0
        private void ProcessPositionChangeMessage(PositionChangeMessage message)
        {
            if (Connector.KeepStrategiesPositions)
            {
                return;
            }

            if (message.StrategyId != EnsureGetId())
            {
                return;
            }

            var connector = SafeGetConnector();

            var security  = connector.LookupById(message.SecurityId);
            var portfolio = connector.LookupByPortfolioName(message.PortfolioName);

            var position = _positions.SafeAdd(CreateKey(security, portfolio), k => new Position
            {
                Security   = security,
                Portfolio  = portfolio,
                StrategyId = message.StrategyId,
            }, out var isNew);

            position.ApplyChanges(message);

            if (isNew)
            {
                _newPosition?.Invoke(position);
            }
            else
            {
                _positionChanged?.Invoke(position);
            }

            RaisePositionChanged();

            foreach (var id in message.GetSubscriptionIds())
            {
                if (_subscriptionsById.TryGetValue(id, out var subscription))
                {
                    PositionReceived?.Invoke(subscription, position);
                }
            }
        }
コード例 #3
0
ファイル: SimConnectAdapter.cs プロジェクト: lyldz/fs2ff
        private async void SimConnect_OnRecvSimobjectData(SimConnectImpl sender, SIMCONNECT_RECV_SIMOBJECT_DATA data)
        {
            if (data.dwRequestID == (uint)REQUEST.Position &&
                data.dwDefineID == (uint)DEFINITION.Position &&
                data.dwData?.FirstOrDefault() is Position pos)
            {
                await PositionReceived.RaiseAsync(pos).ConfigureAwait(false);
            }

            if (data.dwRequestID == (uint)REQUEST.Attitude &&
                data.dwDefineID == (uint)DEFINITION.Attitude &&
                data.dwData?.FirstOrDefault() is Attitude att)
            {
                await AttitudeReceived.RaiseAsync(att).ConfigureAwait(false);
            }

            if (data.dwRequestID == (uint)REQUEST.TrafficObjectBase + data.dwObjectID &&
                data.dwDefineID == (uint)DEFINITION.Traffic &&
                data.dwObjectID != SimConnectImpl.SIMCONNECT_OBJECT_ID_USER &&
                data.dwData?.FirstOrDefault() is Traffic tfk)
            {
                await TrafficReceived.RaiseAsync(tfk, data.dwObjectID).ConfigureAwait(false);
            }
        }
コード例 #4
0
ファイル: XSpi.cs プロジェクト: zhuzhenping/QuantBoxXProvider
 void IXSpi.ProcessQryPosition(PositionField position, bool last)
 {
     PositionReceived?.Invoke(this, position, last);
 }