def buyStock(self, stockTicker): stockOBJ = Stock(stockTicker) if (self.liquidAssets < stockOBJ.getPrice()): raise ValueError( 'You do not have enough liquid assets to purchase this stock.') else: self.stocksBought[stockTicker] += 1 self.liquidAssets -= stockOBJ.getPrice()
def buyStock(self, ticker, quanity): s = Stock(ticker) if (s.exists()): if self.cash - quanity * float(s.getPrice()) >= 0: self.cash -= quanity * float(s.getPrice()) if ticker in self.stocks: self.stocks[ticker] += quanity else: self.stocks[ticker] = quanity else: print("You have insufficent funds for this trade")
class Graph: # sets the stock that the graph tracks def __init__(self, ticker): self.stock = Stock(ticker) # Live graph that follows stock value *needs a lot of work* def start(self): plt.axis([0, 10, 0, 1]) plt.ion() arr = [] for i in range(100): min = 10000 max = 0 curr = float(self.stock.getPrice()) if curr < min: min = curr if curr > max: max = curr plt.axis([0, i + 1, min - 1, max + 1]) arr.append(curr) plt.plot(arr) # Wait one second plt.pause(1) while True: plt.pause(0.05)
def sellStock(self, stockTicker): stockOBJ = Stock(stockTicker) if (self.stocksBought[stockTicker] == 0): raise ValueError('You do not have stocks of this ticker to sell.') else: self.stocksBought[stockTicker] -= 1 self.liquidAssets += stockOBJ.getPrice()
def sellStock(self, ticker, quanity): s = Stock(ticker) if self.stocks[ticker] - quanity >= 0: self.cash += quanity * float(s.getPrice()) self.stocks[ticker] -= quanity else: print("You do not have enough stock for this trade")
def updateTime(self, numDays): self.level.addNumDays(numDays) # update the stock prices for ticker in self.stockValues: # self.stockValues[ticker] = Stock(ticker, self.level.getCurrentDate()).getPrice() s = Stock(ticker) s.updatePriceWithDate(self.level.getCurrentDate()) self.stockValues[ticker] = s.getPrice() self.calculateTotalAssets()
def stockPriceCmd(): print("Stock price for:", end=" ") ticker = input() lookedup_stock = Stock(ticker) print(lookedup_stock.getPrice())