Save symbol price in database
This commit is contained in:
33
api/load_share_price.py
Normal file
33
api/load_share_price.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import datetime
|
||||
import os
|
||||
import threading
|
||||
|
||||
import requests
|
||||
import yfinance
|
||||
|
||||
|
||||
def thread_function(s):
|
||||
my_share_info = yfinance.Ticker(s)
|
||||
my_share_data = my_share_info.info
|
||||
|
||||
if my_share_data['regularMarketPrice'] is not None:
|
||||
payload = {
|
||||
"symbol": s,
|
||||
"price": float(my_share_data['regularMarketPrice']),
|
||||
"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})
|
||||
|
||||
|
||||
username = os.getenv('ADMIN_EMAIL')
|
||||
password = os.getenv('ADMIN_PASSWORD')
|
||||
|
||||
token = requests.post(os.getenv("API_URL") + '/user/login', json={"email": username, "password": password}).json()['data']['token']
|
||||
|
||||
response = requests.get(os.getenv("API_URL") + '/symbols', headers={'Authorization': 'Bearer ' + token}).json()['data']
|
||||
|
||||
for symbol in response:
|
||||
x = threading.Thread(target=thread_function, args=(symbol,))
|
||||
x.start()
|
||||
|
Reference in New Issue
Block a user