Skip to content

Commit e18b61a

Browse files
authored
Merge pull request #47 from EodHistoricalData/dev
added new funcs
2 parents c36c76d + 1f724a5 commit e18b61a

7 files changed

Lines changed: 97 additions & 6 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: 49 additions & 2 deletions
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
@@ -898,8 +899,8 @@ def get_stock_market_tick_data(
898899
):
899900
"""
900901
Available args:
901-
symbol - , for example, AAPL.US, consists of two parts: {SYMBOL_NAME}.{EXCHANGE_ID}.
902-
This API works only for US exchanges for the moment,
902+
symbol - for example, AAPL.US, consists of two parts: {SYMBOL_NAME}.{EXCHANGE_ID}.
903+
This API works only for US exchanges for the moment,
903904
then you can use 'AAPL' or 'AAPL.US' to get the data as well for other US tickers.
904905
from_timestamp and to_timestamp - use these parameters to filter data by datetime.
905906
Parameters should be passed in UNIX time with UTC timezone,
@@ -915,7 +916,53 @@ def get_stock_market_tick_data(
915916
from_timestamp=from_timestamp,
916917
limit=limit
917918
)
919+
920+
def get_sentiment(
921+
self,
922+
s,
923+
from_date=None,
924+
to_date=None
925+
):
926+
"""
927+
Available args:
928+
s [REQUIRED] - parameter to your URL and you will be able to get data for multiple tickers at one request,
929+
all tickers should be separated with a comma.
930+
from_date and to_date [NOT REQUIRED] - the format is ‘YYYY-MM-DD’.
931+
If you need data from Jan 5, 2022 to Feb 10, 2022, you should use from=2022-01-05 and to=2022-02-10.
932+
For more information visit: https://eodhd.com/financial-apis/sentimental-data-financial-api/
933+
List of supported exchanges: https://eodhd.com/financial-apis/exchanges-api-list-of-tickers-and-trading-hours/
934+
"""
935+
936+
api_call = FinancialNewsAPI()
937+
return api_call.get_sentiment(
938+
api_token=self._api_key,
939+
s=s,
940+
from_date=from_date,
941+
to_date=to_date
942+
)
918943

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

920967
class ScannerClient:
921968
"""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)