コード例 #1
0
 void ICGateStreamCallback.RegisterStream(CGateStream stream)
 {
     lock (_streamStatesLock)
     {
         _streamStates[stream] = false;
     }
 }
コード例 #2
0
ファイル: CGatePublisher.cs プロジェクト: ralex1975/Polygon
        public override void Dispose()
        {
            if (!_configuredWell)
            {
                return;
            }

            _disposed = true;

            if (_stream != null)
            {
                _stream.Dispose();
                _stream = null;
            }

            if (_publisher != null)
            {
                _publisher.Dispose();
                _publisher = null;
            }
        }
コード例 #3
0
        void ICGateStreamCallback.HandleMessage(CGateStream stream, CGateMessage message)
        {
            lock (_streamStatesLock)
            {
                _currentState         = _streamStates.All(_ => _.Value);
                _streamStates[stream] = stream.State == State.Active;
                _newState             = _streamStates.All(_ => _.Value);
            }

            if (_newState != _currentState)
            {
                UpdateConnectionState(_newState ? CGConnectionState.Connected : CGConnectionState.Disconnected);
            }

            switch (stream.StreamType)
            {
            case CGateStreamType.FutInfo:
            case CGateStreamType.OptInfo:
                PutMessageToBothEventQueues(message);
                break;

            case CGateStreamType.FortsMessages:
            case CGateStreamType.OrdLogTrades:
            case CGateStreamType.FutTrades:
            case CGateStreamType.OptTrades:
            case CGateStreamType.Pos:
            case CGateStreamType.Part:
            case CGateStreamType.Vm:
                PutMessageToTransactionalEventQueue(message);
                break;

            default:
                PutMessageToMarketdataEventQueue(message);
                break;
            }
        }
コード例 #4
0
ファイル: CGatePublisher.cs プロジェクト: ralex1975/Polygon
        public CGatePublisher(
            string name,
            string schemeFileName,
            string schemeName,
            IMessageConverter converter,
            ICGateStreamCallback callback,
            ICGateLogger logger)
        {
            _logger = logger;

            Name           = name;
            SchemeFileName = schemeFileName;
            SchemeName     = schemeName;

            if (!File.Exists(schemeFileName))
            {
                _logger.Error($"File {schemeFileName} doesn't exist, publisher {Name} won't be started");
                _configuredWell = false;
                return;
            }

            _stream         = new CGateStream(Name, CGateStreamType.FortsMessages, converter, callback, _logger);
            _configuredWell = true;
        }
コード例 #5
0
        /// <summary>
        ///     Конструктор
        /// </summary>
        public CGP2ClientAdapter(
            CGAdapterConfiguration configuration,
            string workingDirectory    = @"cgate",
            bool openOrderBooksStreams = true,
            bool openVolatStream       = true,
            bool openHeartbeatStream   = true)
        {
            _configuration    = configuration;
            _workingDirectory = workingDirectory;

            configuration.Logger.Debug("Creating CGAdapter: ip={0}, port={1}, ini_folder={2}", configuration.Address, configuration.Port, configuration.IniFolder);

            var futInfoStream = new CGateStream(
                name: "FORTS_FUTINFO_REPL",
                streamType: CGateStreamType.FutInfo,
                schemeFileName: $"{configuration.IniFolder}fut_info.ini",
                schemeName: "CustReplScheme",
                converter: new Messages.FutInfo.StreamDataMessageConverter(),
                callback: this,
                logger: configuration.Logger);
            var optInfoStream = new CGateStream(
                name: "FORTS_OPTINFO_REPL",
                streamType: CGateStreamType.OptInfo,
                schemeFileName: $"{configuration.IniFolder}opt_info.ini",
                schemeName: "CustReplScheme",
                converter: new Messages.OptInfo.StreamDataMessageConverter(),
                callback: this,
                logger: configuration.Logger);

            #region data connection
            {
                var firstSubconnections  = new[] { futInfoStream, optInfoStream };
                var secondSubconnections = new[]
                {
                    openHeartbeatStream
                        ? new CGateStream(
                        name: "FORTS_FUTTRADE_REPL",
                        streamType: CGateStreamType.FutTrades,
                        schemeFileName: $"{configuration.IniFolder}fut_trades_heartbeat.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.FutTrades.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger,
                        dependOnStreams: null,
                        mode: "online",
                        transactional: true)
                        : null,
                    new CGateStream(
                        name: "FORTS_FUTCOMMON_REPL",
                        streamType: CGateStreamType.FutCommon,
                        schemeFileName: $"{configuration.IniFolder}fut_common.ini",
                        schemeName: "CustReplScheme",
                        converter: new StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger),
                    new CGateStream(
                        name: "FORTS_OPTCOMMON_REPL",
                        streamType: CGateStreamType.OptCommon,
                        schemeFileName: $"{configuration.IniFolder}opt_common.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.OptCommon.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger),
                    new CGateStream(
                        name: "RTS_INDEX_REPL",
                        streamType: CGateStreamType.RtsIndex,
                        schemeFileName: $"{configuration.IniFolder}rts_index.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.RtsIndex.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger),
                    openVolatStream
                        ? new CGateStream(
                        name: "FORTS_VOLAT_REPL",
                        streamType: CGateStreamType.Volat,
                        schemeFileName: $"{configuration.IniFolder}volat.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.Volat.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger)
                        : null,
                    openOrderBooksStreams
                        ? new CGateStream(
                        name: "FORTS_FUTAGGR20_REPL",
                        streamType: CGateStreamType.OrdersAggr,
                        schemeFileName: $"{configuration.IniFolder}orders_aggr.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.OrdersAggr.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger,
                        dependOnStreams: null,
                        mode: "online",
                        useReplStateWhenReconnect: false)
                        : null,
                    openOrderBooksStreams
                        ? new CGateStream(
                        name: "FORTS_OPTAGGR20_REPL",
                        streamType: CGateStreamType.OrdersAggr,
                        schemeFileName: $"{configuration.IniFolder}orders_aggr.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.OrdersAggr.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger,
                        dependOnStreams: null,
                        mode: "online",
                        useReplStateWhenReconnect: false)
                        : null
                };

                _dataConnection = new CGateConnection(
                    name: "CG_DATA_CONN",
                    ip: configuration.Address,
                    port: configuration.Port,
                    credential: configuration.DataConnectionCredential,
                    firstSubconnections: firstSubconnections,
                    secondSubconnections: secondSubconnections,
                    logger: configuration.Logger,
                    callback: this);
            }

            #endregion

            #region transaction connection

            {
                _ordersPublisher = new CGatePublisher(
                    name: "CG_ORDS_SNDR",
                    schemeFileName: $"{configuration.IniFolder}forts_messages.ini",
                    schemeName: "message",
                    converter: new Messages.FortsMessages.StreamDataMessageConverter(),
                    callback: this,
                    logger: configuration.Logger);

                var firstSubconnections = new CGateSubconnection[]
                {
                    _ordersPublisher,
                    new CGateStream(
                        name: "FORTS_FUTTRADE_REPL",
                        streamType: CGateStreamType.FutTrades,
                        schemeFileName: $"{configuration.IniFolder}fut_trades.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.FutTrades.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger,
                        dependOnStreams: new[] { futInfoStream, optInfoStream }, transactional: true),
                    new CGateStream(name: "FORTS_OPTTRADE_REPL",
                                    streamType: CGateStreamType.OptTrades,
                                    schemeFileName: $"{configuration.IniFolder}opt_trades.ini",
                                    schemeName: "CustReplScheme",
                                    converter: new Messages.OptTrades.StreamDataMessageConverter(),
                                    callback: this,
                                    logger: configuration.Logger,
                                    dependOnStreams: new[] { futInfoStream, optInfoStream }, transactional: true),
                    new CGateStream(
                        name: "FORTS_POS_REPL",
                        streamType: CGateStreamType.Pos,
                        schemeFileName: $"{configuration.IniFolder}pos.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.Pos.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger,
                        dependOnStreams: new[] { futInfoStream, optInfoStream }, transactional: true),
                    new CGateStream(
                        name: "FORTS_PART_REPL",
                        streamType: CGateStreamType.Part,
                        schemeFileName: $"{configuration.IniFolder}part.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.Part.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger,
                        dependOnStreams: new[] { futInfoStream, optInfoStream }, transactional: true),
                    new CGateStream(
                        name: "FORTS_VM_REPL",
                        streamType: CGateStreamType.Vm,
                        schemeFileName: $"{configuration.IniFolder}vm.ini",
                        schemeName: "CustReplScheme",
                        converter: new Messages.Vm.StreamDataMessageConverter(),
                        callback: this,
                        logger: configuration.Logger,
                        dependOnStreams: new[] { futInfoStream, optInfoStream }, transactional: true),
                };

                _transactionConnection = new CGateConnection(
                    "CG_TRNS_CONN",
                    configuration.Address,
                    configuration.Port,
                    configuration.TransactionConnectionCredential,
                    firstSubconnections,
                    null,
                    configuration.Logger,
                    this);
            }

            #endregion
        }