Beispiel #1
0
def add_stock(market, ticker):
    try:
        stock = Stock(market, ticker)
        stock.generate_metrics()
        if stock.data and stock.data['price']:
            stock_list_entry = StockListEntry(market.upper(), ticker.upper())
            db.session.add(stock_list_entry)
            db.session.commit()
        return stock
    except Exception as e:
        logger.error(traceback.format_exc())
    def test_generate_metrics(self):
        with self.client:
            stock = Stock('NASDAQ', 'AAPL')
            stock.generate_metrics()
            self.assertTrue(stock.data['price'])
            self.assertTrue(stock.data['current_ratio'])
            self.assertTrue(stock.data['quick_ratio'])
            self.assertTrue(stock.data['return_on_equity'])
            self.assertTrue(stock.data['debt_equity_ratio'])
            self.assertTrue(stock.data['net_profit_margin'])
            self.assertTrue(stock.data['free_cash_flow'])
            self.assertTrue(stock.data['price_to_earnings_ratio'])

            stock = Stock('NASDAQ', 'AAPLL')
            stock.generate_metrics()
            self.assertFalse(stock.data)
Beispiel #3
0
def get_stocks_from_google():
    try:
        stocks = []
        stock_list_entries = StockListEntry.query.all()

        for stock_list_entry in stock_list_entries:
            stock = Stock(stock_list_entry.market, stock_list_entry.ticker)
            stock.generate_metrics()

            for key, value in stock.data.items():
                setattr(stock_list_entry, key, value)

            db.session.commit()
            stocks.append(object_to_dict(stock_list_entry))

        return stocks
    except Exception as e:
        logger.error(traceback.format_exc())