internal static void Seed(BillsPaymentSystemContext context, int count, List <User> users)
        {
            for (int i = 0; i < count; i++)
            {
                var payment = new PaymentMethod()
                {
                    User        = users[IntGenerator.GenerateInt(0, users.Count - 1)],
                    Type        = PaymentType.BankAccount,
                    BankAccount = new BankAccount()
                    {
                        BankAccountId = i,
                        //Balance = PriceGenerator.GeneratePrice(),
                        BankName  = TextGenerator.FirstName() + "\'s Bank",
                        SwiftCode = TextGenerator.Password(10)
                    },
                    BankAccountId = i
                };
                payment.BankAccount.Deposit(PriceGenerator.GeneratePrice());

                var result = new List <ValidationResult>();
                if (AttributeValidator.IsValid(payment, result))
                {
                    context.PaymentMethods.Add(payment);
                }
                else
                {
                    Console.WriteLine(string.Join(Environment.NewLine, result));
                }

                payment = new PaymentMethod()
                {
                    User       = users[IntGenerator.GenerateInt(0, users.Count - 1)],
                    Type       = PaymentType.CreditCard,
                    CreditCard = new CreditCard()
                    {
                        CreditCardId   = i,
                        ExpirationDate = DateGenerator.FutureDate(),
                        Limit          = PriceGenerator.GeneratePrice(),
                        //MoneyOwed = PriceGenerator.GeneratePrice()
                    },
                    CreditCardId = i
                };
                payment.CreditCard.Withdraw(PriceGenerator.GeneratePrice());

                result = new List <ValidationResult>();
                if (AttributeValidator.IsValid(payment, result))
                {
                    context.PaymentMethods.Add(payment);
                }
                else
                {
                    Console.WriteLine(string.Join(Environment.NewLine, result));
                }
            }

            context.SaveChanges();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            double equity         = 10000;
            double lotSize        = 1;
            double commissionRate = 0.67;
            double tradeZone      = 15;
            double spread         = 0;
            double maximumTurns   = 100;
            double recoveryZone   = tradeZone / 3;
            var    marketPosition = MarketPosition.Long;
            double profitMargin   = 0;
            double pipFactor      = 0.0001;
            double slippage       = 1;

            var _zoneRecovery = new ZoneRecovery(lotSize, pipFactor, commissionRate, profitMargin, slippage);

            var random = new Random(unchecked ((int)DateTime.Now.Ticks));

            var priceGenerator = new PriceGenerator(DateTime.Now.Millisecond, 4, 10, random.Next(800, 1300), 0.004, 0.002, spread);

            var initQuote = priceGenerator.NextQuote;

            double midPrice = (initQuote.Bid + initQuote.Ask) / 2d;

            var session = _zoneRecovery.CreateSession(marketPosition, initQuote.Bid, initQuote.Ask, tradeZone, recoveryZone);

            int ticks = 0;

            int positionCount = 1;

            while (true)
            {
                var nextQuote = priceGenerator.NextQuote;
                midPrice = (nextQuote.Bid + nextQuote.Ask) / 2d;
                //Console.WriteLine($"Bid: {nextQuote.Bid}, Ask: {nextQuote.Ask}");
                (var result, _) = session.PriceAction(nextQuote.Bid, nextQuote.Ask);
                ticks++;
                if (result == PriceActionResult.TakeProfitLevelHit || session.RecoveryTurns > maximumTurns)
                {
                    equity += (session.UnrealizedNetProfit * lotSize);
                    Console.WriteLine($"TP Hit in {session.RecoveryTurns} turns, {session.TotalLotSize} lots, {ticks} ticks, {session.UnrealizedNetProfit} returns, {equity} equity balance");
                    Thread.Sleep(500);
                    if (positionCount > 300)
                    {
                        return;
                    }
                    session = _zoneRecovery.CreateSession(marketPosition, nextQuote.Bid, nextQuote.Ask, tradeZone, recoveryZone);
                    ticks   = 0;
                    positionCount++;
                }
            }
        }
コード例 #3
0
        public void BasicTest()
        {
            //Arrange
            var random = new Random(unchecked ((int)DateTime.Now.Ticks));

            var priceGenerator = new PriceGenerator(DateTime.Now.Millisecond, 4, 10, random.Next(800, 1300), 0.004, 0.002, 3);

            //Act
            var nextQuote = priceGenerator.NextQuote;

            //Assert
            Assert.True(nextQuote.Bid > 0 && nextQuote.Ask > 0);
        }
コード例 #4
0
        public void ReceiveRequest(IRequestEvent requestEvent)
        {
            var split = requestEvent.Subject.Split('/');

            if (split.Length == 5 && split[4].Length > 0)
            {
                var priceGenerator = new PriceGenerator(requestEvent.Subject, publisher, dataSource.Logger);
                timer.Elapsed += (sender, e) => priceGenerator.Emit();

                activeSubscriptions.Add(requestEvent.Subject, timer);
            }
            else
            {
                var errorEvent = publisher.MessageFactory.CreateSubjectErrorEvent(requestEvent.Subject, SubjectError.NotFound);
                publisher.PublishSubjectErrorEvent(errorEvent);
            }
        }
コード例 #5
0
        internal static void InitialCourseSeed(StudentSystemContext context, int count)
        {
            for (int i = 0; i < count; i++)
            {
                var date   = DateGenerator.RandomDate();
                var course = new Course()
                {
                    Name      = TextGenerator.FirstName(),
                    StartDate = date,
                    EndDate   = DateGenerator.DateAfter(date),
                    Price     = PriceGenerator.GeneratePrice()
                };

                context.Courses.Add(course);
            }

            context.SaveChanges();
        }
コード例 #6
0
        public ActionResult UserAppointmentCreate(string initCharge, string endCharge, string podTypeStr, int stationId)
        {
            var user = db.Users.Find(User.Identity.GetUserId());

            if (user.Appointments.Where(x => x.AppointmentStatusId == AppointmentStatusEnum.Pending ||
                                        x.AppointmentStatusId == AppointmentStatusEnum.Ongoing).Count() > 0)
            {
                TempData["msg"] = "Existe outro agendamento, se pretender, elimine-o e crie um novo.";
                return(RedirectToAction("AppointmentsRecords", "Users", null));
            }

            var      station = db.Stations.Find(stationId);
            var      pods    = station.Pods.Where(p => p.PodType.Name == podTypeStr && p.isActive);
            var      podType = podTypeStr == nameof(PodTypeEnum.Fast) ? PodTypeEnum.Fast : PodTypeEnum.Normal;
            DateTime init;
            DateTime end;

            if (DateTime.TryParseExact(initCharge, "MM/dd/yyyy HH:mm:ss", new CultureInfo("pt-PT", false), DateTimeStyles.None, out init) == false ||
                DateTime.TryParseExact(endCharge, "MM/dd/yyyy HH:mm:ss", new CultureInfo("pt-PT", false), DateTimeStyles.None, out end) == false)
            {
                return(View());
            }

            double cost = PriceGenerator.CalculatePrice(init, end, station.Prices, podType);

            if (cost > user.Wallet)
            {
                TempData["msg"] = "Dinheiro insuficiente, para efectuar agendamento tem de conter: " + cost + "€ .";
                return(RedirectToAction("AddMoney", "Users", null));
            }

            Pod pod = pods.ToList().Find(p => (p.Appointments
                                               .All(a => a.Start > end.AddMinutes(5) ||
                                                    a.End.AddMinutes(5) < init)) ||
                                         p.Appointments.Count == 0);

            return(View(new Appointment()
            {
                Start = init, End = end, Pod = pod, PodId = pod.Id, Cost = cost, Station = station, Company = station.Company, User = user
            }));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "Id,CompanyId,StationId,PodId,UserId,Cost,Start,End,AppointmentStatusId")] Appointment appointment)
        {
            var employee = db.Employees.Find(User.Identity.GetUserId());
            var user     = db.Users.Find(appointment.UserId);

            if (user.Appointments.Where(x => x.AppointmentStatusId == AppointmentStatusEnum.Pending ||
                                        x.AppointmentStatusId == AppointmentStatusEnum.Ongoing).Count() > 0)
            {
                return(RedirectToAction("AppointmentRecords", "Users"));
            }

            var prices = db.Stations.Where(s => s.Id == appointment.StationId).Select(s => s.Prices).FirstOrDefault();

            if (prices.Count == 0)
            {
                return(new HttpStatusCodeResult(404, "Error:" + "The station prices are not estabilished. Appointment will not be created."));
            }

            List <Pod> pods = null;

            if (User.IsInRole(nameof(RoleEnum.Employee)))
            {
                pods = employee.Station.Pods.ToList();
            }
            else
            {
                pods = employee.Company.Stations.Where(x => x.Id == appointment.StationId)
                       .SingleOrDefault().Pods.ToList();
            }

            appointment.PodId = pods.Find(p => p.Appointments
                                          .All(a => a.Start > appointment.End.AddMinutes(5) ||
                                               a.End.AddMinutes(5) < appointment.Start) || p.Appointments.Count == 0).Id;

            appointment.AppointmentStatusId = AppointmentStatusEnum.Pending;

            appointment.CompanyId = employee.CompanyId;
            appointment.Cost      = PriceGenerator.CalculatePrice(appointment.Start, appointment.End, prices, db.Pods.Find(appointment.PodId).PodType.Id);

            if (appointment.Cost > user.Wallet)
            {
                return(new HttpStatusCodeResult(404, "Error:" + "The user don''t have enough money to make the appointment"));
            }

            if (ModelState.IsValid)
            {
                user.Wallet         -= appointment.Cost * 0.15;
                db.Entry(user).State = EntityState.Modified;

                db.Appointments.Add(appointment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StationId = new SelectList(db.Stations.Where(s => s.CompanyId == employee.CompanyId), "Id", "ComercialName");

            List <ApplicationUser> users = new List <ApplicationUser>();
            var db_users = db.Users.ToList();

            foreach (ApplicationUser elem in db_users)
            {
                var roleId = elem.Roles.ToList()[0].RoleId;
                var role   = db.Roles.Where(x => x.Id == roleId).FirstOrDefault();

                if (role.Name == nameof(RoleEnum.User))
                {
                    users.Add(elem);
                }
            }
            ViewBag.UserId = new SelectList(users, "Id", "Email"); //TODO: only put users of primary user role
            return(View(appointment));
        }