Skip to content

Commit 2fb42c4

Browse files
committed
added new funcs
1 parent b02da1b commit 2fb42c4

7 files changed

Lines changed: 96 additions & 5 deletions

File tree

eodhd/APIs/FinancialNewsAPI.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,22 @@ def financial_news(self, api_token: str, s = None, t = None, from_date = None, t
4242
if to_date is not None:
4343
query_string += '&to=' + str(to_date)
4444

45-
return self._rest_get_method(api_key = api_token, endpoint = endpoint, querystring = query_string)
45+
return self._rest_get_method(api_key = api_token, endpoint = endpoint, querystring = query_string)
46+
47+
def get_sentiment(self, api_token: str, s: str, from_date: str = None, to_date: str = None):
48+
49+
endpoint = 'sentiments'
50+
51+
query_string = ''
52+
53+
if s is None:
54+
raise ValueError("s argument is empty. You need to add s to args")
55+
56+
query_string += '&s=' + str(s)
57+
58+
if from_date is not None:
59+
query_string += '&from=' + str(from_date)
60+
if to_date is not None:
61+
query_string += '&to=' + str(to_date)
62+
63+
return self._rest_get_method(api_key = api_token, endpoint = endpoint, querystring = query_string)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from .BaseAPI import BaseAPI
2+
3+
class HistoricalMarketCapitalization(BaseAPI):
4+
5+
def get_historical_market_capitalization_data(self, api_token: str, ticker, from_date: str = None, to_date: str = None):
6+
7+
endpoint = 'historical-market-cap'
8+
uri = f'{ticker}'
9+
10+
query_string = ''
11+
12+
if from_date is not None:
13+
query_string += '&from=' + str(from_date)
14+
if to_date is not None:
15+
query_string += '&to=' + str(to_date)
16+
17+
18+
return self._rest_get_method(api_key = api_token, endpoint = endpoint, querystring = query_string, uri = uri)

eodhd/APIs/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
from .OptionsDataAPI import OptionsDataAPI
2020
from .IntradayDataAPI import IntradayDataAPI
2121
from .EodHistoricalStockMarketDataAPI import EodHistoricalStockMarketDataAPI
22-
from .StockMarketTickDataAPI import StockMarketTickDataAPI
22+
from .StockMarketTickDataAPI import StockMarketTickDataAPI
23+
from .HistoricalMarketCapitalizationAPI import HistoricalMarketCapitalization

eodhd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99

1010
# Version of eodhd package
11-
__version__ = "1.0.27"
11+
__version__ = "1.0.28"

eodhd/apiclient.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from eodhd.APIs import IntradayDataAPI
3838
from eodhd.APIs import EodHistoricalStockMarketDataAPI
3939
from eodhd.APIs import StockMarketTickDataAPI
40+
from eodhd.APIs import HistoricalMarketCapitalization
4041

4142
# minimal traceback
4243
sys.tracebacklimit = 1
@@ -895,7 +896,7 @@ def get_stock_market_tick_data(
895896
):
896897
"""
897898
Available args:
898-
symbol - , for example, AAPL.US, consists of two parts: {SYMBOL_NAME}.{EXCHANGE_ID}.
899+
symbol - for example, AAPL.US, consists of two parts: {SYMBOL_NAME}.{EXCHANGE_ID}.
899900
This API works only for US exchanges for the moment,
900901
then you can use 'AAPL' or 'AAPL.US' to get the data as well for other US tickers.
901902
from_timestamp and to_timestamp - use these parameters to filter data by datetime.
@@ -912,7 +913,53 @@ def get_stock_market_tick_data(
912913
from_timestamp=from_timestamp,
913914
limit=limit
914915
)
916+
917+
def get_sentiment(
918+
self,
919+
s,
920+
from_date=None,
921+
to_date=None
922+
):
923+
"""
924+
Available args:
925+
s [REQUIRED] - parameter to your URL and you will be able to get data for multiple tickers at one request,
926+
all tickers should be separated with a comma.
927+
from_date and to_date [NOT REQUIRED] - the format is ‘YYYY-MM-DD’.
928+
If you need data from Jan 5, 2022 to Feb 10, 2022, you should use from=2022-01-05 and to=2022-02-10.
929+
For more information visit: https://eodhd.com/financial-apis/sentimental-data-financial-api/
930+
List of supported exchanges: https://eodhd.com/financial-apis/exchanges-api-list-of-tickers-and-trading-hours/
931+
"""
932+
933+
api_call = FinancialNewsAPI()
934+
return api_call.get_sentiment(
935+
api_token=self._api_key,
936+
s=s,
937+
from_date=from_date,
938+
to_date=to_date
939+
)
915940

941+
def get_historical_market_capitalization_data(
942+
self,
943+
ticker,
944+
from_date=None,
945+
to_date=None
946+
):
947+
"""
948+
Available args:
949+
ticker [REQUIRED] - is the ticker code and it consists of two parts: {SYMBOL_NAME}.{EXCHANGE_ID},
950+
you can use a US ticker code with or without the exchange part (AAPL or AAPL.US)
951+
from_date and to_date [NOT REQUIRED] - the format is ‘YYYY-MM-DD’.
952+
If you need data from Jan 5, 2022 to Feb 10, 2022, you should use from=2022-01-05 and to=2022-02-10.
953+
For more information visit: https://eodhd.com/financial-apis/historical-market-capitalization-api/
954+
"""
955+
956+
api_call = HistoricalMarketCapitalization()
957+
return api_call.get_historical_market_capitalization_data(
958+
api_token=self._api_key,
959+
ticker=ticker,
960+
from_date=from_date,
961+
to_date=to_date
962+
)
916963

917964
class ScannerClient:
918965
"""Scanner class"""

example_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,12 @@ def main() -> None:
133133
resp = api.get_stock_market_tick_data(from_timestamp = '1627896900', to_timestamp = '1630575300', symbol = 'AAPL', limit = 1)
134134
print(resp)
135135

136+
resp = api.get_sentiment(s = 'btc-usd.cc', from_date = '2023-01-01', to_date = '2023-01-15')
137+
print(resp)
138+
139+
resp = api.get_historical_market_capitalization_data(ticker = 'AAPL.US', from_date = '2023-01-01', to_date = '2023-01-15')
140+
print(resp)
141+
142+
136143
if __name__ == "__main__":
137144
main()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# This call to setup() does all the work
1717
setup(
1818
name="eodhd",
19-
version="1.0.27",
19+
version="1.0.28",
2020
description="Official EODHD API Python Library",
2121
long_description=long_description,
2222
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)