Make purchased based on current prices | fix register issue
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
import yfinance as yf
|
||||||
|
|
||||||
|
def getCurrentPrice(symbol):
|
||||||
|
ticker = yf.Ticker(symbol)
|
||||||
|
data = ticker.history(period="1d", interval="1m")
|
||||||
|
current_price = data['Close'].iloc[-1]
|
||||||
|
return current_price
|
||||||
@@ -119,6 +119,10 @@
|
|||||||
async Task LoginSession(){
|
async Task LoginSession(){
|
||||||
string dbPrefix = $"[{userName.ToLower()}]:"; // Set the DB prefix for the get and set
|
string dbPrefix = $"[{userName.ToLower()}]:"; // Set the DB prefix for the get and set
|
||||||
string passwordhash = dbDriver.Get( dbPrefix + "password" ); // Pull the password hash
|
string passwordhash = dbDriver.Get( dbPrefix + "password" ); // Pull the password hash
|
||||||
|
if (string.IsNullOrEmpty(passwordhash)){
|
||||||
|
loginError = "no account found with that username";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (BCrypt.Verify( passWord, passwordhash )){ // If the password is valid
|
if (BCrypt.Verify( passWord, passwordhash )){ // If the password is valid
|
||||||
List<PurchasedStock>? stocks = JsonConvert.DeserializeObject<List<PurchasedStock>>( dbDriver.Get( dbPrefix + "Stocks" ) );
|
List<PurchasedStock>? stocks = JsonConvert.DeserializeObject<List<PurchasedStock>>( dbDriver.Get( dbPrefix + "Stocks" ) );
|
||||||
bool moneyLoaded = float.TryParse(dbDriver.Get( dbPrefix + "money" ), out float moneyResult);
|
bool moneyLoaded = float.TryParse(dbDriver.Get( dbPrefix + "money" ), out float moneyResult);
|
||||||
@@ -148,6 +152,11 @@
|
|||||||
TrackedStocks = new List<PurchasedStock>(),
|
TrackedStocks = new List<PurchasedStock>(),
|
||||||
Money = 1000
|
Money = 1000
|
||||||
};
|
};
|
||||||
|
(bool, string) result = PaymentProcessor.CreatePayment(Session.UserName);
|
||||||
|
if (!result.Item1){
|
||||||
|
resultError = result.Item2;
|
||||||
|
}
|
||||||
|
PaymentKey = result.Item2;
|
||||||
}else{
|
}else{
|
||||||
loginError = "account is taken";
|
loginError = "account is taken";
|
||||||
}
|
}
|
||||||
@@ -243,7 +252,6 @@
|
|||||||
|
|
||||||
string buyStockSymbol = "";
|
string buyStockSymbol = "";
|
||||||
string buyStockQuantity = "";
|
string buyStockQuantity = "";
|
||||||
float StockPrice = 0;
|
|
||||||
void buyStock(){
|
void buyStock(){
|
||||||
if (Session != null){
|
if (Session != null){
|
||||||
string dbPrefix = $"[{userName.ToLower()}]:";
|
string dbPrefix = $"[{userName.ToLower()}]:";
|
||||||
@@ -254,8 +262,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Stock Price
|
||||||
|
float stockPrice = aiModule.GetCurrentPrice( buyStockSymbol );
|
||||||
|
|
||||||
// Try Pay for the stock
|
// Try Pay for the stock
|
||||||
(bool, string) result = PaymentProcessor.TryPayment(PaymentKey, QuantityResult * StockPrice);
|
(bool, string) result = PaymentProcessor.TryPayment(PaymentKey, QuantityResult * stockPrice);
|
||||||
if (!result.Item1){
|
if (!result.Item1){
|
||||||
resultError = result.Item2;
|
resultError = result.Item2;
|
||||||
return;
|
return;
|
||||||
@@ -264,7 +275,7 @@
|
|||||||
// Add the stock
|
// Add the stock
|
||||||
Session.TrackedStocks.Add( new PurchasedStock(){
|
Session.TrackedStocks.Add( new PurchasedStock(){
|
||||||
Symbol = buyStockSymbol.ToUpper(),
|
Symbol = buyStockSymbol.ToUpper(),
|
||||||
PurchasePrice = StockPrice,
|
PurchasePrice = stockPrice,
|
||||||
Quantity = QuantityResult,
|
Quantity = QuantityResult,
|
||||||
PurchaseDate = DateTime.Now
|
PurchaseDate = DateTime.Now
|
||||||
} );
|
} );
|
||||||
|
|||||||
@@ -50,6 +50,16 @@ namespace Controllers.PythonInterop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float GetCurrentPrice(string StockSymbol) {
|
||||||
|
using (Py.GIL()) {
|
||||||
|
dynamic price = Py.Import("currentprice");
|
||||||
|
using (dynamic x = price.getCurrentPrice(StockSymbol)) {
|
||||||
|
float CurrentPrice = (float)x;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user