This commit is contained in:
NikolajDanger
2020-08-09 14:57:10 +02:00
parent 69b9064bb0
commit 95e1ef7e40
2 changed files with 8 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import finnhub, json
import json
from funcs import getName
from .money import checkBalance, addMoney
@ -13,7 +13,7 @@ def getPrice(symbol : str,finnhubClient):
def getPortfolio(user : str,finnhubClient):
with open("resources/games/investments.json") as f:
data = json.load(f)
if user not in data or data[user] == {}:
return f"{getName(user)} does not have a stock portfolio."
else:
@ -56,9 +56,8 @@ def buyStock(user : str, stock : str, buyAmount : int,finnhubClient):
with open("resources/games/investments.json", "w") as f:
json.dump(data,f,indent=4)
return f"{getName(user)} bought {buyAmount} GwendoBucks worth of {stock} stock"
return f"{getName(user)} bought {buyAmount} GwendoBucks worth of {stock} stock"
else:
return f"{stock} is not traded on the american market."
else:
@ -70,9 +69,9 @@ def sellStock(user : str, stock : str, sellAmount : int,finnhubClient):
if sellAmount > 0:
with open("resources/games/investments.json", "r") as f:
data = json.load(f)
stock = stock.upper()
if user in data and stock in data[user]:
value = data[user][stock]
stockPrice = getPrice(stock,finnhubClient)
@ -89,7 +88,7 @@ def sellStock(user : str, stock : str, sellAmount : int,finnhubClient):
with open("resources/games/investments.json", "w") as f:
json.dump(data,f,indent=4)
return f"{getName(user)} sold {sellAmount} GwendoBucks worth of {stock} stock"
else:
return f"You don't have enough {stock} stocks to do that"
@ -120,7 +119,7 @@ def parseInvest(content: str, user : str,finnhubClient):
return "The command must be given as \"!invest buy [stock] [amount of GwendoBucks to purchase with]\""
else:
return "You must give both a stock name and an amount of gwendobucks you wish to spend."
elif content.startswith("sell"):
commands = content.split(" ")
if len(commands) == 3: