Viewing File: /home/ubuntu/codegamaai-test/broker_bot/archive/not_help (1).py
import requests
import finnhub
import datetime
def historical_stock_data(symbol, interval):
API_KEY = "HKN1ON7PGO1OJBDQ"
base_url = "https://www.alphavantage.co/query"
params = {
"function": "TIME_SERIES_INTRADAY",
"symbol": symbol,
"interval": "5min",
"apikey": API_KEY
}
response = requests.get(base_url, params=params)
if response.status_code == 200:
return response.json()
else:
return f"Error fetching data: {response.status_code}"
def stock_info(symbol):
finnhub_client = finnhub.Client(api_key="cnk08ihr01qvd1hlrdfgcnk08ihr01qvd1hlrdg0")
response = finnhub_client.quote(symbol=symbol)
"""
{'c': 859.64, 'd': 7.31, 'dp': 0.8576, 'h': 860.97, 'l': 834.1701, 'o': 852.7, 'pc': 852.33, 't': 1709672400}
"""
time_stamp = response['t']
# Convert timestamp to human readable format
response['t'] = datetime.datetime.fromtimestamp(time_stamp).strftime('%Y-%m-%d %H:%M:%S')
# Convert the response to a more readable format
response = {
"Current Price": response['c'],
"Change": response['d'],
"Change Percent": response['dp'],
"High Price": response['h'],
"Low Price": response['l'],
"Opening Price": response['o'],
"Previous Close": response['pc'],
"Timestamp": response['t']
}
response_string = f"""Stock Info for {symbol}:\n
Current Price: {response['Current Price']}\n
Change: {response['Change']}\n
Change Percent: {response['Change Percent']}\n
High Price: {response['High Price']}\n
Low Price: {response['Low Price']}\n
Opening Price: {response['Opening Price']}\n
Previous Close: {response['Previous Close']}\n
Timestamp: {response['Timestamp']} UTC\n"""
return response_string
Back to Directory
File Manager