Skip to content

Commit

Permalink
feat: bithumb candle
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkersner committed May 4, 2024
1 parent d2b9587 commit bf5f9a6
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ You may use environment variables to configure the DataMaxi+ client to avoid any
DataMaxi+ Python package currently includes the following clients:

- `Binance`
- `Okx`
- `Bithumb`
- `Bybit`
- `Huobi`
- `Coinone`
- `Huobi`
- `Okx`
- `Upbit`
- `Defillama`
- `Naver`
- `Google`
Expand All @@ -68,6 +70,7 @@ First, import the clients,
```python
# CEX
from datamaxi.binance import Binance
from datamaxi.bithumb import Bithumb
from datamaxi.bybit import Bybit
from datamaxi.coinone import Coinone
from datamaxi.huobi import Huobi
Expand All @@ -87,6 +90,7 @@ and initialize them.
```python
# CEX
binance = Binance(api_key=api_key)
bithumb = Bithumb(api_key=api_key)
bybit = Bybit(api_key=api_key)
coinone = Coinone(api_key=api_key)
huobi = Huobi(api_key=api_key)
Expand Down
70 changes: 70 additions & 0 deletions datamaxi/bithumb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from typing import Any, List, Union
import pandas as pd
from datamaxi.api import API
from datamaxi.lib.utils import check_required_parameters
from datamaxi.lib.utils import postprocess
from datamaxi.lib.constants import BASE_URL


class Bithumb(API):
"""Client to fetch Bithumb data from DataMaxi+ API."""

def __init__(self, api_key=None, **kwargs: Any):
"""Initialize the object.
Args:
api_key (str): The DataMaxi+ API key
**kwargs: Keyword arguments used by `datamaxi.api.API`.
"""
if "base_url" not in kwargs:
kwargs["base_url"] = BASE_URL

super().__init__(api_key, **kwargs)

def symbols(self) -> List[str]:
"""Supported Bithumb supported symbols
`GET /v1/raw/bithumb/symbols`
<https://docs.datamaxiplus.com/cex/bithumb/symbols>
Returns:
List of supported Bithumb symbols
"""
url_path = "/v1/raw/bithumb/symbols"
return self.query(url_path)

def intervals(self) -> List[str]:
"""Supported Bithumb supported intervals
`GET /v1/raw/bithumb/intervals`
<https://docs.datamaxiplus.com/cex/bithumb/intervals>
Returns:
List of supported Bithumb intervals
"""
url_path = "/v1/raw/bithumb/intervals"
return self.query(url_path)

@postprocess()
def candle(
self, symbol: str, interval: str = "1d", pandas: bool = True
) -> Union[List, pd.DataFrame]:
"""Get Bithumb candle data
`GET /v1/raw/bithumb/candle`
<https://docs.datamaxiplus.com/cex/bithumb/candle>
Args:
symbol (str): Bithumb symbol
interval (str): Candle interval
pandas (bool): Return data as pandas DataFrame
Returns:
Bithumb candle data for a given symbol and interval in pandas DataFrame
"""
check_required_parameters([[symbol, "symbol"], [interval, "interval"]])
params = {"symbol": symbol, "interval": interval}
return self.query("/v1/raw/bithumb/candle", params)
45 changes: 45 additions & 0 deletions tests/bithumb/test_bithumb_candle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import responses

from datamaxi.bithumb import Bithumb as Client
from tests.util import random_str
from tests.util import mock_http_response
from urllib.parse import urlencode


mock_item = [
[
"Timestamp",
"OpenPrice",
"ClosePrice",
"HighPrice",
"LowPrice",
"Volume",
],
[
1609459200000,
"28923.63000000",
"29600.00000000",
"28624.57000000",
"29331.69000000",
1314910,
],
]

key = random_str()
client = Client(key)

req_params = {"symbol": "BTC-USDT", "interval": "1d"}
params = {"symbol": "BTC-USDT", "interval": "1d", "pandas": False}


@mock_http_response(
responses.GET,
"/v1/raw/bithumb/candle\\?" + urlencode(req_params),
mock_item,
200,
)
def test_bithumb_candle():
"""Tests the API endpoint to get Bithumb candle."""

response = client.candle(**params)
response.should.equal(mock_item)
24 changes: 24 additions & 0 deletions tests/bithumb/test_bithumb_intervals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import responses

from datamaxi.bithumb import Bithumb as Client
from tests.util import random_str
from tests.util import mock_http_response


mock_item = ["a", "b", "c"]

key = random_str()
client = Client(key)


@mock_http_response(
responses.GET,
"/v1/raw/bithumb/intervals",
mock_item,
200,
)
def test_bithumb_intervals():
"""Tests the API endpoint to get Bithumb supported intervals"""

response = client.intervals()
response.should.equal(mock_item)
24 changes: 24 additions & 0 deletions tests/bithumb/test_bithumb_symbols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import responses

from datamaxi.bithumb import Bithumb as Client
from tests.util import random_str
from tests.util import mock_http_response


mock_item = ["a", "b", "c"]

key = random_str()
client = Client(key)


@mock_http_response(
responses.GET,
"/v1/raw/bithumb/symbols",
mock_item,
200,
)
def test_bithumb_symbols():
"""Tests the API endpoint to get Bithumb supported symbols"""

response = client.symbols()
response.should.equal(mock_item)

0 comments on commit bf5f9a6

Please sign in to comment.