예제 #1
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
        }
예제 #2
0
 void ICGateConnectionCallback.ConnectionOpening(CGateConnection connection)
 {
 }
예제 #3
0
 void ICGateConnectionCallback.ConnectionActive(CGateConnection connection)
 {
     UpdateConnectionState(CGConnectionState.Connected);
 }
예제 #4
0
 void ICGateConnectionCallback.ConnectionError(CGateConnection connection)
 {
 }
예제 #5
0
 void ICGateConnectionCallback.ConnectionClosed(CGateConnection connection)
 {
     UpdateConnectionState(CGConnectionState.Disconnected);
 }
예제 #6
0
 void ICGateConnectionCallback.RegisterConnection(CGateConnection connection)
 {
 }