forked from carterabass/Estimize-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEstimize-API.py
220 lines (193 loc) · 9.59 KB
/
Estimize-API.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import requests
import pdb
import sys
from optparse import OptionParser
"""
-API requests should be made to http://api.estimize.com/
-You must supply your API key in the HTTP header X-Estimize-Key, otherwise you will receive a 403 Forbidden response
-Responses are in JSON. You need to specifiy in the HTTP header that content-type should be application/json (see example below)
-Parameters should be specified as query string parameters
-Successful responses will have a status code of 200
-Invalid requests will return a status code of 422 with a JSON object that specifies the errors as an array of strings
within the errors property
"""
url = "http://api.estimize.com"
headers = {"X-Estimize-Key" : "INSERT API KEY HERE!!!", "content-type" : "application/json"}
def request_company_information(ticker):
"""
Overview: returns a dictionary of the company information for the company specified with ticker
Required params: None
Optional params: None
Response:
-name: The name of the company
-ticker: The ticker/symbol for the company
"""
function_url = url + "/companies/%s" % ticker
req = requests.get(function_url, headers=headers)
if req.status_code != 200 : return None
return req.json()
def request_releases_for_company(ticker):
"""
Overview: returns a list of dictionaries of the past financial releases for the speficied company (by ticker)
Required params: None
Optional params: None
Response:
-fiscal_year: The fiscal year for the release
-fiscal_quarter: The fiscal quarter for the release
-release_date: The date of the release
-eps: The earnings per share for the specified fiscal quarter
-revenue: The revenue for the speified fiscal quarter
-wallstreet_eps_estimate: The estimated EPS from Wall Street
-wallstreet_revenue_estimate: The estimated revenue from Wall Street
-consensus_eps_estimate: The average estimated EPS by the Estimize community
-consensus_revenue_estimate: The average estimated revenue by the Estimize community
"""
function_url = url + "/companies/%s/releases" % ticker
req = requests.get(function_url, headers=headers)
if req.status_code != 200 : return None
return req.json()
def request_releases_for_company_for_year(ticker,year):
"""
Overview: returns a list of all the financial releases for the specified company(ticker) for the specified fiscal year(year)
Required params: None
Optional params: None
Response:
-fiscal_year: The fiscal year for the release
-fiscal_quarter: The fiscal quarter for the release
-release_date: The date of the release
-eps: The earnings per share for the specified fiscal quarter
-revenue: The revenue for the speified fiscal quarter
-wallstreet_eps_estimate: The estimated EPS from Wall Street
-wallstreet_revenue_estimate: The estimated revenue from Wall Street
-consensus_eps_estimate: The average estimated EPS by the Estimize community
-consensus_revenue_estimate: The average estimated revenue by the Estimize community
"""
function_url = url + "/companies/%s/releases/%s" % (ticker,year)
req = requests.get(function_url, headers=headers)
if req.status_code != 200 : return None
return req.json()
def request_releases_for_company_for_year_for_quarter(ticker,year,quarter):
"""
Overview: returns a dictionary of the financial release for the specified company(ticker) for the specified fiscal year(year)
for a specified quarter(quarter)
Required params: None
Optional params: None
Response:
-fiscal_year: The fiscal year for the release
-fiscal_quarter: The fiscal quarter for the release
-release_date: The date of the release
-eps: The earnings per share for the specified fiscal quarter
-revenue: The revenue for the speified fiscal quarter
-wallstreet_eps_estimate: The estimated EPS from Wall Street
-wallstreet_revenue_estimate: The estimated revenue from Wall Street
-consensus_eps_estimate: The average estimated EPS by the Estimize community
-consensus_revenue_estimate: The average estimated revenue by the Estimize community
"""
function_url = url + "/companies/%s/releases/%s/%s" % (ticker,year,quarter)
req = requests.get(function_url, headers=headers)
if req.status_code != 200 : return None
return req.json()
def request_estimates_for_company(ticker):
"""
Overview: returns all the estimates for a company (specified by ticker)
Required params: None
Optional params: None
Returns: an array of estimate objects where each estimate has the following properties
-id: the unique identifier for the estimate
-ticker: the ticker for the company being estimated
-fiscal_year: the fiscal year of the quarter being estimated
-fiscal_quarter: the fiscal quarter of the quarter being estimated
-eps: the estimated earnings per share for the company in the specified fiscal quarter
-revenue: the estimated revenue for the company in the specified fiscal quarter
-username: the author of the estimate
-created_at: the time that the estimate was created (UTC)
"""
function_url = url + "/companies/%s/estimates" % ticker
req = requests.get(function_url, headers=headers)
if req.status_code != 200 : return None
return req.json()
def request_estimates_for_company_for_year(ticker,year):
"""
Overview: returns all the estimates for a company (specified by ticker) for the specified fiscal year
Required params: None
Optional params: None
Returns: an array of estimate objects where each estimate has the following properties
-id: the unique identifier for the estimate
-ticker: the ticker for the company being estimated
-fiscal_year: the fiscal year of the quarter being estimated
-fiscal_quarter: the fiscal quarter of the quarter being estimated
-eps: the estimated earnings per share for the company in the specified fiscal quarter
-revenue: the estimated revenue for the company in the specified fiscal quarter
-username: the author of the estimate
-created_at: the time that the estimate was created (UTC)
"""
function_url = url + "/companies/%s/estimates/%s" % (ticker,year)
req = requests.get(function_url, headers=headers)
if req.status_code != 200 : return None
return req.json()
def request_estimates_for_company_for_year_for_quarter(ticker,year,quarter):
"""
Overview: returns all the estimates for a company (specified by ticker) for the specified fiscal year
for a specified quarter(quarter)
Required params: None
Optional params: None
Returns: an array of estimate objects where each estimate has the following properties
-id: the unique identifier for the estimate
-ticker: the ticker for the company being estimated
-fiscal_year: the fiscal year of the quarter being estimated
-fiscal_quarter: the fiscal quarter of the quarter being estimated
-eps: the estimated earnings per share for the company in the specified fiscal quarter
-revenue: the estimated revenue for the company in the specified fiscal quarter
-username: the author of the estimate
-created_at: the time that the estimate was created (UTC)
"""
function_url = url + "/companies/%s/estimates/%s/%s" % (ticker,year,quarter)
req = requests.get(function_url, headers=headers)
if req.status_code != 200 : return None
return req.json()
def request_estimates(start_date,end_date):
"""
Overview: returns all estimates in the specified date-range for all companies
Required params:
start_date: the start date for the date range of estimates to return YYYY-MM-DD
end_date: the end date for the date range of estimates to return YYYY-MM-DD
Optional params: None
Returns: an array of estimate objects where each estimate has the following properties
-id: the unique identifier for the estimate
-ticker: the ticker for the company being estimated
-fiscal_year: the fiscal year of the quarter being estimated
-fiscal_quarter: the fiscal quarter of the quarter being estimated
-eps: the estimated earnings per share for the company in the specified fiscal quarter
-revenue: the estimated revenue for the company in the specified fiscal quarter
-username: the author of the estimate
-created_at: the time that the estimate was created (UTC)
"""
function_url = url + "/estimates"
params = {"start_date" : start_date, "end_date" : end_date}
req = requests.get(function_url, params=params, headers=headers)
pdb.set_trace()
if req.status_code != 200 : return None
return req.json()
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("--t", "--test", type="int", dest="test",
help="""
test 1: request_company_information
test 2: request_releases_for_company
test 3: request_releases_for_company_for_year
test 4: request_releases_for_company_for_year_for_quarter
test 5: request_estimates_for_company
test 6: request_estimates_for_company_for_year
test 7: request_estimates_for_company_for_year_for_quarter
test 8: request_estimates
""", default=1)
(options, args) = parser.parse_args()
if options.test == 1 : request_company_information("AAPL")
elif options.test == 2 : request_releases_for_company("AAPL")
elif options.test == 3 : request_releases_for_company_for_year("AAPL","2013")
elif options.test == 4 : request_releases_for_company_for_year_for_quarter("AAPL","2013","4")
elif options.test == 5 : request_estimates_for_company("AAPL")
elif options.test == 6 : request_estimates_for_company_for_year("AAPL","2013")
elif options.test == 7 : request_estimates_for_company_for_year_for_quarter("AAPL","2013","4")
elif options.test == 8 : request_estimates("2014-01-01","2014-01-10")
else : sys.exit("Useless option passed. Try again.")