public async Task <DealerResponse> AddAuctionBundle(AuctionBundle auctionBundle) { DealerResponse response = new DealerResponse(); List <object> payload = new List <object>(); payload.Add(auctionBundle); double numberToBuy = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture); List <AuctionBundleForDb> list = await GetAuctionBundles(); AuctionBundleForDb bundleForSymbol = await GetAuctionBundleForSymbol(auctionBundle.Symbol, App.User); if (bundleForSymbol == null) { AuctionBundleForDb dbBundle = new AuctionBundleForDb(); dbBundle.Number = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture); dbBundle.MedianValue = auctionBundle.CloseValueAtDateBought; dbBundle.Symbol = auctionBundle.Symbol; dbBundle.Name = auctionBundle.Name; dbBundle.PersonID = App.User.Id; response = App.MiddleDealer.OnEvent(Databases.MessageAction.AddedAuctionBundle, payload); if (response == DealerResponse.Success) { await connection.InsertAsync(dbBundle); } } else { payload.Add(bundleForSymbol); response = App.MiddleDealer.OnEvent(Databases.MessageAction.AddedAuctionBundle, payload); } return(response); }
public async Task <DealerResponse> SellAuctionBundle(AuctionBundle auctionBundle) { DealerResponse response = new DealerResponse(); List <object> payload = new List <object>(); payload.Add(auctionBundle); AuctionBundleForDb bundleForSymbol = await GetAuctionBundleForSymbol(auctionBundle.Symbol, App.User); if (bundleForSymbol != null) { payload.Add(bundleForSymbol); response = App.MiddleDealer.OnEvent(Databases.MessageAction.SellAuctionBundle, payload); } else { return(DealerResponse.NoAuctionsFromCompany); } return(response); }
private async void MakeAuctions() { bool gotResponse = await auctions.GetAuction(symbol, stock); if (!gotResponse) { await DisplayAlert("", "We can't find the stock market, sorry!", "OK"); } else { for (int i = stock.Count - 1; i >= 0; i--) { inverseStock.Add(stock[i]); } for (int i = 6; i >= 0; i--) { Auction s = stock[i]; Random random = new Random(); MEntry mEntry = new MEntry(float.Parse(s.CloseValue.ToString())); mEntry.Label = s.Date.ToString(); mEntry.ValueLabel = s.CloseValue.ToString(); string c = GetRandomColor(); while (c == lastColor) { c = GetRandomColor(); } lastColor = c; mEntry.Color = SKColor.Parse(c); entries.Add(mEntry); counter++; } SellAuctionIcon.IsEnabled = true; BuyAuctionIcon.IsEnabled = true; LineChart chart = new LineChart() { Entries = entries }; chart.LineAreaAlpha = 0; chart.MaxValue = float.Parse(entries[0].Value.ToString(), App.DoubleCultureInfo); chart.MinValue = float.Parse(entries[5].Value.ToString(), App.DoubleCultureInfo); chart.LabelTextSize = 25; AuctionChart.Chart = chart; AuctionChart.IsEnabled = true; AuctionBundle bindingBundle = new AuctionBundle(); bindingBundle.Symbol = symbol; bindingBundle.CloseValueAtDateBought = stock[0].CloseValue; singularyStock.Add(bindingBundle); AuctiomGrid.BindingContext = SingularyStock[0]; double profit = (inverseStock[0].CloseValue - inverseStock[inverseStock.Count - 1].CloseValue) / inverseStock[inverseStock.Count - 1].CloseValue; profit /= 100; //PriceLabel.Text = string.Format("{0:0.000000} %", profit); Person person = App.User; // BuyButton.IsEnabled = true; AuctionBundleForDb boughtBundle = await App.LocalDataBase.GetAuctionBundleForSymbol(symbol, person); if (boughtBundle != null && boughtBundle.Number != 0) { // SellButton.IsEnabled = true; } } }
public DealerResponse OnMessageReceived(MessageAction message, List <object> payload) { Person person = App.User; DealerResponse response = DealerResponse.Unreachable; switch (message) { case MessageAction.AddedAuctionBundle: { person = App.User; var auctionBundle = payload[0] as AuctionBundle; double numberToBuy = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture); if (payload.Count == 1) { double auxNumber = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture); double amountToPay = auctionBundle.CloseValueAtDateBought * auxNumber; person.Amount -= amountToPay; AuctionBundleForHistory bundle = new AuctionBundleForHistory(auctionBundle.Symbol, auctionBundle.Name, auctionBundle.OpenValueAtDateBought, auctionBundle.CloseValueAtDateBought, auctionBundle.DateBought, auctionBundle.Number, AuctionAction.BOUGHT);; bundle.PersonID = person.Id; App.LocalDataBase.AddAuctionBundleToHistory(bundle); App.LocalDataBase.SavePerson(person); response = DealerResponse.Success; } else { AuctionBundleForDb bundleForSymbol = payload[1] as AuctionBundleForDb; bundleForSymbol.MedianValue = ((bundleForSymbol.MedianValue * bundleForSymbol.Number) + (numberToBuy * auctionBundle.CloseValueAtDateBought)) / (double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture) + bundleForSymbol.Number); bundleForSymbol.Number += double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture); AuctionBundleForHistory bundle = new AuctionBundleForHistory(auctionBundle.Symbol, auctionBundle.Name, auctionBundle.OpenValueAtDateBought, auctionBundle.CloseValueAtDateBought, auctionBundle.DateBought, auctionBundle.Number, AuctionAction.BOUGHT);; bundle.PersonID = person.Id; person.Amount -= numberToBuy * auctionBundle.CloseValueAtDateBought; App.LocalDataBase.SavePerson(person); App.LocalDataBase.AddAuctionBundleToHistory(bundle); SaveAuctionBundle(bundleForSymbol); response = DealerResponse.Success; } break; } case MessageAction.GetAllDepositedMoney: { person = App.User; List <Income> incomes = new List <Income>(); foreach (object o in payload) { incomes.Add((Income)o); } foreach (Income i in incomes) { person.Amount += i.AbsoluteValue + i.OverTimeAddition; DeleteIncome(i); } return(DealerResponse.Success); break; } case MessageAction.ManageIncomes: { List <Income> incomes = new List <Income>(); for (int i = 0; i < payload.Count - 1; i++) { incomes.Add((Income)payload[i]); } AppSettings setting = payload[payload.Count - 1] as AppSettings; foreach (Income i in incomes) { if (i.Times != -1) { if (i.TimesLeft > 0 && i.LastRealPayment != null) { DateTime lastRealLogin = DateTime.Parse(setting.LastRealLogin); TimeSpan span = lastRealLogin.Subtract(DateTime.Parse(i.LastRealSupposedPayment)); double appMinutes = span.TotalMinutes * App.Multiplier; if (appMinutes > i.Frequency) { // se sustrage/se adauga la persoana cat trebuie sa plateasca double timesToSubtract = appMinutes / i.Frequency; timesToSubtract = Math.Floor(timesToSubtract); i.TimesLeft -= int.Parse(Math.Floor(timesToSubtract).ToString()); i.LastSupposedPayment = (DateTime.Parse(i.LastSupposedPayment).AddMinutes(timesToSubtract * i.Frequency)).ToString(); i.LastRealSupposedPayment = (DateTime.Parse(i.LastRealSupposedPayment).AddMinutes((timesToSubtract * i.Frequency) / App.Multiplier)).ToString(); i.LastAppPayment = setting.LastLogin; i.LastRealPayment = setting.LastRealLogin; SaveIncome(i); person.Amount += (i.AbsoluteValue * timesToSubtract); SavePerson(person); } } } else { switch (i.Category) { case IncomeCategory.DefaultDeposit: { DateTime lastRealLogin = DateTime.Parse(setting.LastRealLogin); TimeSpan span = lastRealLogin.Subtract(DateTime.Parse(i.LastRealSupposedPayment)); double appMinutes = span.TotalMinutes * App.Multiplier; if (appMinutes > i.Frequency) { double timesToSubtract = appMinutes / i.Frequency; timesToSubtract = Math.Floor(timesToSubtract); i.OverTimeAddition += Math.Floor(timesToSubtract) * ((i.DepositInterest / 100) * i.AbsoluteValue); i.LastSupposedPayment = (DateTime.Parse(i.LastSupposedPayment).AddMinutes(timesToSubtract * i.Frequency)).ToString(); i.LastRealSupposedPayment = (DateTime.Parse(i.LastRealSupposedPayment).AddMinutes((timesToSubtract * i.Frequency) / App.Multiplier)).ToString(); i.LastAppPayment = setting.LastLogin; i.LastRealPayment = setting.LastRealLogin; SaveIncome(i); } break; } case IncomeCategory.Job: { DateTime lastRealLogin = DateTime.Parse(setting.LastRealLogin); TimeSpan span = lastRealLogin.Subtract(DateTime.Parse(i.LastRealSupposedPayment)); double appMinutes = span.TotalMinutes * App.Multiplier; if (appMinutes > i.Frequency) { double timesToSubtract = appMinutes / i.Frequency; timesToSubtract = Math.Floor(timesToSubtract); // se adauga la person banii i.LastSupposedPayment = (DateTime.Parse(i.LastSupposedPayment).AddMinutes(timesToSubtract * i.Frequency)).ToString(); i.LastRealSupposedPayment = (DateTime.Parse(i.LastRealSupposedPayment).AddMinutes((timesToSubtract * i.Frequency) / App.Multiplier)).ToString(); i.LastAppPayment = setting.LastLogin; i.LastRealPayment = setting.LastRealLogin; person.Amount += i.AbsoluteValue * timesToSubtract; SavePerson(person); SaveIncome(i); } break; } } } } return(DealerResponse.Success); break; } case MessageAction.BuyCredit: { StationaryCredit credit = payload[0] as StationaryCredit; Income income = new Income(); income.Category = IncomeCategory.Credit; income.AbsoluteValue = (-1) * (((credit.Cost * (100 + credit.Interest)) / 100) / credit.Duration); income.Periodical = true; income.Frequency = 30; // contracttime, lastpayment, lastrealpayment, lastsupppayment, lastrealsupppayment income.Times = (int)credit.Duration; income.TimesLeft = (int)(income.Times); income.ContractTime = credit.DateBought.ToString(); income.LastRealPayment = credit.DateBought.ToString(); income.LastAppPayment = credit.AppDateBought.ToString(); income.LastRealSupposedPayment = credit.DateBought.ToString(); income.LastSupposedPayment = credit.AppDateBought.ToString(); AddIncome(income); response = DealerResponse.Success; break; } case MessageAction.SellAuctionBundle: { AuctionBundle auctionBundle = payload[0] as AuctionBundle; AuctionBundleForDb bundleForSymbol = payload[1] as AuctionBundleForDb; double numberToSell = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture); if ((bundleForSymbol.Number - numberToSell) >= 0) { bundleForSymbol.Number -= numberToSell; App.LocalDataBase.SaveAuctionBundle(bundleForSymbol); person.Amount += numberToSell * auctionBundle.CloseValueAtDateBought; AuctionBundleForHistory bundle = new AuctionBundleForHistory(auctionBundle.Symbol, auctionBundle.Name, auctionBundle.OpenValueAtDateBought, auctionBundle.CloseValueAtDateBought, auctionBundle.DateBought, auctionBundle.Number, AuctionAction.SOLD);; bundle.PersonID = person.Id; App.LocalDataBase.AddAuctionBundleToHistory(bundle); App.LocalDataBase.SavePerson(person); App.LocalDataBase.SaveAuctionBundle(bundleForSymbol); response = DealerResponse.Success; } else { return(DealerResponse.NotEnoughAuctions); } break; } } return(response); }
public async Task <int> SaveAuctionBundle(AuctionBundleForDb auctionBundle) { return(await connection.UpdateAsync(auctionBundle)); }
private async void AddBundleToStockPortfolio(AuctionBundle auctionBundle) { Person person = App.User; string numberToBuy = auctionBundle.Number; if (action == AuctionAction.BOUGHT) { string auctionNumber = auctionBundle.Number; double auxAuctionNumber = double.Parse(auctionNumber); if (person.Amount < (auctionBundle.CloseValueAtDateBought * auxAuctionNumber)) { await DisplayAlert("", "You do not have enough money", "OK"); } else { auctionBundle.PersonID = person.Id; DealerResponse response = await App.LocalDataBase.AddAuctionBundle(auctionBundle); if (response == DealerResponse.Success) { await DisplayAlert("", "Congratulations, you have just bought " + auctionNumber + " auctions", "OK"); await Navigation.PushAsync(new AuctionHouseView()); } } } else { AuctionBundleForDb boughtBundle = await App.LocalDataBase.GetAuctionBundleForSymbol(auctionBundle.Symbol, person); if (boughtBundle == null) { await DisplayAlert("", "You have not bought auctions from this company yet", "OK"); } else { double profit = (auctionBundle.OpenValueAtDateBought - boughtBundle.MedianValue) * double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture); ProfitLabel.Text = "You gain " + profit + " from transactioning " + auctionBundle.Number + " auctions from " + auctionBundle.Name; ProfitLabel.IsVisible = true; DealerResponse response = await App.LocalDataBase.SellAuctionBundle(auctionBundle); switch (response) { case DealerResponse.Success: { await DisplayAlert("", "Congratuations, you have just sold " + auctionBundle.Number, "OK"); //await Navigation.PushAsync(new AuctionHouseView()); break; } case DealerResponse.NoAuctions: { await DisplayAlert("", "You have no auctions", "OK"); break; } case DealerResponse.NoAuctionsFromCompany: { await DisplayAlert("", "You have not bought auctions froms this company yet or have sold them all", "OK"); break; } case DealerResponse.NotEnoughAuctions: { await DisplayAlert("", "You do not have enough auctions", "OK"); break; } } } } }