Beispiel #1
0
        private void DoWork(object state)
        {
            _logger.LogInformation("MarketMovementService moving the market now...");
            TicksPassed++;
            GetMarketProductsFromDb();
            foreach (var mp in marketProducts)
            {
                using (var scope = ServiceScopeFactory.CreateScope())
                {
                    var services = scope.ServiceProvider;
                    pandaRepo = services.GetRequiredService <IPandaRepository>();

                    int addedAmount = 25;
                    _logger.LogInformation($"Add {addedAmount} pieces of {mp.ProductCode}...");
                    pandaRepo.IncreaseMarketProductAmount(mp.ProductCode, addedAmount);

                    decimal newPrice = CalcNewPrice(mp, addedAmount);
                    _logger.LogInformation($"Set price of {mp.ProductCode} to {newPrice}...");
                    pandaRepo.SetMarketProductPrice(mp.ProductCode, newPrice);

                    BookAllOpenBookingOrders();
                }
            }
            _logger.LogInformation("MarketMovementService done moving the market.");
        }
Beispiel #2
0
 private void GetMarketProductsFromDb()
 {
     using (var scope = ServiceScopeFactory.CreateScope())
     {
         var services = scope.ServiceProvider;
         pandaRepo      = services.GetRequiredService <IPandaRepository>();
         marketProducts = pandaRepo.GetAllMarketProducts().ToList();
     }
 }
Beispiel #3
0
        public static void SeedInitialProductData(IPandaRepository pandaRepo)
        {
            var products = pandaRepo.GetAllProducts();

            if (!products.Any())
            {
                SetupProduct(pandaRepo, "LAX", 100, 0.01m);
                SetupProduct(pandaRepo, "WOT", 1000, 0.01m);
                SetupProduct(pandaRepo, "YSI", 10000, 0.01m);
                SetupProduct(pandaRepo, "NWA", 2000, 0.01m);
                SetupProduct(pandaRepo, "RPI", 2100, 0.01m);
                SetupProduct(pandaRepo, "LOL", 2500, 0.01m);
                SetupProduct(pandaRepo, "SXE", 200, 0.01m);
                SetupProduct(pandaRepo, "RAW", 400, 0.01m);
                SetupProduct(pandaRepo, "FCK", 5000, 0.01m);
            }
        }
Beispiel #4
0
 private void BookAllOpenBookingOrders()
 {
     using (var scope = ServiceScopeFactory.CreateScope())
     {
         var services = scope.ServiceProvider;
         pandaRepo         = services.GetRequiredService <IPandaRepository>();
         openBookingOrders = pandaRepo.GetBookingOrdersUnbooked().ToList();
         foreach (var bookingOrder in openBookingOrders)
         {
             try
             {
                 _logger.LogInformation($"Booking BookingOrder {bookingOrder.Id}: {bookingOrder.Amount} {bookingOrder.ProductCode} by {bookingOrder.Trader.Name}");
                 pandaRepo.BookBookingOrder(bookingOrder);
             }
             catch (Exception ex)
             {
                 _logger.LogInformation("Booking failed!!");
             }
         }
     }
 }
Beispiel #5
0
        public static void SeedDemoData(IPandaRepository pandaRepo)
        {
            var products = pandaRepo.GetAllProducts();

            if (!products.Any())
            {
                pandaRepo.AddMarketProduct(new MarketProduct("LAX"));
                pandaRepo.IncreaseMarketProductAmount("LAX", 100);
                pandaRepo.SetMarketProductPrice("LAX", 25.50m);

                pandaRepo.AddMarketProduct(new MarketProduct("ISI"));
                pandaRepo.IncreaseMarketProductAmount("ISI", 1000);
                pandaRepo.SetMarketProductPrice("ISI", 3.99m);

                pandaRepo.AddMarketProduct(new MarketProduct("WOT"));
                pandaRepo.IncreaseMarketProductAmount("WOT", 200);
                pandaRepo.SetMarketProductPrice("WOT", 1234567.89m);
            }

            var traders = pandaRepo.GetAllTraders();

            if (!traders.Any())
            {
                pandaRepo.AddNewTrader("WBuffett");
                pandaRepo.AddNewTrader("JBelfort");
                var jb = pandaRepo.GetTraderByName("JBelfort");
                var bt = new BankTransaction(jb, 20000.0m);
                pandaRepo.BookBankTransaction(bt);

                var lax = pandaRepo.GetMarketProduct("LAX");
                var bo  = new BookingOrder(jb, lax, 4, 30.0m);
                pandaRepo.PlaceBookingOrder(bo);

                var unbookdBo = pandaRepo.GetBookingOrdersUnbooked();

                pandaRepo.BookBookingOrder(bo);
            }
        }
Beispiel #6
0
 public TradersController(IPandaRepository pandaRepository)
 {
     pandaRepo = pandaRepository;
 }
Beispiel #7
0
 public IndexModel(IPandaRepository pandaRepository)
 {
     pandaRepo = pandaRepository;
 }
Beispiel #8
0
 public PublicApiController(IPandaRepository pandaRepository)
 {
     pandaRepo = pandaRepository;
 }
Beispiel #9
0
 public ValuesController(IPandaRepository pandaRepository)
 {
     pandaRepo = pandaRepository;
 }
Beispiel #10
0
 private static void SetupProduct(IPandaRepository pandaRepo, string productCode, int initialAmount, decimal initalPrice)
 {
     pandaRepo.AddMarketProduct(new MarketProduct(productCode));
     pandaRepo.IncreaseMarketProductAmount(productCode, initialAmount);
     pandaRepo.SetMarketProductPrice(productCode, initalPrice);
 }
Beispiel #11
0
 public BookingModel(IPandaRepository pandaRepository)
 {
     pandaRepo = pandaRepository;
 }