Skip to content

Commit bf5f9a6

Browse files
committed
feat: bithumb candle
1 parent d2b9587 commit bf5f9a6

File tree

5 files changed

+169
-2
lines changed

5 files changed

+169
-2
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ You may use environment variables to configure the DataMaxi+ client to avoid any
5454
DataMaxi+ Python package currently includes the following clients:
5555

5656
- `Binance`
57-
- `Okx`
57+
- `Bithumb`
5858
- `Bybit`
59-
- `Huobi`
6059
- `Coinone`
60+
- `Huobi`
61+
- `Okx`
62+
- `Upbit`
6163
- `Defillama`
6264
- `Naver`
6365
- `Google`
@@ -68,6 +70,7 @@ First, import the clients,
6870
```python
6971
# CEX
7072
from datamaxi.binance import Binance
73+
from datamaxi.bithumb import Bithumb
7174
from datamaxi.bybit import Bybit
7275
from datamaxi.coinone import Coinone
7376
from datamaxi.huobi import Huobi
@@ -87,6 +90,7 @@ and initialize them.
8790
```python
8891
# CEX
8992
binance = Binance(api_key=api_key)
93+
bithumb = Bithumb(api_key=api_key)
9094
bybit = Bybit(api_key=api_key)
9195
coinone = Coinone(api_key=api_key)
9296
huobi = Huobi(api_key=api_key)

datamaxi/bithumb/__init__.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from typing import Any, List, Union
2+
import pandas as pd
3+
from datamaxi.api import API
4+
from datamaxi.lib.utils import check_required_parameters
5+
from datamaxi.lib.utils import postprocess
6+
from datamaxi.lib.constants import BASE_URL
7+
8+
9+
class Bithumb(API):
10+
"""Client to fetch Bithumb data from DataMaxi+ API."""
11+
12+
def __init__(self, api_key=None, **kwargs: Any):
13+
"""Initialize the object.
14+
15+
Args:
16+
api_key (str): The DataMaxi+ API key
17+
**kwargs: Keyword arguments used by `datamaxi.api.API`.
18+
"""
19+
if "base_url" not in kwargs:
20+
kwargs["base_url"] = BASE_URL
21+
22+
super().__init__(api_key, **kwargs)
23+
24+
def symbols(self) -> List[str]:
25+
"""Supported Bithumb supported symbols
26+
27+
`GET /v1/raw/bithumb/symbols`
28+
29+
<https://docs.datamaxiplus.com/cex/bithumb/symbols>
30+
31+
Returns:
32+
List of supported Bithumb symbols
33+
"""
34+
url_path = "/v1/raw/bithumb/symbols"
35+
return self.query(url_path)
36+
37+
def intervals(self) -> List[str]:
38+
"""Supported Bithumb supported intervals
39+
40+
`GET /v1/raw/bithumb/intervals`
41+
42+
<https://docs.datamaxiplus.com/cex/bithumb/intervals>
43+
44+
Returns:
45+
List of supported Bithumb intervals
46+
"""
47+
url_path = "/v1/raw/bithumb/intervals"
48+
return self.query(url_path)
49+
50+
@postprocess()
51+
def candle(
52+
self, symbol: str, interval: str = "1d", pandas: bool = True
53+
) -> Union[List, pd.DataFrame]:
54+
"""Get Bithumb candle data
55+
56+
`GET /v1/raw/bithumb/candle`
57+
58+
<https://docs.datamaxiplus.com/cex/bithumb/candle>
59+
60+
Args:
61+
symbol (str): Bithumb symbol
62+
interval (str): Candle interval
63+
pandas (bool): Return data as pandas DataFrame
64+
65+
Returns:
66+
Bithumb candle data for a given symbol and interval in pandas DataFrame
67+
"""
68+
check_required_parameters([[symbol, "symbol"], [interval, "interval"]])
69+
params = {"symbol": symbol, "interval": interval}
70+
return self.query("/v1/raw/bithumb/candle", params)

tests/bithumb/test_bithumb_candle.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import responses
2+
3+
from datamaxi.bithumb import Bithumb as Client
4+
from tests.util import random_str
5+
from tests.util import mock_http_response
6+
from urllib.parse import urlencode
7+
8+
9+
mock_item = [
10+
[
11+
"Timestamp",
12+
"OpenPrice",
13+
"ClosePrice",
14+
"HighPrice",
15+
"LowPrice",
16+
"Volume",
17+
],
18+
[
19+
1609459200000,
20+
"28923.63000000",
21+
"29600.00000000",
22+
"28624.57000000",
23+
"29331.69000000",
24+
1314910,
25+
],
26+
]
27+
28+
key = random_str()
29+
client = Client(key)
30+
31+
req_params = {"symbol": "BTC-USDT", "interval": "1d"}
32+
params = {"symbol": "BTC-USDT", "interval": "1d", "pandas": False}
33+
34+
35+
@mock_http_response(
36+
responses.GET,
37+
"/v1/raw/bithumb/candle\\?" + urlencode(req_params),
38+
mock_item,
39+
200,
40+
)
41+
def test_bithumb_candle():
42+
"""Tests the API endpoint to get Bithumb candle."""
43+
44+
response = client.candle(**params)
45+
response.should.equal(mock_item)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import responses
2+
3+
from datamaxi.bithumb import Bithumb as Client
4+
from tests.util import random_str
5+
from tests.util import mock_http_response
6+
7+
8+
mock_item = ["a", "b", "c"]
9+
10+
key = random_str()
11+
client = Client(key)
12+
13+
14+
@mock_http_response(
15+
responses.GET,
16+
"/v1/raw/bithumb/intervals",
17+
mock_item,
18+
200,
19+
)
20+
def test_bithumb_intervals():
21+
"""Tests the API endpoint to get Bithumb supported intervals"""
22+
23+
response = client.intervals()
24+
response.should.equal(mock_item)

tests/bithumb/test_bithumb_symbols.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import responses
2+
3+
from datamaxi.bithumb import Bithumb as Client
4+
from tests.util import random_str
5+
from tests.util import mock_http_response
6+
7+
8+
mock_item = ["a", "b", "c"]
9+
10+
key = random_str()
11+
client = Client(key)
12+
13+
14+
@mock_http_response(
15+
responses.GET,
16+
"/v1/raw/bithumb/symbols",
17+
mock_item,
18+
200,
19+
)
20+
def test_bithumb_symbols():
21+
"""Tests the API endpoint to get Bithumb supported symbols"""
22+
23+
response = client.symbols()
24+
response.should.equal(mock_item)

0 commit comments

Comments
 (0)