Exemple #1
0
        /// <summary>
        /// Receives trade when events are raised
        /// </summary>
        /// <param name="trade"></param>
        void OnTradeArrived(Trade trade)
        {
            _persistanceRepository.SaveOrUpdate(ReadModelAdapter.GetTradeReadModel(trade));
            _ohlcCalculation.CalculateAndPersistOhlc(trade);
            _tickerInfoCalculation.CalculateTickerInfo(trade);
            Tuple <string, string> currencies = CurrencySplitterService.SplitCurrencyPair(trade.CurrencyPair);

            // Update the balance on hte Funds BC
            _balanceValidationService.TradeExecuted(currencies.Item1, currencies.Item2, trade.ExecutedVolume.Value,
                                                    trade.ExecutionPrice.Value, trade.ExecutionTime, trade.TradeId.Id, trade.BuyOrder.TraderId.Id,
                                                    trade.SellOrder.TraderId.Id, trade.BuyOrder.OrderId.Id, trade.SellOrder.OrderId.Id);
        }
Exemple #2
0
        public void SaveTradeReadModel_IfSaveOrUpdateMethodIsCalled_ItShouldGetSavedInTheDatabase()
        {
            Order buyOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "buy", 5, 0,
                                                      new StubbedOrderIdGenerator());
            Order sellOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "sell", 5, 0,
                                                       new StubbedOrderIdGenerator());
            //Trade trade=new Trade("XBTUSD",new Price(100),new Volume(10),DateTime.Now,buyOrder,sellOrder);
            Trade          trade = TradeFactory.GenerateTrade("XBTUSD", new Price(100), new Volume(10), buyOrder, sellOrder);
            TradeReadModel model = ReadModelAdapter.GetTradeReadModel(trade);

            _persistanceRepository.SaveOrUpdate(model);
            TradeReadModel getSavedModel = _tradeRepository.GetById(trade.TradeId.Id.ToString());

            Assert.NotNull(getSavedModel);
            AssertAreEqual(getSavedModel, model);
        }
Exemple #3
0
        public void GetRecentTrades_IfRecentTradesRequestArrives_ItShouldReturnRecentTrades()
        {
            Order buyOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "buy", 5, 0,
                                                      new StubbedOrderIdGenerator());
            Order sellOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "sell", 5, 0,
                                                       new StubbedOrderIdGenerator());
            //Trade trade=new Trade("XBTUSD",new Price(100),new Volume(10),DateTime.Now,buyOrder,sellOrder);
            Trade          trade = TradeFactory.GenerateTrade("XBTUSD", new Price(100), new Volume(10), buyOrder, sellOrder);
            TradeReadModel model = ReadModelAdapter.GetTradeReadModel(trade);

            _persistanceRepository.SaveOrUpdate(model);
            IList <object> getTrades = _tradeRepository.GetRecentTrades("", "XBTUSD");

            Assert.NotNull(getTrades);
            Assert.AreEqual(getTrades.Count, 1);
            object[] received = getTrades[0] as object[];
            Assert.AreEqual(received[1], 100);
            Assert.AreEqual(received[2], 10);
        }
Exemple #4
0
        public void GetTradesOfTrader_IfTraderIdIsProvided_AllTradesOfTraderShouldReturn()
        {
            Order buyOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "buy", 5, 0,
                                                      new StubbedOrderIdGenerator());
            Order sellOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "sell", 5, 0,
                                                       new StubbedOrderIdGenerator());
            //Trade trade=new Trade("XBTUSD",new Price(100),new Volume(10),DateTime.Now,buyOrder,sellOrder);
            Trade          trade = TradeFactory.GenerateTrade("XBTUSD", new Price(100), new Volume(10), buyOrder, sellOrder);
            TradeReadModel model = ReadModelAdapter.GetTradeReadModel(trade);

            _persistanceRepository.SaveOrUpdate(model);
            //model.TradeId = DateTime.Now.Millisecond.ToString();
            var getTrades = _tradeRepository.GetTraderTradeHistory("1234");

            Assert.NotNull(getTrades);
            Assert.AreEqual(getTrades.Count, 1);
            object[] received = getTrades[0] as object[];
            Assert.AreEqual(received[2], 100);
            Assert.AreEqual(received[3], 10);
            Assert.AreEqual(received[4], "XBTUSD");
        }
Exemple #5
0
        public void GetTradesOfTrader_IfTraderIdIsProvided_AllTradesOfTraderShouldBeDateTimeSortedDesc()
        {
            Order buyOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "buy", 5, 0,
                                                      new StubbedOrderIdGenerator());
            Order sellOrder = OrderFactory.CreateOrder("1234", "XBTUSD", "market", "sell", 5, 0,
                                                       new StubbedOrderIdGenerator());
            ManualResetEvent resetEvent = new ManualResetEvent(false);
            //Trade trade=new Trade("XBTUSD",new Price(100),new Volume(10),DateTime.Now,buyOrder,sellOrder);
            Trade trade = TradeFactory.GenerateTrade("XBTUSD", new Price(100), new Volume(10), buyOrder, sellOrder);

            resetEvent.WaitOne(2000);
            resetEvent.Reset();
            Trade trade1 = TradeFactory.GenerateTrade("XBTUSD", new Price(100), new Volume(10), buyOrder, sellOrder);

            resetEvent.WaitOne(2000);
            resetEvent.Reset();
            Trade trade2 = TradeFactory.GenerateTrade("XBTUSD", new Price(100), new Volume(10), buyOrder, sellOrder);

            resetEvent.WaitOne(2000);
            resetEvent.Reset();
            TradeReadModel model = ReadModelAdapter.GetTradeReadModel(trade);

            _persistanceRepository.SaveOrUpdate(model);
            TradeReadModel model1 = ReadModelAdapter.GetTradeReadModel(trade1);

            _persistanceRepository.SaveOrUpdate(model1);
            TradeReadModel model2 = ReadModelAdapter.GetTradeReadModel(trade2);

            _persistanceRepository.SaveOrUpdate(model2);
            IList <object> getTrades = _tradeRepository.GetTraderTradeHistory("1234");

            Assert.NotNull(getTrades);
            Assert.AreEqual(getTrades.Count, 3);
            object[] received  = getTrades[0] as object[];
            object[] received1 = getTrades[1] as object[];
            object[] received2 = getTrades[2] as object[];
            Assert.True(Convert.ToDateTime(received[1]) > Convert.ToDateTime(received1[1]));
            Assert.True(Convert.ToDateTime(received1[1]) > Convert.ToDateTime(received2[1]));
        }