forked from ssahadevan-pivotal/engineapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetYahooFinanaceApiData.py
67 lines (44 loc) · 1.35 KB
/
getYahooFinanaceApiData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
from decouple import config
import json
API_KEY= config('API_KEY')
url = "https://yfapi.net/v6/finance/quote"
# Function to get the data from the Yahoo API's
# result has the json data
def getResults(ticker):
#querystring = {"symbols":"AAPL,BTC-USD,EURUSD=X"}
#querystring = {"symbols":"AAPL"}
querystring = {"symbols": ticker }
headers = {
'x-api-key': API_KEY
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
apiData=json.loads(response.text)
print (apiData)
keys=apiData.keys()
print(keys)
result=apiData["quoteResponse"]["result"][0]
resultKeys=result.keys()
print (result)
print (resultKeys)
for x,y in result.items():
print (x, y)
print ("Market Price for " + ticker )
print (result["regularMarketPrice"])
return result
# Get the value for the given key
def getValueFromResult( result , key):
value=result[key]
return value
def getRecommendation( result ):
recommendation="None"
forwardPe = getValueFromResult(myResult, "forwardPE")
if ( forwardPe < 20 ) :
recommendation="Buy"
return recommendation
myTicker='AAPL'
myResult=getResults(myTicker)
print( getValueFromResult(myResult, "fiftyTwoWeekHighChangePercent") )
print( getValueFromResult(myResult, "forwardPE") )
print( getRecommendation(myResult) )