-
Notifications
You must be signed in to change notification settings - Fork 15
Add test_klines.py #15
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
Open
andrgit
wants to merge
15
commits into
sann05:hybrid
Choose a base branch
from
andrgit:hybrid_klines
base: hybrid
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
efca772
Merge pull request #1 from sann05/hybrid
andrgit 33482aa
Add test_exchange_info
andrgit 6525b6c
update test_exchange_info, add second condition
andrgit f8fc0a5
update test_exchange_info
andrgit acedfab
add test klines
andrgit 85bffa4
Revert "add test klines"
andrgit aaf0fd6
Revert "Revert "add test klines""
andrgit 8caff45
Deleted test_exchange_info.py
andrgit 21904a3
changed line length to 79 chars
andrgit 94a2f7d
updated test_klines
andrgit 7eb545e
changed all test,add test interval,limit
andrgit 58a7388
refixed functions,made base test,interval test,limit test
andrgit 1b0e0ae
fix some bugs
andrgit be87e12
Add tests start_time and end_time
andrgit 9b0e394
Add tests: wrong_symbol, start_time_in_future,end_time_less_then_star…
andrgit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,131 @@ | ||
| import functools | ||
| import itertools | ||
| import sys | ||
| import time | ||
| from datetime import datetime, timedelta | ||
| import pytest | ||
|
|
||
| from currencycom import constants | ||
| from currencycom.client import CandlesticksChartIntervals | ||
|
|
||
|
|
||
| class TestKlines: | ||
| date_values = [ | ||
| datetime(1970, 1, 3), | ||
| datetime(1970, 1, 3, 0, 1), | ||
| datetime(2019, 1, 1), | ||
| datetime.now() - timedelta(minutes=1), | ||
| datetime.now() | ||
| ] | ||
| values = [1, 59, 99, 101, 500, 999, 1000] | ||
|
|
||
| def test_base_check(self, client): | ||
| klines = client.get_klines(symbol='GOOGL.', | ||
| interval=CandlesticksChartIntervals | ||
| .MINUTE) | ||
| assert len(klines) > 0 | ||
| assert all(len(i) == 6 for i in klines) | ||
|
|
||
| @pytest.mark.parametrize("interval, minutes", [ | ||
| (CandlesticksChartIntervals.MINUTE, 1), | ||
| (CandlesticksChartIntervals.FIVE_MINUTES, 5), | ||
| (CandlesticksChartIntervals.FIFTEEN_MINUTES, 15), | ||
| (CandlesticksChartIntervals.THIRTY_MINUTES, 30), | ||
| (CandlesticksChartIntervals.HOUR, 60), | ||
| (CandlesticksChartIntervals.FOUR_HOURS, 240), | ||
| (CandlesticksChartIntervals.DAY, 1440), | ||
| (CandlesticksChartIntervals.WEEK, 10080), | ||
| ]) | ||
| def test_check_interval_and_accordance_between_get_klines(self, client, | ||
| interval, | ||
| minutes): | ||
| klines = client.get_klines(symbol='ETH/USD_LEVERAGE', | ||
| interval=interval) | ||
| assert all(val[0] % 60000 == 0 for val in klines) | ||
| assert (klines[i + 1][0] - klines[i][0] == (minutes * 60000) for i in | ||
| range(len(klines) - 1)) | ||
|
|
||
| @pytest.mark.parametrize('limit', [1, 500, 999, 1000]) | ||
| def test_check_valid_limits(self, client, limit): | ||
| """ | ||
| Positive test | ||
| Check get counts | ||
| Сравниваем что количество запрашиваемых и полученных значений лимита | ||
| равны. | ||
| """ | ||
| klines = client.get_klines(symbol='META.', | ||
| interval=CandlesticksChartIntervals.MINUTE, | ||
| limit=limit) | ||
| assert len(klines) == limit | ||
|
|
||
| @pytest.mark.parametrize('limit', | ||
| [1001, sys.maxsize]) | ||
| def test_check_limits_more_max_limit(self, client, limit): | ||
| """ | ||
| Negative test. | ||
| Check values > max limit(1000) | ||
| """ | ||
| with pytest.raises(ValueError): | ||
| client.get_klines(symbol='META.', | ||
| interval=CandlesticksChartIntervals. | ||
| FIFTEEN_MINUTES, | ||
| limit=limit) | ||
|
|
||
| @pytest.mark.parametrize('limit', | ||
| [-1, 0, -sys.maxsize]) | ||
| def test_check_limits_less_1(self, client, limit): | ||
| """ | ||
| Negative test | ||
| Check values < min limit(1) | ||
| """ | ||
| klines = client.get_klines(symbol='META.', | ||
| interval=CandlesticksChartIntervals. | ||
| FIFTEEN_MINUTES, | ||
| limit=limit) | ||
| assert klines['code'] == -1128 | ||
|
|
||
| @pytest.mark.parametrize('date_val', date_values) | ||
| def test_start_time_valid(self, client, date_val): | ||
| klines = client.get_klines(symbol='GOOGL.', | ||
| interval=CandlesticksChartIntervals.HOUR, | ||
| start_time=date_val) | ||
| date_ago_timestamp = date_val.timestamp() | ||
| assert all(date[0] / 1000 >= date_ago_timestamp for date in klines) | ||
|
|
||
| @pytest.mark.parametrize('date_val', date_values) | ||
| def test_end_time_valid(self, client, date_val): | ||
| klines = client.get_klines(symbol='DBK.', | ||
| interval=CandlesticksChartIntervals. | ||
| FIFTEEN_MINUTES, end_time=date_val) | ||
| date_ago_timestamp = date_val.timestamp() | ||
| assert all(date[0] / 1000 <= date_ago_timestamp for date in klines) | ||
|
|
||
| def test_wrong_symbol(self, client): | ||
| klines = client.get_klines(symbol='TEST', | ||
| interval=CandlesticksChartIntervals. | ||
| THIRTY_MINUTES) | ||
| assert 'Invalid symbol' in klines['msg'] | ||
| assert klines['code'] == -1128 | ||
|
|
||
| @pytest.mark.parametrize('date_future', | ||
| [datetime.now() + timedelta(minutes=1), | ||
| datetime(3001, 1, 3)]) | ||
| def test_start_time_future(self, client, date_future): | ||
| klines = client.get_klines(symbol='META.', | ||
| interval=CandlesticksChartIntervals. | ||
| FOUR_HOURS, start_time=date_future) | ||
| assert len(klines) == 0 | ||
|
|
||
| @pytest.mark.parametrize('seconds', | ||
| [1, 214748379, 214748380]) | ||
| def test_end_time_less_then_start_time(self, client, seconds): | ||
| dttm_start = datetime.now() - timedelta(days=1) | ||
| dttm_end = dttm_start - timedelta(seconds=seconds) | ||
| klines = client.get_klines( | ||
| symbol='EUR/USD_LEVERAGE', | ||
| interval=CandlesticksChartIntervals.FIVE_MINUTES, | ||
| start_time=dttm_start, | ||
| end_time=dttm_end | ||
| ) | ||
| assert klines['msg'] == 'endTime should be greater than startTime.' | ||
| assert klines['code'] == -1128 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ничего не пропустил?
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.
ну тут мы проверяем что первая свеча начинается четко с минуты 00, и вторая что разница(interval) между ними то количество минут которое указывали. И что-то еще?