Allow selling
This commit is contained in:
@@ -41,11 +41,9 @@
|
||||
<div>
|
||||
<div><h2>Actions</h2></div>
|
||||
@if (Debounce){
|
||||
<button @onclick="pull">@pullButtonText</button>
|
||||
<button @onclick="train">@trainButtonText</button>
|
||||
<button @onclick="predict">@predictButtonText</button>
|
||||
}else{
|
||||
<button disabled>@pullButtonText</button>
|
||||
<button disabled>@trainButtonText</button>
|
||||
<button disabled>@predictButtonText</button>
|
||||
}
|
||||
@@ -73,6 +71,7 @@
|
||||
<p>Purchased Price: @cur.PurchasePrice</p>
|
||||
<p>Purchased Quantity: @cur.Quantity</p>
|
||||
<p>Purchased Date: @cur.PurchaseDate.ToString("M-dd-yyyy")</p>
|
||||
<button @onclick="() => {sellStock(cur);}">Sell All</button>
|
||||
</div>
|
||||
<div>
|
||||
<span>-></span>
|
||||
@@ -170,30 +169,10 @@
|
||||
|
||||
// AI Stuff
|
||||
|
||||
string pullButtonText = "Pull Data";
|
||||
string trainButtonText = "Train AI";
|
||||
string trainButtonText = "Force Retrain AI";
|
||||
string predictButtonText = "Predict AI";
|
||||
string resultError = "";
|
||||
|
||||
bool Debounce = true;
|
||||
async Task pull(){
|
||||
resultError = "";
|
||||
if (Debounce){
|
||||
Debounce = false;
|
||||
pullButtonText = "Do not refresh the page. The data is pulling.";
|
||||
await Task.Delay(1);
|
||||
Task thread = new Task(async () => {
|
||||
aiModule.PullAI();
|
||||
pullButtonText = "Data pulled";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Task.Delay(2000);
|
||||
pullButtonText = "Pull Data";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
Debounce = true;
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
async Task train(){
|
||||
resultError = "";
|
||||
@@ -294,4 +273,36 @@
|
||||
PaymentKey = result.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
void sellStock(PurchasedStock stock){
|
||||
string dbPrefix = $"[{userName.ToLower()}]:";
|
||||
if (Session != null){
|
||||
|
||||
// Get sell price
|
||||
float sellPrice = stock.Quantity * aiModule.GetCurrentPrice( stock.Symbol );
|
||||
|
||||
// Try to sell the stock
|
||||
(bool, string) result = PaymentProcessor.TrySell(PaymentKey, sellPrice);
|
||||
if (!result.Item1){
|
||||
resultError = result.Item2;
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove Stock
|
||||
Session.TrackedStocks.Remove(stock);
|
||||
dbDriver.Set( dbPrefix + "Stocks", Newtonsoft.Json.JsonConvert.SerializeObject(Session.TrackedStocks) );
|
||||
|
||||
// Reload the users money
|
||||
bool moneyLoaded = float.TryParse(dbDriver.Get( dbPrefix + "money" ), out float moneyResult);
|
||||
Session.Money = moneyLoaded ? moneyResult : 1000;
|
||||
|
||||
// Reset the Impodent Key
|
||||
result = PaymentProcessor.CreatePayment(Session.UserName);
|
||||
if (!result.Item1){
|
||||
resultError = "[New payment session failed] : " + result.Item2;
|
||||
return;
|
||||
}
|
||||
PaymentKey = result.Item2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user