private void CrashAndInitializeAgainWithSnapshot()
        {
            //crash
            InputDisruptorPublisher.Shutdown();
            OutputDisruptor.ShutDown();
            _exchange.StopTimer();
            inputEventStore.ShutDown();
            outputEventStore.ShutDown();
            inputJournaler.ShutDown();
            outputJournaler.ShutDown();
            ContextRegistry.Clear();

            //initialize
            inputEventStore     = new RavenNEventStore(Constants.INPUT_EVENT_STORE);
            outputEventStore    = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            inputJournaler      = new Journaler(inputEventStore);
            outputJournaler     = new Journaler(outputEventStore);
            _applicationContext = ContextRegistry.GetContext();
            IList <CurrencyPair> currencyPairs = new List <CurrencyPair>();

            currencyPairs.Add(new CurrencyPair("BTCUSD", "USD", "BTC"));
            currencyPairs.Add(new CurrencyPair("BTCLTC", "LTC", "BTC"));
            currencyPairs.Add(new CurrencyPair("BTCDOGE", "DOGE", "BTC"));
            _exchange = new Exchange(currencyPairs, outputEventStore.LoadLastSnapshot());
            InputDisruptorPublisher.InitializeDisruptor(new IEventHandler <InputPayload>[] { _exchange, inputJournaler });
            OutputDisruptor.InitializeDisruptor(new IEventHandler <byte[]>[] { outputJournaler });
            _exchange.InitializeExchangeAfterSnaphot();
            LimitOrderBookReplayService service = new LimitOrderBookReplayService();

            service.ReplayOrderBooks(_exchange, outputJournaler);
            _exchange.EnableSnaphots(5000);
            ManualResetEvent resetEvent = new ManualResetEvent(false);

            resetEvent.WaitOne(20000);
        }
Ejemplo n.º 2
0
        //protected override System.Web.Http.Dependencies.IDependencyResolver BuildWebApiDependencyResolver()
        //{
        //    //get the 'default' resolver, populated from the 'main' config metadata
        //    var resolver = base.BuildWebApiDependencyResolver();

        //    //check if its castable to a SpringWebApiDependencyResolver
        //    var springResolver = resolver as SpringWebApiDependencyResolver;

        //    //return the fully-configured resolver
        //    return springResolver;
        //}

        /// <summary>
        /// Method for initializaing the single threaded application parts
        /// </summary>
        private void InitiliazeApplication()
        {
            InputDisruptorPublisher.Shutdown();
            OutputDisruptor.ShutDown();
            IEventStore inputEventStore = new RavenNEventStore(Constants.INPUT_EVENT_STORE);
            IEventStore outputEventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            Journaler inputJournaler = new Journaler(inputEventStore);
            Journaler outputJournaler = new Journaler(outputEventStore);
            ExchangeEssentialsList exchangeEssentialsList=outputEventStore.LoadLastSnapshot();
            ICurrencyPairRepository currencyPairRepository = (ICurrencyPairRepository) ContextRegistry.GetContext()["CurrencyPairRepository"];
            IList<CurrencyPair> tradeableCurrencyPairs = currencyPairRepository.GetTradeableCurrencyPairs();
            Exchange exchange;
            if (exchangeEssentialsList != null)
            {
                //means snapshot found so initialize the exchange
                exchange = new Exchange(tradeableCurrencyPairs, exchangeEssentialsList);
                InputDisruptorPublisher.InitializeDisruptor(new IEventHandler<InputPayload>[] {exchange, inputJournaler});
                OutputDisruptor.InitializeDisruptor(new IEventHandler<byte[]>[] {outputJournaler});
                exchange.InitializeExchangeAfterSnaphot();
                LimitOrderBookReplayService service = new LimitOrderBookReplayService();
                service.ReplayOrderBooks(exchange, outputJournaler);
                exchange.EnableSnaphots(Constants.SnaphsortInterval);
            }
            else
            {
                //no snapshot found
                exchange = new Exchange(tradeableCurrencyPairs);
                InputDisruptorPublisher.InitializeDisruptor(new IEventHandler<InputPayload>[] { exchange, inputJournaler });
                OutputDisruptor.InitializeDisruptor(new IEventHandler<byte[]>[] { outputJournaler });
               // check if there are events to replay
                LimitOrderBookReplayService service = new LimitOrderBookReplayService();
                service.ReplayOrderBooks(exchange, outputJournaler);
                exchange.EnableSnaphots(Constants.SnaphsortInterval);
            }
        }
Ejemplo n.º 3
0
 public new void TearDown()
 {
     BeforeTearDown();
     _databaseUtility.Create();
     OutputDisruptor.ShutDown();
     AfterTearDown();
 }
 public new void TearDown()
 {
     BeforeTearDown();
     _databaseUtility.Create();
     OutputDisruptor.ShutDown();
     _eventStore.RemoveAllEvents();
     AfterTearDown();
 }
Ejemplo n.º 5
0
 public new void TearDown()
 {
     _databaseUtility.Create();
     InputDisruptorPublisher.Shutdown();
     OutputDisruptor.ShutDown();
     inputEventStore.RemoveAllEvents();
     outputEventStore.RemoveAllEvents();
 }
 public void TearDown()
 {
     _exchange.StopTimer();
     _databaseUtility.Create();
     InputDisruptorPublisher.Shutdown();
     OutputDisruptor.ShutDown();
     inputEventStore.RemoveAllEvents();
     outputEventStore.RemoveAllEvents();
 }
 public void TearDown()
 {
     InputDisruptorPublisher.Shutdown();
     OutputDisruptor.ShutDown();
     ContextRegistry.Clear();
     _databaseUtility.Create();
     inputEventStore.RemoveAllEvents();
     outputEventStore.RemoveAllEvents();
 }
 public void TearDown()
 {
     OutputDisruptor.ShutDown();
     _eventStore.RemoveAllEvents();
 }
Ejemplo n.º 9
0
 public void TearDown()
 {
     OutputDisruptor.ShutDown();
 }
        public void GetTradesForTraderBetweenTimeRangeTest_TestsTheMethodThatWillGetAllTradesForACurrencypair_AssertsTheValuesOfTheFetchedTrades()
        {
            // Get the context
            IApplicationContext applicationContext = ContextRegistry.GetContext();
            //Exchange exchange = new Exchange();
            //IEventStore inputEventStore = new RavenNEventStore(Constants.INPUT_EVENT_STORE);
            //IEventStore outputEventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            //Journaler inputJournaler = new Journaler(inputEventStore);
            //Journaler outputJournaler = new Journaler(outputEventStore);
            //InputDisruptorPublisher.InitializeDisruptor(new IEventHandler<InputPayload>[] { exchange, inputJournaler });
            //OutputDisruptor.InitializeDisruptor(new IEventHandler<byte[]>[] { outputJournaler });

            // Get the instance through Spring configuration
            TradeController tradeController = (TradeController)applicationContext["TradeController"];

            tradeController.Request = new HttpRequestMessage(HttpMethod.Post, "");
            tradeController.Request.Headers.Add("Auth", "123456789");

            // Get the instance through Spring configuration
            OrderController orderController = (OrderController)applicationContext["OrderController"];

            orderController.Request = new HttpRequestMessage(HttpMethod.Post, "");
            orderController.Request.Headers.Add("Auth", "123456789");

            ITradeRepository tradeRepository = (ITradeRepository)applicationContext["TradeRepository"];

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 491,
                Volume = 100,
                Side   = "buy",
                Type   = "limit"
            });

            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);
            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 492,
                Volume = 300,
                Side   = "buy",
                Type   = "limit"
            });

            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);

            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 493,
                Volume = 1000,
                Side   = "buy",
                Type   = "limit"
            });

            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 493,
                Volume = 1000,
                Side   = "sell",
                Type   = "limit"
            });

            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);

            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 492,
                Volume = 300,
                Side   = "sell",
                Type   = "limit"
            });

            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);

            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 491,
                Volume = 100,
                Side   = "sell",
                Type   = "limit"
            });

            manualResetEvent.Reset();
            manualResetEvent.WaitOne(4000);
            IHttpActionResult httpActionResult = tradeController.GetTradeHistory(new TradeHistoryParams("2014/05/09", "2014/05/09"));
            OkNegotiatedContentResult <object> okResponseObject = (OkNegotiatedContentResult <object>)httpActionResult;

            IList <object>  objectList     = (IList <object>)okResponseObject.Content;
            List <object[]> newObjectsList = new List <object[]>();

            for (int i = 0; i < objectList.Count; i++)
            {
                object[] objects = objectList[i] as object[];
                newObjectsList.Add(objects);
            }

            Assert.AreEqual(493, newObjectsList[0][2]);
            Assert.AreEqual(1000, newObjectsList[0][3]);

            Assert.AreEqual(492, newObjectsList[1][2]);
            Assert.AreEqual(300, newObjectsList[1][3]);

            Assert.AreEqual(491, newObjectsList[2][2]);
            Assert.AreEqual(100, newObjectsList[2][3]);

            InputDisruptorPublisher.Shutdown();
            OutputDisruptor.ShutDown();

            tradeRepository.RollBack();
        }
        public void GetTradeDetails_SendMatchingOrdersWithDifferentTraders_TradeDetailsShouldGetReceived()
        {
            // Get the context
            IApplicationContext applicationContext = ContextRegistry.GetContext();

            // Get the instance through Spring configuration
            TradeController tradeController = (TradeController)applicationContext["TradeController"];

            tradeController.Request = new HttpRequestMessage(HttpMethod.Post, "");
            tradeController.Request.Headers.Add("Auth", "123456789");

            // Get the instance through Spring configuration
            OrderController orderController = (OrderController)applicationContext["OrderController"];

            orderController.Request = new HttpRequestMessage(HttpMethod.Post, "");
            orderController.Request.Headers.Add("Auth", "123456789");
            ITradeRepository tradeRepository = (ITradeRepository)applicationContext["TradeRepository"];

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 491,
                Volume = 100,
                Side   = "buy",
                Type   = "limit"
            });

            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);
            OrderController orderController1 = (OrderController)applicationContext["OrderController"];

            orderController1.Request = new HttpRequestMessage(HttpMethod.Post, "");
            orderController1.Request.Headers.Add("Auth", "55555");
            orderController1.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 490,
                Volume = 300,
                Side   = "sell",
                Type   = "limit"
            });

            manualResetEvent.Reset();
            manualResetEvent.WaitOne(4000);
            IHttpActionResult httpActionResult = tradeController.GetTradeHistory(new TradeHistoryParams("", ""));
            OkNegotiatedContentResult <object> okResponseObject = (OkNegotiatedContentResult <object>)httpActionResult;

            IList <object> objectList = (IList <object>)okResponseObject.Content;

            object[] details = objectList[0] as object[];
            string   tradeId = details[0] as string;

            //verify trader("123456789") details
            httpActionResult = tradeController.TradeDetails(tradeId);
            OkNegotiatedContentResult <TradeDetailsRepresentation> tradeDetails =
                (OkNegotiatedContentResult <TradeDetailsRepresentation>)httpActionResult;

            Assert.AreEqual(tradeDetails.Content.TradeId, tradeId);
            Assert.AreEqual(tradeDetails.Content.ExecutionPrice, (decimal)details[2]);
            Assert.AreEqual(tradeDetails.Content.Volume, (decimal)details[3]);
            Assert.AreEqual(tradeDetails.Content.Order.Price, 491);
            Assert.AreEqual(tradeDetails.Content.Order.Side, OrderSide.Buy.ToString());
            Assert.AreEqual(tradeDetails.Content.Order.Type, OrderType.Limit.ToString());
            Assert.AreEqual(tradeDetails.Content.Order.Volume, 100);
            Assert.AreEqual(tradeDetails.Content.Order.Status, OrderState.Complete.ToString());

            //verify trader("55555") details
            TradeController tradeController1 = (TradeController)applicationContext["TradeController"];

            tradeController1.Request = new HttpRequestMessage(HttpMethod.Post, "");
            tradeController1.Request.Headers.Add("Auth", "55555");
            httpActionResult = tradeController1.TradeDetails(tradeId);
            OkNegotiatedContentResult <TradeDetailsRepresentation> tradeDetails1 =
                (OkNegotiatedContentResult <TradeDetailsRepresentation>)httpActionResult;

            Assert.AreEqual(tradeDetails1.Content.TradeId, tradeId);
            Assert.AreEqual(tradeDetails1.Content.ExecutionPrice, (decimal)details[2]);
            Assert.AreEqual(tradeDetails1.Content.Volume, (decimal)details[3]);
            Assert.AreEqual(tradeDetails1.Content.Order.Price, 490);
            Assert.AreEqual(tradeDetails1.Content.Order.Side, OrderSide.Sell.ToString());
            Assert.AreEqual(tradeDetails1.Content.Order.Type, OrderType.Limit.ToString());
            Assert.AreEqual(tradeDetails1.Content.Order.Volume, 300);
            Assert.AreEqual(tradeDetails1.Content.Order.Status, OrderState.PartiallyFilled.ToString());

            InputDisruptorPublisher.Shutdown();
            OutputDisruptor.ShutDown();
            tradeRepository.RollBack();
        }