async def get_stock_quote(ctx, ticker, price=None): # Instantiating Stock class stocks = Stock(ticker, price, FINN_API_KEY) # Returning stock data stock_quote = await stocks.get_stock_quote() # Response when only a ticker is passed to the bot command default_msg = (tabulate( [["Current Price", "Open", "Previous Close", "High", "Low"], [ stock_quote['currentPrice'], stock_quote['openPrice'], stock_quote['prevClose'], stock_quote['highPrice'], stock_quote['lowPrice'] ]], headers="firstrow")) if price == None: await ctx.send("Loading...") await ctx.send(f'```{default_msg}```') elif price == 'current': await ctx.send("Current Price: " + stock_quote['currentPrice']) elif price == 'open': await ctx.send("Open Price: " + stock_quote['openPrice']) elif price == 'close': await ctx.send("Previous Close Price: " + stock_quote['prevClose']) elif price == 'high': await ctx.send("Today's High: " + stock_quote['highPrice']) elif price == 'low': await ctx.send("Today's Low: " + stock_quote['lowPrice']) else: await ctx.send(stock_quote)
def load_orders(self, path_orders, path_dividends, country): print('Loading orders and dividends for {} wallet...'.format(country)) orders = pd.read_csv(path_orders, sep=';', index_col=0, header=0) dividends = pd.read_csv(path_dividends, sep=';', index_col=0, header=0) list_stocks = [] for ticker in orders.index.unique(): list_orders = [] for row in orders.loc[[ticker]].iterrows(): list_orders.append( Order(row[1]['Date'], row[1]['Amount'], row[1]['Price'], row[1]['Kind'])) list_dividends = [] if ticker in dividends.index: for row in dividends.loc[[ticker]].iterrows(): list_dividends.append( Dividend(row[1]['Date'], row[1]['Value'], row[1]['Kind'])) list_stocks.append(Stock(ticker, list_orders, list_dividends)) return Wallet(list_stocks, country)
async def get_company_profile(ctx, ticker, price=None): stocks = Stock(ticker, price, FINN_API_KEY) company_profile = await stocks.get_company_profile_data() # print(company_profile) companyName = 'Company Name: ' + company_profile['Company_Name'] companyCountry = 'Country: ' + company_profile['Company_Country'] companyIPO = 'IPO: ' + company_profile['Company_IPO'] companyTicker = 'Ticker Symbol: ' + company_profile['Company_Ticker_Symbol'] companyWebsite = 'Website: ' + company_profile['Company_Website'] companyIndustry = 'Industry: ' + company_profile['Company_Industry'] companyLogo = company_profile['Company_Logo'] logo = Embed() logo.set_image(url=companyLogo) profile_msg = companyName + "\n" + companyCountry + "\n" + companyIPO + "\n" + companyTicker + "\n" + companyWebsite + "\n" + companyIndustry await ctx.send(embed=logo) await ctx.send(f'```{profile_msg}```')
def __init__(self, nbrStocks=10): self.stocks = [Stock() for i in range(nbrStocks)]
from classes.stock import Stock from classes.plot import Plot #timeframes = [ "1d", "1m", "3m", "6m", "1y", "2y", "5y", "ytd", "20190301" ] dates = ["20190304", "20190116"] stocks = [] # for timeframe in timeframes: for date in dates: #stock = Stock( "MSFT", timeframe ) stock = Stock(symbol="MSFT", date=date) stock.fetch_chart() stocks.append(stock) data_points = [] time_frame_idx = 0 for stock in stocks: close_prices = stock.get_close_prices() print("close_prices: " + str(close_prices)) xvals = list(range(0, len(close_prices))) # xyvals = ( xvals,close_prices,timeframes[ time_frame_idx ] ) xyvals = (xvals, close_prices, dates[time_frame_idx]) data_points.append(xyvals) time_frame_idx += 1 plot = Plot(rows=2, cols=4, plot_name="MSFT Stock Charts") for xyvals in data_points: if (plot.add_subplot(xyvals)): plot.plot() else: print("In app.py, error occured")
class MainProgram: """ class docstring """ def __init__(self): self.stock = Stock() self.main() def main(self): """ mathod docstring """ while True: print("\n1 - see the stock") print("2 - add to stock") print("3 - remove from stock") choice = input("> ") if choice == "1": self.stock.show_stock() elif choice == "2": self.stock.add_component() elif choice == "3": print("\n1 - remove processor") print("2 - remove graphic card") print("3 - remove hdd") print("4 - remove RAM") component = input("> ") self.remove_from_stock(component) else: break def remove_from_stock(self, component): """ mathod docstring """ if component == "1": self.stock.remove_from_stock(self.stock.processor_stock) elif component == "2": self.stock.remove_from_stock(self.stock.graphic_card_stock) elif component == "3": self.stock.remove_from_stock(self.stock.hdd_stock) elif component == "4": self.stock.remove_from_stock(self.stock.ram_stock)
def __init__(self): self.stock = Stock() self.main()
f = FinanceAPI() print(f) # Check for API Key and load if Path("financeAPI/Secret_Key.txt").is_file(): with open('financeAPI/Secret_Key.txt') as file: key = file.read() f.registerKey_(key) else: print("No file with API key found") exit() #f.start_stock_screener() Square = Stock('SQ') #PayPal = Stock('PYPL') #CDProjekt = Stock('7CD') #Visa = Stock('V') #Mastercard = Stock('MA') #Microsoft = Stock('MSFT') # Read data from file if it exists: #if Path("data/"+name_testdict+".json").is_file(): # with open("data/"+name_testdict+".json") as file: # company_dict = json.load(file) #else: # company_dict = f.build_dict(name_testdict) # with open("data/"+name_testdict+".json",'w') as file: # # Serialize data into file: # json.dump(company_dict, file)
from classes.stock import Stock from classes.plot import Plot #timeframes = [ "1d", "1m", "3m", "6m", "1y", "2y", "5y", "ytd", "20190301" ] #dates = [ "20190304", "20190116" ] dates = ["6m"] stocks = [] # for timeframe in timeframes: for date in dates: #stock = Stock( "MSFT", timeframe ) # stock = Stock( symbol = "MSFT", date = date ) stock = Stock(symbol="MSFT", time_range=date, last_date="20190304") stock.fetch_chart() stocks.append(stock) data_points = [] time_frame_idx = 0 for stock in stocks: close_prices = stock.get_close_prices() # print ( "close_prices: " + str(close_prices) ) xvals = list(range(0, len(close_prices))) # xyvals = ( xvals,close_prices,timeframes[ time_frame_idx ] ) xyvals = (xvals, close_prices, dates[time_frame_idx]) data_points.append(xyvals) time_frame_idx += 1 plot = Plot(rows=1, cols=1, plot_name="MSFT Stock Charts") for xyvals in data_points: if (plot.add_subplot(xyvals)): plot.plot() else: