Spaces:
Running
Running
Robert Castagna
commited on
Commit
·
f9d5fa2
1
Parent(s):
fe859cf
relative import error
Browse files- pages/2_Portfolio_Builder.py +15 -1
pages/2_Portfolio_Builder.py
CHANGED
|
@@ -16,7 +16,8 @@ import platform
|
|
| 16 |
import datetime
|
| 17 |
import asyncio
|
| 18 |
import nest_asyncio
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
def open_nested_event_loop():
|
| 22 |
# Check if there is an existing event loop, if not, create a new one
|
|
@@ -36,6 +37,19 @@ def get_positions(account):
|
|
| 36 |
tickers.append([position.contract.symbol, position.position, position.marketPrice])
|
| 37 |
return tickers
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
@st.cache_data
|
| 40 |
def get_list_of_tickers():
|
| 41 |
comp_info = get_finnhub_data('/stock/symbol?exchange=US')
|
|
|
|
| 16 |
import datetime
|
| 17 |
import asyncio
|
| 18 |
import nest_asyncio
|
| 19 |
+
import json
|
| 20 |
+
import requests
|
| 21 |
|
| 22 |
def open_nested_event_loop():
|
| 23 |
# Check if there is an existing event loop, if not, create a new one
|
|
|
|
| 37 |
tickers.append([position.contract.symbol, position.position, position.marketPrice])
|
| 38 |
return tickers
|
| 39 |
|
| 40 |
+
def get_finnhub_data(example: str) -> json:
|
| 41 |
+
"""
|
| 42 |
+
Pass in the "example" string from the API documentation. It changes for every endpoint.
|
| 43 |
+
|
| 44 |
+
:param1 example: '/company-news?symbol=AAPL&from=2023-08-15&to=2023-08-20'
|
| 45 |
+
"""
|
| 46 |
+
base_url = 'https://finnhub.io/api/v1//'
|
| 47 |
+
|
| 48 |
+
token = f"&token={os.environ['finnhub_token']}"
|
| 49 |
+
|
| 50 |
+
request = requests.get(f"{base_url}{example}{token}")
|
| 51 |
+
return request.json()
|
| 52 |
+
|
| 53 |
@st.cache_data
|
| 54 |
def get_list_of_tickers():
|
| 55 |
comp_info = get_finnhub_data('/stock/symbol?exchange=US')
|