-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Client #1147
base: master
Are you sure you want to change the base?
Data Client #1147
Changes from 8 commits
8c59aa9
e95d639
1de6d0f
eb915fc
4e63679
bf6c866
820becd
bacc32a
4ecba53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pandas import DataFrame | ||
|
||
from binance.client import Client | ||
from binance.enums import KLINES_RESPONSE_COLUMNS | ||
|
||
class DataClient(Client): | ||
|
||
def get_historical_klines(self, **args): | ||
klines = super().get_historical_klines(**args) | ||
return DataFrame(klines, columns=KLINES_RESPONSE_COLUMNS) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
import pytest | ||
import requests_mock | ||
|
||
from binance.client import Client | ||
from binance.data_client import DataClient | ||
from binance.enums import KLINE_INTERVAL_1MINUTE | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def client(): | ||
"""Returns a client to use for testing purposes""" | ||
return Client("api_key", "api_secret") | ||
|
||
@pytest.fixture(scope="module") | ||
def data_client(): | ||
"""Returns a data client to use for testing purposes""" | ||
return DataClient("api_key", "api_secret") | ||
|
||
|
||
# | ||
# KLINES RESPONSE DATA | ||
# | ||
|
||
|
||
klines_row_1 = [ | ||
1500004800000, | ||
"0.00005000", | ||
"0.00005300", | ||
"0.00001000", | ||
"0.00004790", | ||
"663152.00000000", | ||
1500004859999, | ||
"30.55108144", | ||
43, | ||
"559224.00000000", | ||
"25.65468144", | ||
"83431971.04346950", | ||
] | ||
|
||
klines_row_2 = [ | ||
1519892340000, | ||
"0.00099400", | ||
"0.00099810", | ||
"0.00099400", | ||
"0.00099810", | ||
"4806.04000000", | ||
1519892399999, | ||
"4.78553253", | ||
154, | ||
"1785.14000000", | ||
"1.77837524", | ||
"0", | ||
] | ||
|
||
url_1 = "https://api.binance.com/api/v3/klines?interval=1m&limit=1&startTime=0&symbol=BNBBTC" | ||
url_2 = "https://api.binance.com/api/v3/klines?interval=1m&limit=1000&startTime=1519862400000&symbol=BNBBTC" | ||
url_3 = "https://api.binance.com/api/v3/klines?interval=1m&limit=1000&startTime=1519892400000&symbol=BNBBTC" | ||
|
||
response_1 = [klines_row_1] | ||
response_2 = [klines_row_2 for _ in range(0,500)] | ||
response_3 = [] | ||
|
||
@pytest.fixture(scope="module") | ||
def historical_klines_response(client): | ||
with requests_mock.mock() as mock: | ||
mock.get(url_1, json=response_1) | ||
mock.get(url_2, json=response_2) | ||
mock.get(url_3, json=response_3) | ||
|
||
klines = client.get_historical_klines( | ||
symbol="BNBBTC", | ||
interval=KLINE_INTERVAL_1MINUTE, | ||
start_str="1st March 2018" | ||
) | ||
#print(klines) | ||
return klines | ||
|
||
@pytest.fixture(scope="module") | ||
def historical_klines_response_df(data_client): | ||
with requests_mock.mock() as mock: | ||
mock.get(url_1, json=response_1) | ||
mock.get(url_2, json=response_2) | ||
mock.get(url_3, json=response_3) | ||
|
||
klines = data_client.get_historical_klines( | ||
symbol="BNBBTC", | ||
interval=KLINE_INTERVAL_1MINUTE, | ||
start_str="1st March 2018" | ||
) | ||
#print(klines) | ||
return klines | ||
|
||
@pytest.fixture(scope="module") | ||
def klines(historical_klines_response): | ||
"""Alias method""" | ||
return historical_klines_response | ||
|
||
@pytest.fixture(scope="module") | ||
def klines_df(historical_klines_response_df): | ||
"""Alias method""" | ||
return historical_klines_response_df |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pandas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, you should define version range: pandas>=n.n.n<n+1
This comment was marked as outdated.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
from pandas import DataFrame | ||
|
||
from binance.enums import KLINES_RESPONSE_COLUMNS | ||
|
||
|
||
def test_historical_klines(klines_df): | ||
assert len(klines_df) == 500 | ||
assert isinstance(klines_df, DataFrame) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
assert klines_df.columns.tolist() == KLINES_RESPONSE_COLUMNS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you shure, that this file should be stored in project root?
And add module's description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confest in the root directory is a best practice to help us avoid adding init files to the test directory. It facilities local imports, especially as they pertain to testing.
https://stackoverflow.com/questions/34466027/in-pytest-what-is-the-use-of-conftest-py-files