Skip to content

Commit

Permalink
Merge pull request #2361 from freqtrade/dataprovider_tests
Browse files Browse the repository at this point in the history
Add tests for orderbook and market in dataprovider
  • Loading branch information
hroff-1902 committed Oct 11, 2019
2 parents 10a22e7 + 5e23cc7 commit 31389b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions freqtrade/data/dataprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import logging
from pathlib import Path
from typing import List, Tuple
from typing import Any, Dict, List, Optional, Tuple

from pandas import DataFrame

Expand Down Expand Up @@ -85,7 +85,7 @@ def get_pair_dataframe(self, pair: str, ticker_interval: str = None) -> DataFram
logger.warning(f"No data found for ({pair}, {ticker_interval}).")
return data

def market(self, pair: str):
def market(self, pair: str) -> Optional[Dict[str, Any]]:
"""
Return market data for the pair
:param pair: Pair to get the data for
Expand All @@ -100,9 +100,9 @@ def ticker(self, pair: str):
# TODO: Implement me
pass

def orderbook(self, pair: str, maximum: int):
def orderbook(self, pair: str, maximum: int) -> Dict[str, List]:
"""
return latest orderbook data
fetch latest orderbook data
:param pair: pair to get the data for
:param maximum: Maximum number of orderbook entries to query
:return: dict including bids/asks with a total of `maximum` entries.
Expand Down
32 changes: 32 additions & 0 deletions tests/data/test_dataprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,35 @@ def test_refresh(mocker, default_conf, ticker_history):
assert len(refresh_mock.call_args[0]) == 1
assert len(refresh_mock.call_args[0][0]) == len(pairs) + len(pairs_non_trad)
assert refresh_mock.call_args[0][0] == pairs + pairs_non_trad


def test_orderbook(mocker, default_conf, order_book_l2):
api_mock = MagicMock()
api_mock.fetch_l2_order_book = order_book_l2
exchange = get_patched_exchange(mocker, default_conf, api_mock=api_mock)

dp = DataProvider(default_conf, exchange)
res = dp.orderbook('ETH/BTC', 5)
assert order_book_l2.call_count == 1
assert order_book_l2.call_args_list[0][0][0] == 'ETH/BTC'
assert order_book_l2.call_args_list[0][0][1] == 5

assert type(res) is dict
assert 'bids' in res
assert 'asks' in res


def test_market(mocker, default_conf, markets):
api_mock = MagicMock()
api_mock.markets = markets
exchange = get_patched_exchange(mocker, default_conf, api_mock=api_mock)

dp = DataProvider(default_conf, exchange)
res = dp.market('ETH/BTC')

assert type(res) is dict
assert 'symbol' in res
assert res['symbol'] == 'ETH/BTC'

res = dp.market('UNITTEST/BTC')
assert res is None

0 comments on commit 31389b3

Please sign in to comment.