Example #1
0
def populate_stock_real_time():
    try:
        stocks_prices = get_stocks_real_time([stock.ticker for stock in Stock.all()])
    except:
        try:
            stocks_prices = scrape_yahoo_site([stock.ticker for stock in Stock.all()])
        except:
            try:
                stocks_prices = get_stocks_real_time_google([stock.ticker for stock in Stock.all()])
            except:
                return
    for stock_price in stocks_prices:
        stock = Stock.where('ticker', stock_price['ticker']).first()
        if stock:
            stock_price['info']['stock_id'] = stock.id
            HalfHourlyQuote(stock_price['info']).save()
def populate_stock_real_time():
    try:
        stocks_prices = get_stocks_real_time([stock.ticker for stock in Stock.all()])
    except:
        return
    for stock_price in stocks_prices:
        stock = Stock.where('ticker', stock_price['ticker']).first()
        if stock:
            stock.hourly_quotes().save(HourlyQuote(stock_price['info']))
Example #3
0
def populate_stock_real_time():
    try:
        stocks_prices = get_stocks_real_time(
            [stock.ticker for stock in Stock.all()])
    except:
        return
    for stock_price in stocks_prices:
        stock = Stock.where('ticker', stock_price['ticker']).first()
        if stock:
            stock.hourly_quotes().save(HourlyQuote(stock_price['info']))
def convert_hourly_to_daily():
    for stock in Stock.all():
        older_quotes = HalfHourlyQuote.where('stock_id',
                                             stock.id).older().get_models()
        try:
            close_quote = older_quotes[0]
        except:
            return
        info = {
            'date': close_quote.datetime.format('YYYY-MM-DD'),
            'close_price': close_quote.price
        }
        stock.daily_quotes().save(DailyQuote(info))
        for old_quote in older_quotes:
            old_quote.delete()
def populate_stock_history(beg, end):
    for stock in Stock.all():
        try: 
            stock_history = get_stock_history(stock.ticker, BEG, END)
        except:
            print('ERROR: could not get stock history for \n {}'.format(stock.ticker))
            print(sys.exc_info())
            continue
        for day in stock_history:
            try:
                stock_quotes = stock.daily_quotes()
            except:
                print('ERROR: could not get stocks for \n {}'.format(stock.ticker))
                raise sys.exc_info()
            if not stock_quotes.save(DailyQuote(day)):
                print('ERROR: could not save daily quote for \n {}'.format(day))
Example #6
0
def populate_stock_history(beg, end):
    for stock in Stock.all():
        try:
            stock_history = get_stock_history(stock.ticker, BEG, END)
        except:
            print('ERROR: could not get stock history for \n {}'.format(
                stock.ticker))
            print(sys.exc_info())
            continue
        for day in stock_history:
            try:
                stock_quotes = stock.daily_quotes()
            except:
                print('ERROR: could not get stocks for \n {}'.format(
                    stock.ticker))
                raise sys.exc_info()
            if not stock_quotes.save(DailyQuote(day)):
                print(
                    'ERROR: could not save daily quote for \n {}'.format(day))
Example #7
0
def queryByCondition():
    form = request.form.to_dict()
    r = Stock.all(**form)
    return make_response(jsonify(r))