-
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.
- Loading branch information
1 parent
8f497de
commit 18b7352
Showing
3 changed files
with
103 additions
and
1 deletion.
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
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,100 @@ | ||
from typing import Any, List, Dict, Union | ||
import pandas as pd | ||
from datamaxi.api import API | ||
from datamaxi.lib.utils import check_required_parameters | ||
from datamaxi.datamaxi.utils import convert_data_to_data_frame | ||
|
||
|
||
class Ticker(API): | ||
"""Client to fetch ticker data from DataMaxi+ API.""" | ||
|
||
def __init__(self, api_key=None, **kwargs: Any): | ||
"""Initialize ticker 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, | ||
exchange: str, | ||
symbol: str, | ||
pandas: bool = True, | ||
) -> Union[Dict, pd.DataFrame]: | ||
"""Fetch ticker data | ||
`GET /api/v1/ticker` | ||
<https://docs.datamaxiplus.com/api/datasets/ticker/ticker> | ||
Args: | ||
exchange (str): Exchange name | ||
symbol (str): Symbol name | ||
pandas (bool): Return data as pandas DataFrame | ||
Returns: | ||
Ticker data in pandas DataFrame | ||
""" | ||
|
||
check_required_parameters( | ||
[ | ||
[exchange, "exchange"], | ||
[symbol, "symbol"], | ||
] | ||
) | ||
|
||
params = { | ||
"exchange": exchange, | ||
"symbol": symbol, | ||
} | ||
|
||
res = self.query("/api/v1/ticker", params) | ||
|
||
if pandas: | ||
return res | ||
# FIXME | ||
# df = convert_data_to_data_frame(res) | ||
# return df | ||
else: | ||
return res | ||
|
||
def exchanges(self, exchange: str) -> List[str]: | ||
"""Fetch supported exchanges accepted by | ||
[datamaxi.Ticker.get](./#datamaxi.datamaxi.Ticker.get) | ||
API. | ||
`GET /api/v1/ticker/exchanges` | ||
<https://docs.datamaxiplus.com/api/datasets/ticker/exchanges> | ||
Returns: | ||
List of supported exchange | ||
""" | ||
url_path = "/api/v1/ticker/exchanges" | ||
return self.query(url_path) | ||
|
||
def symbols(self, exchange: str) -> List[str]: | ||
"""Fetch supported symbols accepted by | ||
[datamaxi.Ticker.get](./#datamaxi.datamaxi.Ticker.get) | ||
API. | ||
`GET /api/v1/ticker/symbols` | ||
<https://docs.datamaxiplus.com/api/datasets/ticker/symbols> | ||
Args: | ||
exchange (str): Exchange name | ||
Returns: | ||
List of supported symbols | ||
""" | ||
check_required_parameter(exchange, "exchange") | ||
|
||
params = { | ||
"exchange": exchange, | ||
} | ||
|
||
url_path = "/api/v1/ticker/symbols" | ||
return self.query(url_path, params) |