def download_stock_data(index: str, symbols: list, count: int, resolution="D"): client = Finnhub.Client(api_key=API_KEY) for symbol in symbols: stock_candle = client.stock_candle(symbol=symbol, resolution=resolution, count=count) if stock_candle["s"] != "ok": continue directory = os.path.join(os.curdir, "data", index) if not os.path.exists(directory): os.mkdir(directory) file_path = os.path.join(directory, "{}.csv".format(symbol)) with open(file_path, "w", newline='') as fobj: field_names = [key for key in stock_candle.keys() if key != "s"] writer = csv.DictWriter(fobj, fieldnames=field_names) writer.writeheader() for i in range(len(stock_candle[field_names[0]])): obj = {key: stock_candle[key][i] for key in field_names} writer.writerow(obj) time.sleep(1)
def finnhub_price(share_symbol): from finnhub import client as Finnhub client = Finnhub.Client(api_key=config['finnhub_api_key']) price = client.quote(symbol = share_symbol) ##print("api_call") return price
from finnhub import client as Finnhub client = Finnhub.Client(api_key="********************") # Get real-time update on the number of COVID-19 (Coronavirus) cases in the US client.covid() # Get general information of a company client.company_profile(symbol="NFLX") # Get latest company's CEO compensation client.ceo_compensation(symbol="NFLX") # Get latest analyst recommendation trends client.recommendation(symbol="NFLX") # Get latest price target consensus client.price_target(symbol="NFLX") # Get latest stock upgrade and downgrade client.upgrade_downgrade(symbol="NFLX") # Get company option chain client.option_chain(symbol="NFLX") # Get company peers client.peers(symbol="NFLX") # Get company quarterly earnings client.earnings(symbol="NFLX")
# https://github.com/s0h3ck/finnhub-api-python-client from finnhub import client as Finnhub import pandas as pd API_key = '' client = Finnhub.Client(api_key=API_key) AAPL_candle = client.stock_candle(symbol="AAPL", resolution="D", count=3650) status = AAPL_candle.pop('s') if status == 'ok': AAPL_df = pd.DataFrame.from_dict(AAPL_candle) # Forex and crpyto has limit 500 # Get general information of a company client.company_profile(symbol="NFLX") # Get latest company's CEO compensation client.ceo_compensation(symbol="NFLX") # Get latest analyst recommendation trends client.recommendation(symbol="NFLX") # Get latest price target consensus client.price_target(symbol="NFLX") # Get latest stock upgrade and downgrade client.upgrade_downgrade(symbol="NFLX") # Get company option chain
import discord import asyncio import os import time import datetime from finnhub import client as Finnhub # api docs: https://finnhub.io/docs/api import requests FINNHUB_API_TOKEN = os.environ.get('FINNHUB_API_TOKEN') FINNHUB_RS_API_TOKEN = os.environ.get('FINNHUB_API_TOKEN_4') finnhub_client = Finnhub.Client(api_key=FINNHUB_API_TOKEN) finnhub_rs_client = Finnhub.Client(api_key=FINNHUB_RS_API_TOKEN) async def rs(ctx, ticker): """Sends the stock_price_today() embedded message and updates it every minute for 5 minutes. Parameters ---------- ctx : discord.ext.commands.Context context of the command ticker : string stock ticker (ex. AAPL, MSFT, TSLA, ^DJI, BTCUSDT) """ status, embed = await stock_price_today(ctx, ticker, True) message = await ctx.send(embed=embed) if status != 'ok': # if not okay then don't edit return
from finnhub import client as Finnhub import pandas as pd import datetime client = Finnhub.Client(api_key="burenjf48v6u5d1lc1cg") #public key normalize_flag = True divide_by_max_flag = False start = int(datetime.datetime(2017, 12, 1).timestamp()) end = int(datetime.datetime(2020, 12, 31).timestamp()) resolution = "W" # 1, 5, 15, 30, 60, D, W, M value_type = "h" # c v h l def normalize(numbers): maximum = max(numbers) minimum = min(numbers) return [(x - minimum) / (maximum - minimum) for x in numbers] def divide_by_max(numbers): maximum = max(numbers) return [x / maximum for x in numbers] def plot_finnhub_data(symbol, finnhub_data, value_type): if normalize_flag: finnhub_data[value_type] = normalize(finnhub_data[value_type]) if divide_by_max_flag: finnhub_data[value_type] = divide_by_max(finnhub_data[value_type])
hub.sentiment('TSLA') x = hub.economic_code().name.unique() hub.economic_calendar().to_csv('FH_Econ_Caledanr.csv') ########################################################################################## from finnhub import client as Finnhub client = Finnhub.Client(api_key=token) pd.DataFrame(client.exchange()).to_csv("exchanges.csv") # List supported stock exchanges # List supported forex symbols for every supported forex exchanges exchg = pd.read_csv("..\\Tkrs_metadata\\exchanges.csv") # file was downloaded earlier with client.exchange() df = pd.concat((json_normalize(client.stock_symbol(exchange=exch)).assign(source = exch) for exch in exchg.FinnHub_code[exchg.Main==1].tolist()), ignore_index = True) client.company_profile(symbol="NFLX") # PREMIUM: Get general information of a company json_normalize(client.company_profile_base(symbol="NFLX")) # Free: Get general information of a company
import discord import os import time import re import datetime from PIL import Image, ImageFont, ImageDraw from finnhub import client as Finnhub # api docs: https://finnhub.io/docs/api import requests import matplotlib import mplfinance import stocks import pandas as pd FINNHUB_CHART_API_TOKEN_2 = os.environ.get('FINNHUB_API_TOKEN_2') FINNHUB_CRYPTO_API_TOKEN_3 = os.environ.get('FINNHUB_API_TOKEN_3') finnhub_chart_client = Finnhub.Client(api_key=FINNHUB_CHART_API_TOKEN_2) finnhub_other_crypto_client = Finnhub.Client( api_key=FINNHUB_CRYPTO_API_TOKEN_3) async def chart(ctx, ticker, timeframe, chart_type): """Called from stock_candle() and stock_line() in bot.py Creates the stock chart for the specified ticker and timeframe Parameters ---------- ctx : discord.ext.commands.Context context of the command ticker : string stock ticker (ex. AAPL, MSFT, TSLA, ^DJI, BTCUSDT) timeframe : string
from finnhub import client as Finnhub from os import environ client = Finnhub.Client(api_key=environ['FH_API_KEY']) def get_candles(symbol, resolution='D', count=7): response = client.stock_candle(symbol=symbol, resolution=resolution, count=count) return response
#from yahoo_fin import stock_info as si #si.get_live_price("appl") #API Key P6Qq2bpJ8nZgCkjyoRq9 # import quandl # quandl.ApiConfig.api_key = "P6Qq2bpJ8nZgCkjyoRq9" # data = quandl.get("FRED/GDP", start_date="2001-12-31", end_date="2005-12-31") from finnhub import client as Finnhub import pprint #Imports as dictionary client = Finnhub.Client(api_key="bpv6h7vrh5rabkt31o30") #TO_Stocks = client.stock_symbol(exchange="TO") #pprint.pprint(client.company_profile(symbol="SRT-UN.TO")) #print("PRICE") print(client.price_target(symbol="SRT-UN.TO"))
result_df = pd.concat([info_df,FIP_df,CR_df], axis=1, join ="inner") result_df """# Print To Excel""" #Exports to Local Data. Need to download to computer for now result_df.to_excel('FIP_FEBRUARY.xlsx',index=True) """# Testing RSI api's""" !pip install finnhub-python from finnhub import client as Finnhub from finnhub import client as Finnhub client = Finnhub.Client(api_key="bsu3fpv48v6r5qhbp2ug") symbol = "BLNK" temp = client.aggregate_indicator(symbol, resolution='D') print(temp) # temp['technicalAnalysis']['signal'] temp['trend']['adx'] temp['trend']['trending'] # pattern recognition analysis temp = client.pattern_recognition(symbol,resolution='D') temp