Skip to content

Commit

Permalink
feat: ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkersner committed Jul 26, 2024
1 parent 8f497de commit 18b7352
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
2 changes: 2 additions & 0 deletions datamaxi/datamaxi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datamaxi.datamaxi.funding_rate import FundingRate
from datamaxi.datamaxi.dex_trade import DexTrade
from datamaxi.datamaxi.forex import Forex
from datamaxi.datamaxi.ticker import Ticker


class Datamaxi:
Expand All @@ -23,3 +24,4 @@ def __init__(self, api_key=None, **kwargs: Any):
self.funding_rate = FundingRate(api_key, **kwargs)
self.dex_trade = DexTrade(api_key, **kwargs)
self.forex = Forex(api_key, **kwargs)
self.ticker = Ticker(api_key, **kwargs)
2 changes: 1 addition & 1 deletion datamaxi/datamaxi/forex.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get(
return res

def symbols(self) -> List[str]:
"""Fetch supported forex symbols accepted by
"""Fetch supported symbols accepted by
[datamaxi.Forex.get](./#datamaxi.datamaxi.Forex.get)
API.
Expand Down
100 changes: 100 additions & 0 deletions datamaxi/datamaxi/ticker.py
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)

0 comments on commit 18b7352

Please sign in to comment.