missing test added

This commit is contained in:
Misagh 2019-04-05 20:20:16 +02:00
parent 25d8e93a90
commit 54d068de44
2 changed files with 15 additions and 5 deletions

View File

@ -13,7 +13,7 @@ import arrow
from requests.exceptions import RequestException from requests.exceptions import RequestException
import sdnotify import sdnotify
from freqtrade import (DependencyException, OperationalException, from freqtrade import (DependencyException, OperationalException, InvalidOrderException,
TemporaryError, __version__, constants, persistence) TemporaryError, __version__, constants, persistence)
from freqtrade.data.converter import order_book_to_dataframe from freqtrade.data.converter import order_book_to_dataframe
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
@ -692,11 +692,13 @@ class FreqtradeBot(object):
logger.debug('Handling stoploss on exchange %s ...', trade) logger.debug('Handling stoploss on exchange %s ...', trade)
stoploss_order = None
try: try:
# First we check if there is already a stoploss on exchange # First we check if there is already a stoploss on exchange
stoploss_order = self.exchange.get_order(trade.stoploss_order_id, trade.pair) \ stoploss_order = self.exchange.get_order(trade.stoploss_order_id, trade.pair) \
if trade.stoploss_order_id else None if trade.stoploss_order_id else None
except DependencyException as exception: except InvalidOrderException as exception:
logger.warning('Unable to fetch stoploss order: %s', exception) logger.warning('Unable to fetch stoploss order: %s', exception)
# If trade open order id does not exist: buy order is fulfilled # If trade open order id does not exist: buy order is fulfilled
@ -705,8 +707,7 @@ class FreqtradeBot(object):
# Limit price threshold: As limit price should always be below price # Limit price threshold: As limit price should always be below price
limit_price_pct = 0.99 limit_price_pct = 0.99
# If buy order is fulfilled but there is no stoploss, # If buy order is fulfilled but there is no stoploss, we add a stoploss on exchange
# then we add a stoploss on exchange
if (buy_order_fulfilled and not stoploss_order): if (buy_order_fulfilled and not stoploss_order):
if self.edge: if self.edge:
stoploss = self.edge.stoploss(pair=trade.pair) stoploss = self.edge.stoploss(pair=trade.pair)

View File

@ -12,7 +12,7 @@ import pytest
import requests import requests
from freqtrade import (DependencyException, OperationalException, from freqtrade import (DependencyException, OperationalException,
TemporaryError, constants) TemporaryError, InvalidOrderException, constants)
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
from freqtrade.freqtradebot import FreqtradeBot from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
@ -1052,6 +1052,15 @@ def test_handle_stoploss_on_exchange(mocker, default_conf, fee, caplog,
freqtrade.handle_stoploss_on_exchange(trade) freqtrade.handle_stoploss_on_exchange(trade)
assert log_has('Unable to place a stoploss order on exchange: ', caplog.record_tuples) assert log_has('Unable to place a stoploss order on exchange: ', caplog.record_tuples)
#Fifth case: get_order returns InvalidOrder
# It should try to add stoploss order
trade.stoploss_order_id = 100
stoploss_limit.reset_mock()
mocker.patch('freqtrade.exchange.Exchange.get_order', side_effect=InvalidOrderException())
mocker.patch('freqtrade.exchange.Exchange.stoploss_limit', stoploss_limit)
freqtrade.handle_stoploss_on_exchange(trade)
assert stoploss_limit.call_count == 1
def test_handle_stoploss_on_exchange_trailing(mocker, default_conf, fee, caplog, def test_handle_stoploss_on_exchange_trailing(mocker, default_conf, fee, caplog,
markets, limit_buy_order, limit_sell_order) -> None: markets, limit_buy_order, limit_sell_order) -> None: