Example #1
0
        public InMemoryExecutionDatabaseTests(ITestOutputHelper output)
        {
            // Fixture Setup
            var container = TestComponentryContainer.Create(output);

            this.database = new InMemoryExecutionDatabase(container);
        }
Example #2
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}");
        }
Example #3
0
        public ExecutionEngineTests(ITestOutputHelper output)
        {
            // Fixture Setup
            var container        = TestComponentryContainer.Create(output);
            var messagingAdapter = new MockMessageBusProvider(container).Adapter;

            this.tradingGateway = new MockTradingGateway(container);
            this.receiver       = new MockComponent(container);
            this.receiver.RegisterHandler <Event>(this.receiver.OnMessage);

            this.database = new InMemoryExecutionDatabase(container);

            this.engine = new ExecutionEngine(
                container,
                messagingAdapter,
                this.database,
                this.tradingGateway,
                this.receiver.Endpoint);

            this.tradingGateway.Start().Wait();
            this.receiver.Start().Wait();
            this.engine.Start().Wait();
        }