示例#1
0
 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()
示例#2
0
 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")
示例#3
0
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)  
示例#4
0
 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()
示例#5
0
    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")
示例#6
0
 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()
示例#7
0
文件: app.py 项目: JonahR/rueb-stock
def stockPriceCmd():
    print("Stock price for:", end=" ")
    ticker = input()
    lookedup_stock = Stock(ticker)
    print(lookedup_stock.getPrice())