예제 #1
0
def calculate():
    url = 'http://www.google.com/'
    timeout = 2
    try:
        _ = requests.get(url, timeout=timeout)
        symbol = (request.form['ticketSymbol'])
        try:
            data = YahooFinancials(symbol)
            date = datetime.datetime.now(tzlocal())
            timezone = str(time.asctime(time.localtime(time.time())))
            strftime = date.strftime("%Z")
            financials = data.get_stock_quote_type_data()
            name = str(financials.get(symbol).get('longName'))
            sym = financials.get(symbol).get('symbol')
            current = str(data.get_current_price())
            currentchange = str(round(data.get_current_change(), 2))
            percentchange = str(
                round(data.get_current_percent_change() * 100, 2)) + '%'
            return render_template('output.html',
                                   symbol=symbol,
                                   data=data,
                                   timezone=timezone,
                                   strftime=strftime,
                                   financials=financials,
                                   name=name,
                                   sym=sym,
                                   current=current,
                                   currentchange=currentchange,
                                   percentchange=percentchange)
        except:
            return 'INVALID SYMBOL'
    except:
        return 'NO INTERNET CONNECTION'
예제 #2
0
from yahoofinancials import YahooFinancials
import pandas as pd
import time
## dd/mm/yyyy format
print(time.strftime("%d/%m/%Y"))
## 12 hour format ##
print(time.strftime("%I:%M:%S"))
holdings = open(
    "holdings.txt"
)  #create a file called "holdings" and add your stock list to it

for line in holdings:
    Name_of_stock = line.split(',')[0]
    Ticker_symbol = line.split(',')[1].split('*')[0]
    #print (Name_of_stock,Ticker_symbol)
    stockInfo = YahooFinancials(
        Ticker_symbol)  #import the stock details from yahoo finance
    stockpricechange = format(
        100 * float(stockInfo.get_current_change()) /
        (float(stockInfo.get_current_price()) -
         float(stockInfo.get_current_change())), '.2f')
    #For ease of viewing this allows you to see if the stock has risen or fallen
    if float(stockpricechange) > 0.00:
        print Name_of_stock, Ticker_symbol, "^^^", "UP", stockpricechange, "^^^", stockInfo.get_currency(
        ), stockInfo.get_current_price()
    elif float(stockpricechange) <= 0.00:
        print Name_of_stock, Ticker_symbol, "***", "DOWN", stockpricechange, "***", stockInfo.get_currency(
        ), stockInfo.get_current_price()
    # Written by Tom Meany please add suff you think is useful!
예제 #3
0
from yahoofinancials import YahooFinancials
from servertools import SlackComm

stonk = '6098.T'

yf = YahooFinancials(stonk)

price = yf.get_current_price()
change = yf.get_current_change()
pct_change = yf.get_current_percent_change()

scom = SlackComm('viktor')

jpyusd = 1 / 104.48
units = 100
strike_price = 4542
msg = f'{units:,.0f} shares of `{stonk}` are now worth *`{(price - strike_price) * jpyusd * units:+,.2f}`* USD' \
      f' more than when you got it'

blocks = [
    scom.bkb.make_context_section(
        f':trending_up_and_down: time for stonk updates !'),
    scom.bkb.make_block_section(msg),
    scom.bkb.make_context_section([
        f'JPY/USD: {jpyusd:.4f}, strike price: {strike_price}, current price: {price}'
    ])
]

scom.st.send_message('C01M49M5EEM', message='stonk update', blocks=blocks)