Untitled
unknown
plain_text
3 years ago
3.0 kB
12
Indexable
from django.shortcuts import render
from openbb_terminal.sdk import openbb
from django.http import HttpResponse
import pandas as pd
import requests
import certifi
from urllib.request import urlopen
import json
import os
from dotenv import load_dotenv
load_dotenv()
def home(request):
# Load API keys from .env file
load_dotenv()
openbb.api_key = os.getenv("OPENBB_API_KEY")
openbb.financialmodelingprep_api_key = os.getenv("API_KEY_FINANCIALMODELINGPREP")
print(os.getenv("API_KEY_FINANCIALMODELINGPREP"))
# Get financial metrics for AAPL
metrics = openbb.stocks.fa.metrics("AAPL")
# Check if metrics is None
if metrics is None:
print("No metrics returned for AAPL")
else:
# Print the metrics and the type of the metrics variable
print(metrics)
print(type(metrics))
# Print some of the metrics
print(f"Current price: {metrics['Current Price']}")
print(f"EPS: {metrics['EPS']}")
print(f"ROE: {metrics['ROE']}")
# # configure()
# api_key = "b9a63ce321bc74d39371e7ad4438a512"
# symbol = "AAPL"
# url = f"https://api.openbb.co/v1/quote?symbol={symbol}"
# headers = {
# "Content-Type": "application/json",
# "Authorization": f"Bearer {api_key}"
# }
# response = requests.get(url, headers=headers)
# if response.status_code == 200:
# data = response.json()
# print(f"Latest stock quote for {symbol}: {data['last_price']}")
# else:
# print(f"Error retrieving stock quote: {response.status_code} - {response.text}")
# print(openbb.keys.fmp)
# opi = os.environ.get("API_KEY_FINANCIALMODELINGPREP")
# openbb.keys.fmp = opi
# print(openbb.keys.fmp)
# url = ("https://financialmodelingprep.com/api/v3/financial-statement-symbol-lists?apikey=b9a63ce321bc74d39371e7ad4438a512")
# print(opi)
# # openbb.openbb_terminal.keys.fmp = os.getenv("apikey")
# # openbb.apikey['fmp'] = "b9a63ce321bc74d39371e7ad4438a512"
# # return HttpResponse(openbb.stocks.fa.income("AAPL"), openbb.stocks.fa.income("AAPL"))
# # return HttpResponse(openbb.stocks.fa.income("AAPL"))
# # return HttpResponse(openbb.economy.events())
# s = requests.Session()
# # YOUR_API_KEY = 'b9a63ce321bc74d39371e7ad4438a512'
# # url = ("https://financialmodelingprep.com/api/v3/financial-statement-symbol-lists?apikey={os.getenv('api_key')}")
# response = urlopen(url, cafile=certifi.where())
# data = response.read().decode("utf-8")
# # print(json.loads(data))
# stock_data = openbb.stocks.fa.metrics("AAPL")
# # economy_data = openbb.economy.events()
# # print("INCOME STATEMENT")
# # print(type(stock_data))
# # print(stock_data.iloc[:,[2,3]])
# # print(stock_data["2022-09-30"])
# # stock_data.set_index("2021-09-30", inplace = True)
# # print(stock_data.loc["Net income"])
return HttpResponse(metrics)
Editor is loading...