コード例 #1
0
        /// <summary>
        /// Replays events for the LimitOrderBooks to rebuild them to their prior state
        /// </summary>
        public void ReplayOrderBooks(Exchange exchange, Journaler journaler)
        {
            exchange.TurnReplayModeOn();
            foreach (var exchangeEssential in exchange.ExchangeEssentials)
            {
                //List<Order> ordersForReplay = journaler.GetOrdersForReplay(exchangeEssential.LimitOrderBook);
                List <Order> ordersForReplay = null;

                if (ordersForReplay != null)
                {
                    Order[] deepCopy = (Order[])GetCopy(ordersForReplay.ToArray());
                    foreach (var order in deepCopy)
                    {
                        if (order.OrderState == OrderState.Accepted)
                        {
                            exchange.PlaceNewOrder(order);
                        }
                        else if (order.OrderState == OrderState.Cancelled)
                        {
                            exchange.CancelOrder(new OrderCancellation(order.OrderId, order.TraderId, order.CurrencyPair));
                        }
                    }
                }
            }
            exchange.TurnReplayModeOff();
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Journaler journaler = db.Journaler.Find(id);

            db.Journaler.Remove(journaler);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #5
0
ファイル: frmMain.cs プロジェクト: mcskik/Utilities
        public frmMain()
        {
            InitializeComponent();
            Boolean debug = Administrator.ProfileManager.SystemProfile.Debug;

            _Journaler = new Journaler(rtxOutput, rtxJournal);
            InitialiseFields();
        }
コード例 #6
0
        public void Setup()
        {
            // NOTE: Passing in NULL as RavenDB event store is no longer operational
            //IEventStore eventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            Journaler journaler = new Journaler(null);

            // Initialize the output Disruptor and assign the journaler as the event handler
            OutputDisruptor.InitializeDisruptor(new IEventHandler <byte[]>[] { journaler });
        }
コード例 #7
0
        public void SetUp()
        {
            //initialize journaler
            _eventStore = new RavenNEventStore(Constants.INPUT_EVENT_STORE);
            Journaler journaler = new Journaler(_eventStore);

            //assign journaler to disruptor as its consumer
            InputDisruptorPublisher.InitializeDisruptor(new IEventHandler <InputPayload>[] { journaler });
            _manualResetEvent = new ManualResetEvent(false);
        }
コード例 #8
0
 public ActionResult Edit([Bind(Include = "JournalID,JournalNb,Afleveret,MedieArt,Antal,Regs,Note")] Journaler journaler)
 {
     if (ModelState.IsValid)
     {
         db.Entry(journaler).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(journaler));
 }
コード例 #9
0
        public ActionResult Create([Bind(Include = "JournalID,JournalNb,Afleveret,MedieArt,Antal,Regs,Note")] Journaler journaler)
        {
            if (ModelState.IsValid)
            {
                db.Journaler.Add(journaler);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(journaler));
        }
コード例 #10
0
        // GET: Journalers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Journaler journaler = db.Journaler.Find(id);

            if (journaler == null)
            {
                return(HttpNotFound());
            }
            return(View(journaler));
        }
コード例 #11
0
        public new void SetUp()
        {
            BeforeSetup();
            var connection = ConfigurationManager.ConnectionStrings["MySql"].ToString();

            _databaseUtility = new DatabaseUtility(connection);
            _databaseUtility.Create();
            _databaseUtility.Populate();

            //initialize journaler
            _eventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            Journaler journaler = new Journaler(_eventStore);

            //assign journaler to disruptor as its consumer
            OutputDisruptor.InitializeDisruptor(new IEventHandler <byte[]>[] { journaler });
            _manualResetEvent = new ManualResetEvent(false);
            _listener         = new OrderEventListener(_persistance, _balanceValidationService);
            AfterSetup();
        }
コード例 #12
0
        public new void SetUp()
        {
            BeforeSetup();
            var connection = ConfigurationManager.ConnectionStrings["MySql"].ToString();

            _databaseUtility = new DatabaseUtility(connection);
            _databaseUtility.Create();
            _databaseUtility.Populate();
            //_persistance = ContextRegistry.GetContext()["PersistenceRepository"] as IPersistanceRepository;
            //_orderRepository = ContextRegistry.GetContext()["OrderRepository"] as IOrderRepository;
            //initialize journaler
            _eventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            Journaler journaler = new Journaler(_eventStore);

            //assign journaler to disruptor as its consumer
            OutputDisruptor.InitializeDisruptor(new IEventHandler <byte[]>[] { journaler });
            _manualResetEvent = new ManualResetEvent(false);
            //  _listener = new TradeEventListener(_persistance);
            AfterSetup();
        }
コード例 #13
0
        public void SetUp()
        {
            var connection = ConfigurationManager.ConnectionStrings["MySql"].ToString();

            _databaseUtility = new DatabaseUtility(connection);
            _databaseUtility.Create();
            _databaseUtility.Populate();
            inputEventStore  = new RavenNEventStore(Constants.INPUT_EVENT_STORE);
            outputEventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            inputJournaler   = new Journaler(inputEventStore);
            outputJournaler  = new Journaler(outputEventStore);
            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);
            _exchange.EnableSnaphots(5000);
            InputDisruptorPublisher.InitializeDisruptor(new IEventHandler <InputPayload>[] { _exchange, inputJournaler });
            OutputDisruptor.InitializeDisruptor(new IEventHandler <byte[]>[] { outputJournaler });
        }
コード例 #14
0
        //[Test]
        public void PerformanceTest()
        {
            // Initialize the output Disruptor and assign the journaler as the event handler
            IEventStore eventStore = new RavenNEventStore(Constants.OUTPUT_EVENT_STORE);
            Journaler   journaler  = new Journaler(eventStore);

            OutputDisruptor.InitializeDisruptor(new IEventHandler <byte[]>[] { journaler });
            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);
            List <OrderId> orderIds = new List <OrderId>();

            // Create Orders
            Order[] orders = new Order[10000];
            Random  random = new Random();

            for (int i = 0; i < orders.Length; i++)
            {
                bool    isBuy = ((i % 2) == 0);
                decimal delta = isBuy ? 1880 : 1884;

                Price price = new Price(random.Next(1, 10) + delta);

                Volume volume = new Volume(random.Next() % 10 + 1 * 100);

                OrderId orderId = new OrderId(random.Next(1, 100).ToString(CultureInfo.InvariantCulture));
                orderIds.Add(orderId);
                orders[i] = new Order(orderId, "BTCUSD", price, isBuy ? OrderSide.Buy :
                                      OrderSide.Sell, OrderType.Limit, volume, new TraderId(random.Next(1, 100).ToString()));
            }
            JustAddOrdersToList(orders);
            AddOrdersAndCancel(_exchange.ExchangeEssentials.First().LimitOrderBook, orders, orderIds);
        }
コード例 #15
0
ファイル: frmMain.cs プロジェクト: mcskik/Utilities
 private void cmdClear_Click(object sender, EventArgs e)
 {
     Administrator.ProfileManager.CommandSettings.Clear();
     _Journaler = new Journaler(rtxOutput, rtxJournal);
     InitialiseCommandField();
 }