/// <summary>
        /// Initializes a new instance of the <see cref="FxcmFixMessageHandler"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="accountId">The account identifier for the handler.</param>
        /// <param name="accountCurrency">The account currency.</param>
        /// <param name="useBrokerTimestampForTicks">The flag to use the brokers timestamp for ticks.</param>
        public FxcmFixMessageHandler(
            IComponentryContainer container,
            AccountId accountId,
            Currency accountCurrency,
            bool useBrokerTimestampForTicks = false)
            : base(container)
        {
            this.accountId       = accountId;
            this.accountCurrency = accountCurrency;
            this.symbolCache     = new ObjectCache <string, Symbol>(Symbol.FromString);
            this.orderIdIndex    = new Dictionary <string, OrderId>();

            // Improved performance by reusing MarketDataIncrementalRefresh classes
            this.mdBidGroup = new MarketDataIncrementalRefresh.NoMDEntriesGroup();
            this.mdAskGroup = new MarketDataIncrementalRefresh.NoMDEntriesGroup();

            if (useBrokerTimestampForTicks)
            {
                // FXCM market data timestamp has a lower resolution than .TimeNow()
                this.tickTimestampProvider = this.GetMarketDataTimestamp;
            }
            else
            {
                this.tickTimestampProvider = this.TimeNow;
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisExecutionDatabase"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="connection">The redis connection multiplexer.</param>
        /// <param name="eventSerializer">The event serializer.</param>
        /// <param name="loadCaches">The option flag to load caches from Redis on instantiation.</param>
        /// <param name="orderStatusCheckInterval">The minutes interval between order status checks.</param>
        public RedisExecutionDatabase(
            IComponentryContainer container,
            ConnectionMultiplexer connection,
            ISerializer <Event> eventSerializer,
            bool loadCaches = true,
            int orderStatusCheckInterval = 1)
            : base(container)
        {
            this.redisServer     = connection.GetServer(RedisConstants.Localhost, RedisConstants.DefaultPort);
            this.redisDatabase   = connection.GetDatabase();
            this.eventSerializer = eventSerializer;

            this.OrderStatusCheckInterval = Duration.FromMinutes(orderStatusCheckInterval);

            if (loadCaches)
            {
                this.Logger.LogInformation($"The option {nameof(loadCaches)} is {loadCaches}");
                this.LoadCaches();
            }
            else
            {
                this.Logger.LogWarning(
                    LogId.Database,
                    $"The option {nameof(loadCaches)} is {loadCaches} this should only be done in a testing environment).");
            }
        }
 /// <inheritdoc />
 public BinanceDataGateway(
     IComponentryContainer container,
     IMessageBusAdapter messagingAdapter)
     : base(container, messagingAdapter)
 {
     this.Brokerage = new Brokerage("Binance");
 }
Exemple #4
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);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageBusConnected"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        protected MessageBusConnected(IComponentryContainer container, IMessageBusAdapter messagingAdapter)
            : base(container)
        {
            this.messagingAdapter = messagingAdapter;

            this.RegisterHandler <IEnvelope>(this.OnEnvelope);
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FixTradingGateway"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        /// <param name="fixClient">The FIX client.</param>
        public FixTradingGateway(
            IComponentryContainer container,
            IMessageBusAdapter messagingAdapter,
            IFixClient fixClient)
            : base(container, messagingAdapter)
        {
            this.fixClient = fixClient;

            // Commands
            this.RegisterHandler <ConnectSession>(this.OnMessage);
            this.RegisterHandler <DisconnectSession>(this.OnMessage);

            // Events
            this.RegisterHandler <OrderSubmitted>(this.OnMessage);
            this.RegisterHandler <OrderAccepted>(this.OnMessage);
            this.RegisterHandler <OrderRejected>(this.OnMessage);
            this.RegisterHandler <OrderWorking>(this.OnMessage);
            this.RegisterHandler <OrderModified>(this.OnMessage);
            this.RegisterHandler <OrderCancelReject>(this.OnMessage);
            this.RegisterHandler <OrderExpired>(this.OnMessage);
            this.RegisterHandler <OrderCancelled>(this.OnMessage);
            this.RegisterHandler <OrderPartiallyFilled>(this.OnMessage);
            this.RegisterHandler <OrderFilled>(this.OnMessage);
            this.RegisterHandler <AccountStateEvent>(this.OnMessage);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataService"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="dataGateway">The data gateway.</param>
        /// <param name="config">The service configuration.</param>
        /// <exception cref="ArgumentException">If the addresses is empty.</exception>
        public DataService(
            IComponentryContainer container,
            MessageBusAdapter messagingAdapter,
            DataBusAdapter dataBusAdapter,
            IDataGateway dataGateway,
            ServiceConfiguration config)
            : base(
                container,
                messagingAdapter,
                config.FixConfig)
        {
            this.dataBus           = dataBusAdapter;
            this.dataGateway       = dataGateway;
            this.managedComponents = new List <Address>
            {
                ComponentAddress.DataServer,
                ComponentAddress.DataPublisher,
                ComponentAddress.MarketDataRepository,
                ComponentAddress.TickPublisher,
                ComponentAddress.TickProvider,
                ComponentAddress.BarProvider,
                ComponentAddress.InstrumentRepository,
                ComponentAddress.InstrumentProvider,
            };

            this.subscribingSymbols = config.DataConfig.SubscribingSymbols;

            this.RegisterConnectionAddress(ComponentAddress.DataGateway);
        }
Exemple #8
0
 public ThrottlerTests(ITestOutputHelper output)
 {
     // Fixture Setup
     this.container = TestComponentryContainer.Create(output);
     this.receiver  = new MockComponent(this.container);
     this.receiver.RegisterHandler <string>(this.receiver.OnMessage);
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataServer"/> class.
 /// </summary>
 /// <param name="container">The componentry container.</param>
 /// <param name="messagingAdapter">The messaging adapter.</param>
 /// <param name="headerSerializer">The header serializer.</param>
 /// <param name="requestSerializer">The inbound message serializer.</param>
 /// <param name="responseSerializer">The outbound message serializer.</param>
 /// <param name="compressor">The data compressor.</param>
 /// <param name="encryption">The encryption configuration.</param>
 /// <param name="serviceName">The service name.</param>
 /// <param name="requestPort">The inbound port.</param>
 /// <param name="responsePort">The outbound port.</param>
 public DataServer(
     IComponentryContainer container,
     IMessageBusAdapter messagingAdapter,
     ISerializer <Dictionary <string, string> > headerSerializer,
     IMessageSerializer <Request> requestSerializer,
     IMessageSerializer <Response> responseSerializer,
     ICompressor compressor,
     EncryptionSettings encryption,
     Label serviceName,
     Port requestPort,
     Port responsePort)
     : base(
         container,
         messagingAdapter,
         headerSerializer,
         requestSerializer,
         responseSerializer,
         compressor,
         encryption,
         serviceName,
         ZmqNetworkAddress.AllInterfaces(requestPort),
         ZmqNetworkAddress.AllInterfaces(responsePort))
 {
     this.RegisterHandler <DataRequest>(this.OnMessage);
     this.RegisterHandler <DataResponse>(this.OnMessage);
     this.RegisterHandler <QueryFailure>(this.OnMessage);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FxcmFixMessageRouter"/> class.
 /// </summary>
 /// <param name="container">The componentry container.</param>
 /// <param name="accountId">The account identifier for the router.</param>
 public FxcmFixMessageRouter(
     IComponentryContainer container,
     AccountId accountId)
     : base(container)
 {
     this.accountId = accountId;
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExecutionDatabase"/> class.
 /// </summary>
 /// <param name="container">The componentry container.</param>
 protected ExecutionDatabase(IComponentryContainer container)
     : base(container)
 {
     this.CachedAccounts  = new Dictionary <AccountId, Account>();
     this.CachedOrders    = new Dictionary <OrderId, Order>();
     this.CachedPositions = new Dictionary <PositionId, Position>();
 }
Exemple #12
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;
        }
Exemple #13
0
 /// <summary>
 /// Creates and returns a new message bus adapter.
 /// </summary>
 /// <param name="container">The componentry container.</param>
 /// <returns>The messaging adapter.</returns>
 public static MessageBusAdapter Create(IComponentryContainer container)
 {
     return(new MessageBusAdapter(
                new MessageBus <Command>(container),
                new MessageBus <Event>(container),
                new MessageBus <Message>(container)));
 }
Exemple #14
0
 /// <summary>
 /// Creates and returns a new message bus adapter.
 /// </summary>
 /// <param name="container">The componentry container.</param>
 /// <returns>The messaging adapter.</returns>
 public static DataBusAdapter Create(IComponentryContainer container)
 {
     return(new DataBusAdapter(
                new DataBus <QuoteTick>(container),
                new DataBus <TradeTick>(container),
                new DataBus <BarData>(container),
                new DataBus <Instrument>(container)));
 }
Exemple #15
0
 public DataBusTests(ITestOutputHelper output)
 {
     // Fixture Setup
     this.container = TestComponentryContainer.Create(output);
     this.receiver  = new MockComponent(this.container, "1");
     this.dataBus   = new DataBus <Tick>(this.container);
     this.receiver.RegisterHandler <Tick>(this.receiver.OnMessage);
     this.dataBus.Start().Wait();
 }
Exemple #16
0
 public MockComponent(
     IComponentryContainer container,
     string subName            = "",
     int workDelayMilliseconds = 1000)
     : base(container, subName)
 {
     this.Messages = new List <object>();
     this.workDelayMilliseconds = workDelayMilliseconds;
 }
 public InstrumentProviderTests(ITestOutputHelper output)
     : base(output)
 {
     // Fixture Setup
     this.container        = TestComponentryContainer.Create(output);
     this.messagingAdapter = new MockMessageBusProvider(this.container).Adapter;
     this.dataSerializer   = new InstrumentSerializer();
     this.repository       = new MockInstrumentRepository(this.dataSerializer);
 }
 public RedisExecutionDatabaseTests(ITestOutputHelper output)
 {
     // Fixture Setup
     this.container       = TestComponentryContainer.Create(output);
     this.redisConnection = ConnectionMultiplexer.Connect("localhost:6379,allowAdmin=true");
     this.database        = new RedisExecutionDatabase(
         this.container,
         this.redisConnection,
         new MsgPackEventSerializer());
 }
Exemple #19
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);
        }
Exemple #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Component"/> class.
        /// </summary>
        /// <param name="container">The components componentry container.</param>
        /// <param name="subName">The sub-name for the component.</param>
        protected Component(IComponentryContainer container, string subName)
        {
            this.clock       = container.Clock;
            this.guidFactory = container.GuidFactory;

            this.Name   = new Label($"{this.GetType().NameFormatted()}{SetSubName(subName)}");
            this.Logger = container.LoggerFactory.CreateLogger(this.Name.Value);

            this.InitializedTime = this.clock.TimeNow();
            this.Logger.LogDebug(LogId.Component, "Initialized.");
        }
Exemple #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InstrumentProvider"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        /// <param name="repository">The instrument repository.</param>
        /// <param name="dataSerializer">The data serializer.</param>
        public InstrumentProvider(
            IComponentryContainer container,
            IMessageBusAdapter messagingAdapter,
            IInstrumentRepositoryReadOnly repository,
            IDataSerializer <Instrument> dataSerializer)
            : base(container, messagingAdapter)
        {
            this.repository     = repository;
            this.dataSerializer = dataSerializer;

            this.RegisterHandler <DataRequest>(this.OnMessage);
        }
Exemple #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BarProvider"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        /// <param name="repository">The instrument repository.</param>
        /// <param name="dataSerializer">The data serializer for the provider.</param>
        public BarProvider(
            IComponentryContainer container,
            IMessageBusAdapter messagingAdapter,
            IBarRepository repository,
            IDataSerializer <Bar> dataSerializer)
            : base(container, messagingAdapter)
        {
            this.repository     = repository;
            this.dataSerializer = dataSerializer;

            this.RegisterHandler <DataRequest>(this.OnMessage);
        }
Exemple #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExecutionEngine"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The message bus adapter.</param>
        /// <param name="database">The execution database.</param>
        /// <param name="gateway">The trading gateway.</param>
        /// <param name="eventPublisher">The event publisher endpoint.</param>
        /// <param name="gtdExpiryBackups">The option flag for GTD order expiry cancel backups.</param>
        public ExecutionEngine(
            IComponentryContainer container,
            IMessageBusAdapter messagingAdapter,
            IExecutionDatabase database,
            ITradingGateway gateway,
            IEndpoint eventPublisher,
            bool gtdExpiryBackups = true)
            : base(container, messagingAdapter)
        {
            this.database       = database;
            this.gateway        = gateway;
            this.eventPublisher = eventPublisher;

            this.bufferModify = new Dictionary <OrderId, ModifyOrder>();
            this.cancelJobs   = new Dictionary <OrderId, JobKey>();

            this.GtdExpiryBackups = gtdExpiryBackups;

            // Commands
            this.RegisterHandler <SubmitOrder>(this.OnMessage);
            this.RegisterHandler <SubmitBracketOrder>(this.OnMessage);
            this.RegisterHandler <CancelOrder>(this.OnMessage);
            this.RegisterHandler <ModifyOrder>(this.OnMessage);
            this.RegisterHandler <AccountInquiry>(this.OnMessage);

            // Events
            this.RegisterHandler <OrderSubmitted>(this.OnMessage);
            this.RegisterHandler <OrderAccepted>(this.OnMessage);
            this.RegisterHandler <OrderRejected>(this.OnMessage);
            this.RegisterHandler <OrderWorking>(this.OnMessage);
            this.RegisterHandler <OrderModified>(this.OnMessage);
            this.RegisterHandler <OrderCancelReject>(this.OnMessage);
            this.RegisterHandler <OrderExpired>(this.OnMessage);
            this.RegisterHandler <OrderCancelled>(this.OnMessage);
            this.RegisterHandler <OrderPartiallyFilled>(this.OnMessage);
            this.RegisterHandler <OrderFilled>(this.OnMessage);
            this.RegisterHandler <AccountStateEvent>(this.OnMessage);

            // Order Events
            this.Subscribe <OrderSubmitted>();
            this.Subscribe <OrderAccepted>();
            this.Subscribe <OrderRejected>();
            this.Subscribe <OrderWorking>();
            this.Subscribe <OrderModified>();
            this.Subscribe <OrderCancelReject>();
            this.Subscribe <OrderExpired>();
            this.Subscribe <OrderCancelled>();
            this.Subscribe <OrderPartiallyFilled>();
            this.Subscribe <OrderFilled>();
            this.Subscribe <AccountStateEvent>();

            this.Logger.LogInformation(LogId.Component, $"{nameof(this.GtdExpiryBackups)} is {this.GtdExpiryBackups}");
        }
Exemple #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessagingComponent"/> class.
        /// </summary>
        /// <param name="container">The components componentry container.</param>
        /// <param name="subName">The sub-name for the component.</param>
        protected MessagingComponent(IComponentryContainer container, string subName)
            : base(container, subName)
        {
            this.processor = new MessageProcessor();
            this.processor.RegisterUnhandled(this.Unhandled);

            this.Mailbox        = new Mailbox(new Address(this.Name.Value), this.processor.Endpoint);
            this.ComponentState = ComponentState.Initialized;

            this.RegisterExceptionHandler(this.HandleException);
            this.RegisterHandler <Start>(this.OnMessage);
            this.RegisterHandler <Stop>(this.OnMessage);
        }
Exemple #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageBus{T}"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        public MessageBus(IComponentryContainer container)
            : base(container)
        {
            this.deadLetters      = new List <object>();
            this.subscriptionsAll = new List <Mailbox>();
            this.subscriptions    = new Dictionary <Type, List <Mailbox> >();

            this.switchboard = Switchboard.Empty();

            this.RegisterHandler <IEnvelope>(this.OnReceive);
            this.RegisterHandler <InitializeSwitchboard>(this.OnMessage);
            this.RegisterHandler <Subscribe <Type> >(this.OnMessage);
            this.RegisterHandler <Unsubscribe <Type> >(this.OnMessage);
        }
Exemple #26
0
 public BarProviderTests(ITestOutputHelper output)
     : base(output)
 {
     // Fixture Setup
     this.container        = TestComponentryContainer.Create(output);
     this.messagingAdapter = new MockMessageBusProvider(this.container).Adapter;
     this.barSerializer    = new BarSerializer();
     this.repository       = new MockMarketDataRepository(
         this.container,
         new QuoteTickSerializer(),
         new TradeTickSerializer(),
         this.barSerializer,
         DataBusFactory.Create(this.container));
 }
        /// <summary>
        /// Creates and returns a new FIX gateway.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        /// <param name="fixClient">The FIX client.</param>
        /// <returns>The created FIX gateway.</returns>
        public static FixTradingGateway Create(
            IComponentryContainer container,
            IMessageBusAdapter messagingAdapter,
            IFixClient fixClient)
        {
            var gateway = new FixTradingGateway(
                container,
                messagingAdapter,
                fixClient);

            fixClient.InitializeGateway(gateway);

            return(gateway);
        }
Exemple #28
0
 public MockDataPublisher(
     IComponentryContainer container,
     IDataBusAdapter dataBusAdapter,
     EncryptionSettings encryption,
     ZmqNetworkAddress networkAddress)
     : base(
         container,
         dataBusAdapter,
         new BypassCompressor(),
         encryption,
         networkAddress)
 {
     this.RegisterHandler <(string, string)>(this.OnMessage);
 }
Exemple #29
0
        public MessageServerTests(ITestOutputHelper output)
            : base(output)
        {
            // Fixture Setup
            this.container          = TestComponentryContainer.Create(output);
            this.messagingAdapter   = new MockMessageBusProvider(this.container).Adapter;
            this.headerSerializer   = new MsgPackDictionarySerializer();
            this.requestSerializer  = new MsgPackRequestSerializer();
            this.responseSerializer = new MsgPackResponseSerializer();
            this.compressor         = new BypassCompressor();

            this.testRequestAddress  = ZmqNetworkAddress.LocalHost(new Port(55655));
            this.testResponseAddress = ZmqNetworkAddress.LocalHost(new Port(55656));
        }
Exemple #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TickProvider"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        /// <param name="repository">The tick repository.</param>
        /// <param name="quoteSerializer">The quote tick serializer.</param>
        /// <param name="tradeSerializer">The trade tick serializer.</param>
        public TickProvider(
            IComponentryContainer container,
            IMessageBusAdapter messagingAdapter,
            ITickRepository repository,
            IDataSerializer <QuoteTick> quoteSerializer,
            IDataSerializer <TradeTick> tradeSerializer)
            : base(container, messagingAdapter)
        {
            this.repository      = repository;
            this.quoteSerializer = quoteSerializer;
            this.tradeSerializer = tradeSerializer;

            this.RegisterHandler <DataRequest>(this.OnMessage);
        }