Skip to content

Commit 515f3e6

Browse files
committed
New tests has been added
1 parent 983a7a8 commit 515f3e6

1 file changed

Lines changed: 245 additions & 62 deletions

File tree

example_api.py

Lines changed: 245 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,325 @@
1-
"""API example"""
1+
"""
2+
example_api.py
3+
4+
Examples of using the EODHD Python Financial Library (APIClient)
5+
"""
26

37
import config as cfg
48
from eodhd import APIClient
59

610

711
def main() -> None:
812
"""Main"""
9-
1013
api = APIClient(cfg.API_KEY)
1114

15+
# --- Exchanges & symbols ---
1216
resp = api.get_exchanges()
1317
print(resp)
14-
# print(resp.dtypes)
15-
# print(resp.describe())
1618

1719
resp = api.get_exchange_symbols("US")
1820
print(resp)
19-
# print(resp.dtypes)
20-
# print(resp.describe())
2121

22-
resp = api.get_intraday_historical_data('BTC-USD.CC','1m')
23-
# resp = api.get_historical_data("BTC-USD.CC", "1m", "2021-11-27 23:56:00")
24-
# resp = api.get_historical_data("BTC-USD.CC", "1m", "2021-11-27 23:56:00", "2021-11-27 23:59:00")
22+
# --- Intraday / Historical ---
23+
resp = api.get_intraday_historical_data("BTC-USD.CC", "1m")
2524
print(resp)
26-
# print(resp.dtypes)
27-
# print(resp.describe())
2825

2926
resp = api.get_historical_data("BTC-USD.CC", "5m")
30-
# resp = api.get_historical_data("BTC-USD.CC", "5m", "2021-11-27 23:55:00")
31-
# resp = api.get_historical_data("BTC-USD.CC", "5m", "2021-11-27 23:55:00", "2021-11-28 02:00:00")
3227
print(resp)
33-
# print(resp.dtypes)
34-
# print(resp.describe())
3528

3629
resp = api.get_historical_data("BTC-USD.CC", "1h")
37-
# resp = api.get_historical_data("BTC-USD.CC", "1h", "2021-11-27 23:00:00")
38-
# resp = api.get_historical_data("BTC-USD.CC", "1h", "2021-11-27 23:00:00", "2021-11-28 23:59:00")
3930
print(resp)
40-
# print(resp.dtypes)
41-
# print(resp.describe())
4231

4332
resp = api.get_historical_data("BTC-USD.CC", "d")
44-
# resp = api.get_historical_data("BTC-USD.CC", "d", "2021-11-24")
45-
# resp = api.get_historical_data("BTC-USD.CC", "d", "2021-11-24", "2021-11-27")
4633
print(resp)
47-
# print(resp.dtypes)
48-
# print(resp.describe())
4934

5035
resp = api.get_historical_data("BTC-USD.CC", "d", results=400)
51-
# resp = api.get_historical_data("BTC-USD.CC", "d", "2021-11-24")
52-
# resp = api.get_historical_data("BTC-USD.CC", "d", "2021-11-24", "2021-11-27")
5336
print(resp)
54-
# print(resp.dtypes)
55-
# print(resp.describe())
5637

57-
resp = api.get_details_trading_hours_stock_market_holidays(code = 'US', from_date = '2022-12-01', to_date = '2023-01-03')
58-
# resp = api.get_details_trading_hours_stock_market_holidays(code = 'US')
38+
# --- Trading hours / holidays ---
39+
resp = api.get_details_trading_hours_stock_market_holidays(
40+
code="US", from_date="2022-12-01", to_date="2023-01-03"
41+
)
5942
print(resp)
6043

61-
resp = api.get_bonds_fundamentals_data(isin = 'DE000CB83CF0')
44+
# --- Bulk EOD splits/dividends ---
45+
resp = api.get_eod_splits_dividends_data(
46+
country="US",
47+
type="splits",
48+
date="2010-09-21",
49+
symbols="MSFT",
50+
filter="extended",
51+
)
6252
print(resp)
6353

64-
resp = api.get_eod_splits_dividends_data(country = 'US', type = 'splits', date = '2010-09-21', symbols = 'MSFT', filter = 'extended')
65-
# resp = api.get_eod_splits_dividends_data(country = 'US', type = 'dividends', date = '2010-09-21', symbols = 'MSFT', filter = 'extended')
54+
# --- Earning trends ---
55+
resp = api.get_earning_trends_data(symbols="AAPL.US")
6656
print(resp)
6757

68-
resp = api.get_earning_trends_data(symbols = 'AAPL.US')
69-
# resp = api.get_earning_trends_data(symbols = 'AAPL.US, MS')
58+
# --- Economic events ---
59+
resp = api.get_economic_events_data(
60+
date_from="2020-01-05",
61+
date_to="2020-02-10",
62+
country="AU",
63+
comparison="mom",
64+
offset=50,
65+
limit=50,
66+
)
7067
print(resp)
7168

72-
resp = api.get_economic_events_data(date_from = '2020-01-05', date_to = '2020-02-10', country = 'AU', comparison = 'mom',
73-
offset = 50, limit = 50)
74-
# resp = api.get_economic_events_data(date_from = '2020-01-05', date_to = '2020-02-10', country = 'AU', comparison = 'qoq', offset = 50, limit = 50)
75-
# resp = api.get_economic_events_data(date_from = '2020-01-05', date_to = '2020-02-10', country = 'AU', comparison = 'yoy', offset = 50, limit = 50)
69+
# --- Financial News (ticker or tag) ---
70+
resp = api.financial_news(
71+
s="AAPL.US",
72+
t=None,
73+
from_date="2020-01-05",
74+
to_date="2020-02-10",
75+
limit=100,
76+
offset=200,
77+
)
7678
print(resp)
7779

78-
resp = api.financial_news(s = 'AAPL.US', t = None, from_date = '2020-01-05', to_date = '2020-02-10', limit = 100, offset = 200)
79-
# resp = api.financial_news(s = None, t = 'balance sheet', from_date = '2020-01-05', to_date = '2020-02-10', limit = 100, offset = 200)
80+
# --- Fundamentals ---
81+
resp = api.get_fundamentals_data(ticker="AAPL")
8082
print(resp)
8183

82-
resp = api.get_fundamentals_data(ticker = 'AAPL')
84+
# --- Historical dividends/splits ---
85+
resp = api.get_historical_dividends_data(
86+
date_from="2020-01-05", date_to="2020-02-10", ticker="AAPL.US"
87+
)
8388
print(resp)
8489

85-
resp = api.get_historical_dividends_data(date_from = '2020-01-05', date_to = '2020-02-10', ticker = 'AAPL.US')
90+
resp = api.get_historical_splits_data(
91+
date_from="2020-01-05", date_to="2020-02-10", ticker="AAPL.US"
92+
)
8693
print(resp)
8794

88-
resp = api.get_historical_splits_data(date_from = '2020-01-05', date_to = '2020-02-10', ticker = 'AAPL.US')
95+
# --- Insider transactions ---
96+
resp = api.get_insider_transactions_data(
97+
date_from="2020-01-05", date_to="2020-02-10", code="AAPL", limit=200
98+
)
8999
print(resp)
90100

91-
resp = api.get_insider_transactions_data(date_from = '2020-01-05', date_to = '2020-02-10', code = 'AAPL', limit = 200)
92-
#resp = api.get_insider_transactions_data(date_from = '2020-01-05', date_to = '2020-02-10', code = 'AAPL.US', limit = 200)
101+
# --- Live stock prices ---
102+
resp = api.get_live_stock_prices(
103+
date_from="2020-01-05", date_to="2020-02-10", ticker="AAPL.US"
104+
)
93105
print(resp)
94106

95-
resp = api.get_live_stock_prices(date_from = '2020-01-05', date_to = '2020-02-10', ticker = 'AAPL.US')
107+
# --- Macro indicators ---
108+
resp = api.get_macro_indicators_data(country="US", indicator="population_total")
96109
print(resp)
97110

98-
resp = api.get_macro_indicators_data(country = 'US', indicator = 'population_total')
99-
# resp = api.get_macro_indicators_data(country = 'US', indicator = 'consumer_price_index')
111+
# --- Screener ---
112+
resp = api.stock_market_screener(
113+
sort="market_capitalization.desc",
114+
filters='[["market_capitalization",">",1000], ["name","match","apple"], ["code","=","AAPL"],["exchange","=","us"],["sector","=","Technology"]]',
115+
limit=10,
116+
signals="bookvalue_neg",
117+
offset=0,
118+
)
100119
print(resp)
101120

102-
resp = api.stock_market_screener(sort = 'market_capitalization.desc', filters = '[["market_capitalization",">",1000], ["name","match","apple"], ["code","=","AAPL"],["exchange","=","us"],["sector","=","Technology"]]', limit = 10, signals = 'bookvalue_neg', offset = 0)
121+
# --- Calendars ---
122+
resp = api.get_upcoming_earnings_data(from_date="2020-01-05", to_date="2020-02-10", symbols="MSFT")
103123
print(resp)
104124

105-
resp = api.get_upcoming_earnings_data(from_date = '2020-01-05', to_date = '2020-02-10', symbols = 'MSFT')
125+
resp = api.get_upcoming_IPOs_data(from_date="2020-01-05", to_date="2020-02-10")
106126
print(resp)
107127

108-
resp = api.get_upcoming_IPOs_data(from_date = '2020-01-05', to_date = '2020-02-10')
128+
resp = api.get_upcoming_splits_data(from_date="2020-01-05", to_date="2020-02-10")
109129
print(resp)
110130

111-
resp = api.get_upcoming_splits_data(from_date = '2020-01-05', to_date = '2020-02-10')
131+
# --- Technical indicators ---
132+
resp = api.get_technical_indicator_data(
133+
ticker="AAPL.US",
134+
function="avgvolccy",
135+
period=100,
136+
date_from="2020-01-05",
137+
date_to="2020-02-10",
138+
order="a",
139+
splitadjusted_only="0",
140+
)
112141
print(resp)
113142

114-
resp = api.get_technical_indicator_data(ticker = 'AAPL.US', function = 'avgvolccy', period = 100, date_from = '2020-01-05', date_to = '2020-02-10',
115-
order = 'a', splitadjusted_only = '0')
143+
# --- Lists / symbol change history ---
144+
resp = api.get_list_of_exchanges()
116145
print(resp)
117146

118-
resp = api.get_list_of_exchanges()
147+
resp = api.get_list_of_tickers(delisted=1, code="US")
148+
print(resp)
149+
150+
resp = api.symbol_change_history(from_date="2020-01-05", to_date="2020-02-10")
151+
print(resp)
152+
153+
# --- Intraday (unix timestamps example) ---
154+
resp = api.get_intraday_historical_data(
155+
symbol="AAPL.MX",
156+
from_unix_time="1627896900",
157+
to_unix_time="1630575300",
158+
interval="1h",
159+
)
160+
print(resp)
161+
162+
# --- EOD historical stock market data ---
163+
resp = api.get_eod_historical_stock_market_data(
164+
symbol="AAPL.MX",
165+
period="d",
166+
from_date="2023-01-01",
167+
to_date="2023-01-15",
168+
order="a",
169+
)
170+
print(resp)
171+
172+
# --- Tick data ---
173+
resp = api.get_stock_market_tick_data(
174+
from_timestamp="1627896900",
175+
to_timestamp="1630575300",
176+
symbol="AAPL",
177+
limit=1,
178+
)
179+
print(resp)
180+
181+
# --- News sentiment ---
182+
resp = api.get_sentiment(s="btc-usd.cc", from_date="2023-01-01", to_date="2023-01-15")
183+
print(resp)
184+
185+
# --- News Word Weights (NEW) ---
186+
resp = api.news_word_weights(
187+
s="AAPL.US",
188+
date_from="2025-01-01",
189+
date_to="2025-01-15",
190+
limit=10,
191+
)
192+
print(resp)
193+
194+
# --- Historical market cap ---
195+
resp = api.get_historical_market_capitalization_data(
196+
ticker="AAPL.US",
197+
from_date="2023-01-01",
198+
to_date="2023-01-15",
199+
)
200+
print(resp)
201+
202+
203+
# Live v2 US Stocks: Extended Quotes (Delayed) - /us-quote-delayed
204+
resp = api.us_extended_quotes(
205+
symbols=["AAPL.US", "TSLA.US"],
206+
page_limit=2,
207+
page_offset=0,
208+
fmt="json", # or "csv"
209+
)
210+
print(resp)
211+
212+
# CBOE Indices List - /cboe/indices
213+
resp = api.get_cboe_indices_list(fmt="json")
119214
print(resp)
120215

121-
resp = api.get_list_of_tickers(delisted = 1, code = 'US')
216+
# CBOE Index Feed (index + components) - /cboe/index
217+
resp = api.get_cboe_index_data(
218+
index_code="BDE30P",
219+
feed_type="snapshot_official_closing",
220+
date="2017-02-01",
221+
fmt="json",
222+
)
122223
print(resp)
123224

124-
resp = api.symbol_change_history(from_date = '2020-01-05', to_date = '2020-02-10')
225+
# ID Mapping - /id-mapping
226+
# By symbol
227+
resp = api.get_id_mapping(symbol="AAPL.US", page_limit=100, page_offset=0, fmt="json")
125228
print(resp)
126229

127-
resp = api.get_intraday_historical_data(symbol = 'AAPL.MX', from_unix_time = '1627896900', to_unix_time = '1630575300', interval='1h')
230+
# By ISIN
231+
resp = api.get_id_mapping(isin="US0378331005", fmt="json")
128232
print(resp)
129233

130-
resp = api.get_eod_historical_stock_market_data(symbol = 'AAPL.MX', period='d', from_date = '2023-01-01', to_date = '2023-01-15', order='a')
234+
# By exchange code (example)
235+
resp = api.get_id_mapping(ex="US", page_limit=50, page_offset=0, fmt="json")
131236
print(resp)
132237

133-
resp = api.get_stock_market_tick_data(from_timestamp = '1627896900', to_timestamp = '1630575300', symbol = 'AAPL', limit = 1)
238+
# Marketplace S&P Global / UnicornBay indices list
239+
resp = api.mp_indices_list()
134240
print(resp)
135241

136-
resp = api.get_sentiment(s = 'btc-usd.cc', from_date = '2023-01-01', to_date = '2023-01-15')
242+
# Marketplace S&P Global / UnicornBay index components
243+
resp = api.mp_index_components(symbol="GSPC.INDX", historical=False)
137244
print(resp)
138245

139-
resp = api.get_historical_market_capitalization_data(ticker = 'AAPL.US', from_date = '2023-01-01', to_date = '2023-01-15')
246+
resp = api.mp_index_components(
247+
symbol="GSPC.INDX",
248+
historical=True,
249+
from_date="2015-01-01",
250+
to_date="2017-01-01",
251+
)
252+
print(resp)
253+
254+
# US Options: underlying symbols list
255+
resp = api.get_us_options_underlyings(fmt="json")
256+
print(resp)
257+
258+
# US Options: contracts
259+
resp = api.get_us_options_contracts(
260+
underlying_symbol="AAPL",
261+
exp_date_from="2025-01-01",
262+
exp_date_to="2025-06-01",
263+
type="call",
264+
sort="exp_date",
265+
page_offset=0,
266+
page_limit=50,
267+
fields=["contract", "exp_date", "strike", "type", "tradetime"],
268+
fmt="json",
269+
)
270+
print(resp)
271+
272+
# US Options: EOD
273+
resp = api.get_us_options_eod(
274+
underlying_symbol="AAPL",
275+
exp_date_from="2025-01-01",
276+
exp_date_to="2025-06-01",
277+
type="put",
278+
strike_from=100,
279+
strike_to=200,
280+
sort="-exp_date",
281+
page_offset=0,
282+
page_limit=50,
283+
fields="contract,exp_date,strike,type,tradetime,volume,last,bid,ask",
284+
compact=1,
285+
fmt="json",
286+
)
287+
print(resp)
288+
289+
# Technical Indicators enhancements
290+
# beta
291+
resp = api.get_technical_indicator_data(
292+
ticker="AAPL.US",
293+
function="beta",
294+
period=50,
295+
date_from="2020-01-05",
296+
date_to="2020-02-10",
297+
order="a",
298+
fmt="json",
299+
# code2="GSPC.INDX", # optional, if your APIClient passes it through
300+
)
301+
print(resp)
302+
303+
# dx alias -> dmi
304+
resp = api.get_technical_indicator_data(
305+
ticker="AAPL.US",
306+
function="dx",
307+
period=14,
308+
date_from="2020-01-05",
309+
date_to="2020-02-10",
310+
order="a",
311+
fmt="json",
312+
)
313+
print(resp)
314+
315+
# filter_field example (last EMA only)
316+
resp = api.get_technical_indicator_data(
317+
ticker="AAPL.US",
318+
function="ema",
319+
period=50,
320+
filter_field="last_ema",
321+
fmt="json",
322+
)
140323
print(resp)
141324

142325

0 commit comments

Comments
 (0)