-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: forex * feat: ticker * feat: premium * feat: /v1 -> /api/v1 * fix: missing import * fix: remove additional premium param * feat: pandas conversion * fix: flake8 * feat: bump up version to v0.14.0 * feat: docs
- Loading branch information
1 parent
cfa5e64
commit 3e17555
Showing
16 changed files
with
353 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.13.0" | ||
__version__ = "0.14.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from typing import Any, List, Dict, Union | ||
import pandas as pd | ||
from datamaxi.api import API | ||
from datamaxi.lib.utils import check_required_parameter | ||
|
||
|
||
class Forex(API): | ||
"""Client to fetch forex data from DataMaxi+ API.""" | ||
|
||
def __init__(self, api_key=None, **kwargs: Any): | ||
"""Initialize forex client. | ||
Args: | ||
api_key (str): The DataMaxi+ API key | ||
**kwargs: Keyword arguments used by `datamaxi.api.API`. | ||
""" | ||
super().__init__(api_key, **kwargs) | ||
|
||
def get( | ||
self, | ||
symbol: str, | ||
pandas: bool = True, | ||
) -> Union[Dict, pd.DataFrame]: | ||
"""Fetch forex data | ||
`GET /api/v1/forex` | ||
<https://docs.datamaxiplus.com/api/datasets/forex/forex> | ||
Args: | ||
symbol (str): Symbol name | ||
pandas (bool): Return data as pandas DataFrame | ||
Returns: | ||
Forex data in pandas DataFrame | ||
""" | ||
check_required_parameter(symbol, "symbol") | ||
|
||
params = { | ||
"symbol": symbol, | ||
} | ||
|
||
res = self.query("/api/v1/forex", params) | ||
|
||
if pandas: | ||
df = pd.DataFrame(res) | ||
df = df.set_index("d") | ||
return df | ||
else: | ||
return res | ||
|
||
def symbols(self) -> List[str]: | ||
"""Fetch supported symbols accepted by | ||
[datamaxi.Forex.get](./#datamaxi.datamaxi.Forex.get) | ||
API. | ||
`GET /api/v1/forex/symbols` | ||
<https://docs.datamaxiplus.com/api/datasets/forex/symbols> | ||
Returns: | ||
List of supported symbols | ||
""" | ||
url_path = "/api/v1/forex/symbols" | ||
return self.query(url_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from typing import Any, List, Dict, Union | ||
import pandas as pd | ||
from datamaxi.api import API | ||
from datamaxi.lib.utils import check_required_parameters | ||
|
||
|
||
class Premium(API): | ||
"""Client to fetch premium data from DataMaxi+ API.""" | ||
|
||
def __init__(self, api_key=None, **kwargs: Any): | ||
"""Initialize premium client. | ||
Args: | ||
api_key (str): The DataMaxi+ API key | ||
**kwargs: Keyword arguments used by `datamaxi.api.API`. | ||
""" | ||
super().__init__(api_key, **kwargs) | ||
|
||
def get( | ||
self, | ||
sourceExchange: str, | ||
targetExchange: str, | ||
symbol: str, | ||
pandas: bool = True, | ||
) -> Union[Dict, pd.DataFrame]: | ||
"""Fetch premium data | ||
`GET /api/v1/premium` | ||
<https://docs.datamaxiplus.com/api/datasets/premium/premium> | ||
Args: | ||
sourceExchange (str): Source exchange name | ||
targetExchange (str): Target exchange name | ||
symbol (str): Symbol name | ||
pandas (bool): Return data as pandas DataFrame | ||
Returns: | ||
Premium data in pandas DataFrame | ||
""" | ||
|
||
check_required_parameters( | ||
[ | ||
[sourceExchange, "sourceExchange"], | ||
[targetExchange, "targetExchange"], | ||
[symbol, "symbol"], | ||
] | ||
) | ||
|
||
params = { | ||
"sourceExchange": sourceExchange, | ||
"targetExchange": targetExchange, | ||
"symbol": symbol, | ||
} | ||
|
||
res = self.query("/api/v1/premium", params) | ||
|
||
if pandas: | ||
df = pd.DataFrame(res) | ||
df = df.set_index("d") | ||
return df | ||
else: | ||
return res | ||
|
||
def exchanges(self) -> List[str]: | ||
"""Fetch supported exchanges accepted by | ||
[datamaxi.Premium.get](./#datamaxi.datamaxi.Premium.get) | ||
API. | ||
`GET /api/v1/Premium/exchanges` | ||
<https://docs.datamaxiplus.com/api/datasets/Premium/exchanges> | ||
Returns: | ||
List of supported exchange | ||
""" | ||
url_path = "/api/v1/premium/exchanges" | ||
return self.query(url_path) | ||
|
||
def symbols(self, sourceExchange: str, targetExchange: str) -> List[str]: | ||
"""Fetch supported symbols accepted by | ||
[datamaxi.Premium.get](./#datamaxi.datamaxi.Premium.get) | ||
API. | ||
`GET /api/v1/premium/symbols` | ||
<https://docs.datamaxiplus.com/api/datasets/premium/symbols> | ||
Args: | ||
sourceExchange (str): Source exchange name | ||
targetExchange (str): Target exchange name | ||
Returns: | ||
List of supported symbols | ||
""" | ||
check_required_parameters( | ||
[ | ||
[sourceExchange, "sourceExchange"], | ||
[targetExchange, "targetExchange"], | ||
] | ||
) | ||
|
||
params = {"sourceExchange": sourceExchange, "targetExchange": targetExchange} | ||
|
||
url_path = "/api/v1/premium/symbols" | ||
return self.query(url_path, params) |
Oops, something went wrong.