Updated load_share_price.py
This commit is contained in:
parent
8862636fd7
commit
19d52c0ed1
@ -9,19 +9,42 @@ import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
import investpy
|
||||
import pandas
|
||||
import requests
|
||||
import yfinance
|
||||
from currency_converter import CurrencyConverter
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
def thread_function(s):
|
||||
my_share_info = yfinance.Ticker(s)
|
||||
my_share_data = my_share_info.info
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=s, products=['stocks'], countries=['germany'], n_results=1)
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = round(float(recent_data.iloc[-1]["Close"]), 2)
|
||||
|
||||
if my_share_data['regularMarketPrice'] is not None:
|
||||
payload = {
|
||||
"symbol": s,
|
||||
"price": float(my_share_data['regularMarketPrice']),
|
||||
"isin": s,
|
||||
"price": round(float(stock_price), 2),
|
||||
"time": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
||||
}
|
||||
|
||||
requests.post(os.getenv("API_URL") + '/symbol', json=payload, headers={'Authorization': 'Bearer ' + token})
|
||||
except RuntimeError:
|
||||
my_converter = CurrencyConverter()
|
||||
|
||||
search_result = investpy.search_quotes(text=s, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = my_converter.convert(float(recent_data.iloc[-1]["Close"]), str(currency), 'EUR')
|
||||
|
||||
payload = {
|
||||
"isin": s,
|
||||
"price": round(float(stock_price), 2),
|
||||
"time": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
||||
}
|
||||
|
||||
|
@ -12,5 +12,7 @@ pytest~=7.1.2
|
||||
pytest-cov
|
||||
marshmallow~=3.15.0
|
||||
faker~=13.7.0
|
||||
yfinance~=0.1.70
|
||||
requests~=2.27.1
|
||||
requests~=2.27.1
|
||||
investpy~=1.0.8
|
||||
pandas~=1.4.1
|
||||
currencyconverter~=0.16.12
|
Loading…
Reference in New Issue
Block a user