-
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
d2b9587
commit bf5f9a6
Showing
5 changed files
with
169 additions
and
2 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
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,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) |
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,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) |
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,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) |
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,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) |