Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataBusConnected"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        protected DataBusConnected(IComponentryContainer container, IDataBusAdapter dataBusAdapter)
            : base(container)
        {
            this.dataBusAdapter = dataBusAdapter;

            this.RegisterHandler <IEnvelope>(this.OnEnvelope);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublisherDataBus"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="compressor">The data compressor.</param>
        /// <param name="encryption">The encryption configuration.</param>
        /// <param name="networkAddress">The publishers network address.</param>
        protected PublisherDataBus(
            IComponentryContainer container,
            IDataBusAdapter dataBusAdapter,
            ICompressor compressor,
            EncryptionSettings encryption,
            ZmqNetworkAddress networkAddress)
            : base(container, dataBusAdapter)
        {
            this.compressor = compressor;

            this.socket = new PublisherSocket
            {
                Options =
                {
                    Identity = Encoding.UTF8.GetBytes($"{nameof(Nautilus)}-{this.Name.Value}"),
                    Linger   = TimeSpan.FromSeconds(1),
                },
            };

            this.networkAddress = networkAddress;

            if (encryption.UseEncryption)
            {
                EncryptionProvider.SetupSocket(encryption, this.socket);
                this.Logger.LogInformation(LogId.Network, $"{encryption.Algorithm} encryption setup for {this.networkAddress}");
            }
            else
            {
                this.Logger.LogWarning(LogId.Network, $"No encryption setup for {this.networkAddress}");
            }

            this.SentCount = 0;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FixDataGateway"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="fixClient">The FIX client.</param>
        public FixDataGateway(
            IComponentryContainer container,
            IDataBusAdapter dataBusAdapter,
            IFixClient fixClient)
            : base(container, dataBusAdapter)
        {
            this.fixClient = fixClient;

            this.RegisterHandler <ConnectSession>(this.OnMessage);
            this.RegisterHandler <DisconnectSession>(this.OnMessage);
        }
Ejemplo n.º 4
0
 public MockDataPublisher(
     IComponentryContainer container,
     IDataBusAdapter dataBusAdapter,
     EncryptionSettings encryption,
     ZmqNetworkAddress networkAddress)
     : base(
         container,
         dataBusAdapter,
         new BypassCompressor(),
         encryption,
         networkAddress)
 {
     this.RegisterHandler <(string, string)>(this.OnMessage);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates and returns a new FIX gateway.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="fixClient">The FIX client.</param>
        /// <returns>The created FIX gateway.</returns>
        public static FixDataGateway Create(
            IComponentryContainer container,
            IDataBusAdapter dataBusAdapter,
            IFixClient fixClient)
        {
            var gateway = new FixDataGateway(
                container,
                dataBusAdapter,
                fixClient);

            fixClient.InitializeGateway(gateway);

            return(gateway);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisInstrumentRepository"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="serializer">The instrument serializer.</param>
        /// <param name="connection">The redis connection multiplexer.</param>
        public RedisInstrumentRepository(
            IComponentryContainer container,
            IDataBusAdapter dataBusAdapter,
            IDataSerializer <Instrument> serializer,
            ConnectionMultiplexer connection)
            : base(container, dataBusAdapter)
        {
            this.serializer    = serializer;
            this.redisServer   = connection.GetServer(RedisConstants.Localhost, RedisConstants.DefaultPort);
            this.redisDatabase = connection.GetDatabase();
            this.cache         = new Dictionary <Symbol, Instrument>();

            this.RegisterHandler <Instrument>(this.OnData);

            this.Subscribe <Instrument>();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MockMarketDataRepository"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="quoteSerializer">The quote tick serializer for the repository.</param>
        /// <param name="tradeSerializer">The trade tick serializer for the repository.</param>
        /// <param name="barSerializer">The bar serializer for the repository.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        public MockMarketDataRepository(
            IComponentryContainer container,
            IDataSerializer <QuoteTick> quoteSerializer,
            IDataSerializer <TradeTick> tradeSerializer,
            IDataSerializer <Bar> barSerializer,
            IDataBusAdapter dataBusAdapter)
            : base(container, dataBusAdapter)
        {
            this.quoteTickDatabase = new Dictionary <Symbol, List <QuoteTick> >();
            this.tradeTickDatabase = new Dictionary <Symbol, List <TradeTick> >();
            this.barsDatabase      = new Dictionary <BarType, List <Bar> >();
            this.quoteSerializer   = quoteSerializer;
            this.tradeSerializer   = tradeSerializer;
            this.barSerializer     = barSerializer;

            this.RegisterHandler <QuoteTick>(this.Ingest);
            this.Subscribe <QuoteTick>();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataPublisher"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="instrumentSerializer">The instrument serializer.</param>
        /// <param name="compressor">The data compressor.</param>
        /// <param name="encryption">The encryption configuration.</param>
        /// <param name="port">The port.</param>
        public DataPublisher(
            IComponentryContainer container,
            IDataBusAdapter dataBusAdapter,
            IDataSerializer <Instrument> instrumentSerializer,
            ICompressor compressor,
            EncryptionSettings encryption,
            Port port)
            : base(
                container,
                dataBusAdapter,
                compressor,
                encryption,
                ZmqNetworkAddress.AllInterfaces(port))
        {
            this.instrumentSerializer = instrumentSerializer;

            this.RegisterHandler <Instrument>(this.OnMessage);

            this.Subscribe <BarData>();
            this.Subscribe <Instrument>();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisMarketDataRepository"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="dataBusAdapter">The data bus adapter for the component.</param>
        /// <param name="connection">The clients manager.</param>
        /// <param name="retentionTimeTicksDays">The rolling retention time for tick data in days.</param>
        /// <param name="retentionTimeBarsDays">The rolling retention time for bar data in days.</param>
        public RedisMarketDataRepository(
            IComponentryContainer container,
            IDataBusAdapter dataBusAdapter,
            ConnectionMultiplexer connection,
            int retentionTimeTicksDays,
            IReadOnlyDictionary <BarStructure, int> retentionTimeBarsDays)
            : base(container, dataBusAdapter)
        {
            this.redisServer   = connection.GetServer(RedisConstants.Localhost, RedisConstants.DefaultPort);
            this.redisDatabase = connection.GetDatabase();

            this.pricePrecisions = new Dictionary <Symbol, int>();
            this.sizePrecisions  = new Dictionary <Symbol, int>();

            this.retentionTimeTicksMs = retentionTimeTicksDays * MillisecondsPerDay;
            this.retentionTimeBarsMs  = new Dictionary <BarStructure, long>();

            // Configure retention times converting to milliseconds
            foreach (var(barStructure, retentionDays) in retentionTimeBarsDays)
            {
                this.retentionTimeBarsMs.Add(barStructure, retentionDays * MillisecondsPerDay);
            }

            // Hardcode time bucket constants
            this.timeBuckets = new Dictionary <BarStructure, long>
            {
                { BarStructure.Second, 1000 },
                { BarStructure.Minute, 60000 },
                { BarStructure.Hour, 3600000 },
                { BarStructure.Day, 86400000 }
            };

            this.RegisterHandler <QuoteTick>(this.OnTick);
            this.RegisterHandler <Instrument>(this.OnInstrument);

            this.Subscribe <QuoteTick>();
            this.Subscribe <Instrument>();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TickPublisher"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="quoteSerializer">The quote tick serializer.</param>
        /// <param name="tradeSerializer">The trade tick serializer.</param>
        /// <param name="compressor">The data compressor.</param>
        /// <param name="encryption">The encryption configuration.</param>
        /// <param name="port">The publisher port.</param>
        public TickPublisher(
            IComponentryContainer container,
            IDataBusAdapter dataBusAdapter,
            IDataSerializer <QuoteTick> quoteSerializer,
            IDataSerializer <TradeTick> tradeSerializer,
            ICompressor compressor,
            EncryptionSettings encryption,
            Port port)
            : base(
                container,
                dataBusAdapter,
                compressor,
                encryption,
                ZmqNetworkAddress.AllInterfaces(port))
        {
            this.quoteSerializer = quoteSerializer;
            this.tradeSerializer = tradeSerializer;

            this.RegisterHandler <QuoteTick>(this.OnMessage);
            this.RegisterHandler <TradeTick>(this.OnMessage);

            this.Subscribe <QuoteTick>();
            this.Subscribe <TradeTick>();
        }