Exemplo n.º 1
0
def getAllStockData(ticker):
    '''Get a few random tickers.'''
    stock = Share(ticker)
    stock.refresh()
    data = {
        'name': stock.get_name(),
        'price': stock.get_price(),
        'change': stock.get_change(),
        'volume': stock.get_volume(),
        'prev_close': stock.get_prev_close(),
        'open': stock.get_open(),
        'avg_daily_volume': stock.get_avg_daily_volume(),
        'stock_exchange': stock.get_stock_exchange,
        'market_cap': stock.get_market_cap(),
        'book_value': stock.get_book_value(),
        'ebitda': stock.get_ebitda(),
        'dividend_share': stock.get_dividend_share(),
        'dividend_yield': stock.get_dividend_yield(),
        'earnings_share': stock.get_earnings_share(),
        'days_high': stock.get_days_high(),
        'days_low': stock.get_days_low(),
        'year_high': stock.get_year_high(),
        'year_low': stock.get_year_low(),
        '50day_moving_avg': stock.get_50day_moving_avg(),
        '200day_moving_avg': stock.get_200day_moving_avg(),
        'price_earnings_ratio': stock.get_price_earnings_ratio(),
        'price_earnings_growth_ratio': stock.get_price_earnings_growth_ratio(),
        'get_price_sales': stock.get_price_sales(),
        'get_price_book': stock.get_price_book(),
        'get_short_ratio': stock.get_short_ratio(),
        'trade_datetime': stock.get_trade_datetime(),
        'percent_change_from_year_high': stock.get_percent_change_from_year_high(),
        'percent_change_from_year_low': stock.get_percent_change_from_year_low(),
        'change_from_year_low': stock.get_change_from_year_low(),
        'change_from_year_high': stock.get_change_from_year_high(),
        'percent_change_from_200_day_moving_average': stock.get_percent_change_from_200_day_moving_average(),
        'change_from_200_day_moving_average': stock.get_change_from_200_day_moving_average(),
        'percent_change_from_50_day_moving_average': stock.get_percent_change_from_50_day_moving_average(),
        'change_from_50_day_moving_average': stock.get_change_from_50_day_moving_average(),
        'EPS_estimate_next_quarter': stock.get_EPS_estimate_next_quarter(),
        'EPS_estimate_next_year': stock.get_EPS_estimate_next_year(),
        'ex_dividend_date': stock.get_ex_dividend_date(),
        'EPS_estimate_current_year': stock.get_EPS_estimate_current_year(),
        'price_EPS_estimate_next_year': stock.get_price_EPS_estimate_next_year(),
        'price_EPS_estimate_current_year': stock.get_price_EPS_estimate_current_year(),
        'one_yr_target_price': stock.get_one_yr_target_price(),
        'change_percent_change': stock.get_change_percent_change(),
        'divended_pay_date': stock.get_dividend_pay_date(),
        'currency': stock.get_currency(),
        'last_trade_with_time': stock.get_last_trade_with_time(),
        'days_range': stock.get_days_range(),
        'years_range': stock.get_year_range()
    }
    return data
Exemplo n.º 2
0
class Symbol(object):

    def __init__(self, symbol, s_date=None, e_date=None):
        self.log=Logging()
        self.name=symbol
        self.created=datetime.datetime.utcnow()
        self.log.info("created {}".format(self.name))
        try:
            self.share=Share(symbol)
        except:
            self.log.error("platform is offline or not connecting")

        if s_date and e_date:
            self.begin=s_date
            self.end=e_date
            try:
                self.share=Share(symbol)
                self.data=self.share.get_historical(self.begin, self.end)
                self.log.refresh("{} data collected".format(self.name))
            except:
                self.log.error("platform is offline or not connecting")
    
    def refresh_data(self, s_date=None, e_date=None):
        if s_date and e_date:
            try:
                share=Share(self.name)
                self.begin=s_date
                self.end=e_date
                share.get_historical(s_date, e_date)
                self.log.refresh("{} data collected".format(self.name))
            except:
                self.log.error("platform is offline or not connecting")

    def market_cap(self):
        try:
            self.market_cap = self.share.get_market_cap()
            self.log.info("{} market cap refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")
        
    def earnings_per_share(self):
        try:
            self.eps = self.share.get_earnings_share()
            self.log.info("{} eps refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")

    def moving_average_50(self):
        try:
            self.moving_average_50 = self.share.get_50day_moving_average()
            self.log.info("{} 50 day moving ave refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")

    #implement TODO
    def nday_moving_average(self, n):
        try:
            self.moving_average_n = None
            self.log.info("{} {} day moving ave refreshed".format(self.name, n))
        except:
            self.log.error("platform is offline or not connecting")

    def price_earnings_ratio(self):
        try:
            self.price_to_earnings = self.share.get_price_earnings_ratio()
            self.log.info("{} price to earnings refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")


    def book_value(self):
        try:
            self.book = self.share.get_price_book()
            self.log.info("{} book value refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")

    def year_high(self):
        try:
            self.year_high = self.share.get_change_from_year_high()
            self.log.info("{} year high change refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")

    def year_low(self):
        try:
            self.year_low = self.share.get_change_from_year_low()
            self.log.info("{} year low change refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")

    def target_price(self):
        try:
            self.year_target = self.share.get_change_from_year_high()
            self.log.info("{} year target change refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")
    
    def year_range(self):
        try:
            self.year_range = self.share.get_change_from_year_high()
            self.log.info("{} year range change refreshed".format(self.name))
        except:
            self.log.error("platform is offline or not connecting")
Exemplo n.º 3
0
print "get_price_earnings_ratio:", tesla.get_price_earnings_ratio()
print "get_price_earnings_growth_ratio:", tesla.get_price_earnings_growth_ratio(
)
print "get_price_sales:", tesla.get_price_sales()
print "get_price_book:", tesla.get_price_book()
print "get_short_ratio:", tesla.get_short_ratio()
print "get_trade_datetime:", tesla.get_trade_datetime()
# "a:", print tesla.get_historical(start_date, end_date)
# "a:", print tesla.get_info()
print "get_name:", tesla.get_name()
print "refresh:", tesla.refresh()
print "get_percent_change_from_year_high:", tesla.get_percent_change_from_year_high(
)
print "get_percent_change_from_year_low:", tesla.get_percent_change_from_year_low(
)
print "get_change_from_year_low:", tesla.get_change_from_year_low()
print "get_change_from_year_high:", tesla.get_change_from_year_high()
print "get_percent_change_from_200_day_moving_average:", tesla.get_percent_change_from_200_day_moving_average(
)
print "get_change_from_200_day_moving_average:", tesla.get_change_from_200_day_moving_average(
)
print "get_percent_change_from_50_day_moving_average:", tesla.get_percent_change_from_50_day_moving_average(
)
print "get_change_from_50_day_moving_average:", tesla.get_change_from_50_day_moving_average(
)
print "get_EPS_estimate_next_quarter:", tesla.get_EPS_estimate_next_quarter()
print "get_EPS_estimate_next_year:", tesla.get_EPS_estimate_next_year()
print "get_ex_dividend_date:", tesla.get_ex_dividend_date()
print "get_EPS_estimate_current_year:", tesla.get_EPS_estimate_current_year()
print "get_price_EPS_estimate_next_year:", tesla.get_price_EPS_estimate_next_year(
)