tests and flake8 compliance

This commit is contained in:
Nullart 2018-06-18 18:05:43 +08:00
parent 735356197d
commit 2f6673fbe7
5 changed files with 48 additions and 27 deletions

View File

@ -258,4 +258,3 @@ class Analyze(object):
if time_diff > duration: if time_diff > duration:
roi_rate = (trade.open_rate * (1 + threshold)) * (1+(2.1*get_fee(trade.pair))) roi_rate = (trade.open_rate * (1 + threshold)) * (1+(2.1*get_fee(trade.pair)))
return self.trunc_num(roi_rate, 8) return self.trunc_num(roi_rate, 8)

View File

@ -244,7 +244,6 @@ class FreqtradeBot(object):
:param ticker: Ticker to use for getting Ask and Last Price :param ticker: Ticker to use for getting Ask and Last Price
:return: float: Price :return: float: Price
""" """
ticker = exchange.get_ticker(pair) ticker = exchange.get_ticker(pair)
logger.info('ticker data %s', ticker) logger.info('ticker data %s', ticker)
@ -273,9 +272,13 @@ class FreqtradeBot(object):
logger.info('used rate %0.8f', used_rate) logger.info('used rate %0.8f', used_rate)
logger.info('percent_from_top %0.8f', self.config['bid_strategy']['percent_from_top'])
logger.info('percent_from_top %s', self.config['bid_strategy']['percent_from_top'] > 0)
if self.config['bid_strategy']['percent_from_top'] > 0: if self.config['bid_strategy']['percent_from_top'] > 0:
used_rate = self.analyze.trunc_num(used_rate - (used_rate * self.config['bid_strategy']['percent_from_top']),8) used_rate = used_rate - (used_rate * self.config['bid_strategy']['percent_from_top'])
used_rate = self.analyze.trunc_num(used_rate, 8)
logger.info('used rate xx %0.8f', used_rate) logger.info('used rate xx %0.8f', used_rate)
return used_rate return used_rate
def create_trade(self) -> bool: def create_trade(self) -> bool:
@ -285,6 +288,7 @@ class FreqtradeBot(object):
:return: True if a trade object has been created and persisted, False otherwise :return: True if a trade object has been created and persisted, False otherwise
""" """
stake_amount = self.config['stake_amount'] stake_amount = self.config['stake_amount']
interval = self.analyze.get_ticker_interval() interval = self.analyze.get_ticker_interval()
stake_currency = self.config['stake_currency'] stake_currency = self.config['stake_currency']
fiat_currency = self.config['fiat_display_currency'] fiat_currency = self.config['fiat_display_currency']
@ -295,8 +299,10 @@ class FreqtradeBot(object):
stake_amount stake_amount
) )
whitelist = copy.deepcopy(self.config['exchange']['pair_whitelist']) whitelist = copy.deepcopy(self.config['exchange']['pair_whitelist'])
# Check if stake_amount is fulfilled # Check if stake_amount is fulfilled
if exchange.get_balance(stake_currency) < stake_amount: current_balance = exchange.get_balance(self.config['stake_currency'])
if current_balance < stake_amount:
raise DependencyException( raise DependencyException(
f'stake amount is not fulfilled (currency={stake_currency})') f'stake amount is not fulfilled (currency={stake_currency})')
@ -528,7 +534,7 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
ordertime = arrow.get(order['datetime']).datetime ordertime = arrow.get(order['datetime']).datetime
# Check if trade is still actually open # Check if trade is still actually open
if (int(order['filled']) == 0) and (order['status'] == 'open'): if (order['status'] == 'open'):
if order['side'] == 'buy' and ordertime < buy_timeoutthreashold: if order['side'] == 'buy' and ordertime < buy_timeoutthreashold:
self.handle_timedout_limit_buy(trade, order) self.handle_timedout_limit_buy(trade, order)
elif order['side'] == 'sell' and ordertime < sell_timeoutthreashold: elif order['side'] == 'sell' and ordertime < sell_timeoutthreashold:

View File

@ -98,6 +98,7 @@ def default_conf():
"use_book_order": False, "use_book_order": False,
"book_order_top": 6, "book_order_top": 6,
"ask_last_balance": 0.0, "ask_last_balance": 0.0,
"percent_from_top": 0.0
}, },
"ask_strategy": { "ask_strategy": {
"use_book_order": False, "use_book_order": False,

View File

@ -499,7 +499,12 @@ def test_balance_fully_ask_side(mocker) -> None:
""" """
Test get_target_bid() method Test get_target_bid() method
""" """
param = {'use_book_order': False, 'book_order_top': 6, 'ask_last_balance': 0.0} param = {
'use_book_order': False,
'book_order_top': 6,
'ask_last_balance': 0.0,
'percent_from_top': 0
}
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param}) freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07 assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
@ -509,7 +514,12 @@ def test_balance_fully_last_side(mocker) -> None:
""" """
Test get_target_bid() method Test get_target_bid() method
""" """
param = {'use_book_order': False, 'book_order_top': 6, 'ask_last_balance': 0.0} param = {
'use_book_order': False,
'book_order_top': 6,
'ask_last_balance': 0.0,
'percent_from_top': 0
}
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param}) freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07 assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
@ -519,7 +529,12 @@ def test_balance_bigger_last_ask(mocker) -> None:
""" """
Test get_target_bid() method Test get_target_bid() method
""" """
param = {'use_book_order': False, 'book_order_top': 6, 'ask_last_balance': 0.0} param = {
'use_book_order': False,
'book_order_top': 6,
'ask_last_balance': 0.0,
'percent_from_top': 0.00
}
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param}) freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07 assert freqtrade.get_target_bid('ETH/BTC') >= 0.07