Skip to content

Commit

Permalink
Rename stoploss_limit to stoploss
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Jan 19, 2020
1 parent da0af48 commit 256fc2e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
3 changes: 1 addition & 2 deletions freqtrade/exchange/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def get_order_book(self, pair: str, limit: int = 100) -> dict:

return super().get_order_book(pair, limit)

def stoploss_limit(self, pair: str, amount: float, stop_price: float,
order_types: Dict) -> Dict:
def stoploss(self, pair: str, amount: float, stop_price: float, order_types: Dict) -> Dict:
"""
creates a stoploss limit order.
this stoploss-limit is binance-specific.
Expand Down
6 changes: 3 additions & 3 deletions freqtrade/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,10 @@ def sell(self, pair: str, ordertype: str, amount: float,

return self.create_order(pair, ordertype, 'sell', amount, rate, params)

def stoploss_limit(self, pair: str, amount: float, stop_price: float,
order_types: Dict) -> Dict:
def stoploss(self, pair: str, amount: float, stop_price: float, order_types: Dict) -> Dict:
"""
creates a stoploss limit order.
creates a stoploss order.
The precise ordertype is determined by the order_types dict or exchange default.
Since ccxt does not unify stoploss-limit orders yet, this needs to be implemented in each
exchange's subclass.
The exception below should never raise, since we disallow
Expand Down
6 changes: 3 additions & 3 deletions freqtrade/freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ def create_stoploss_order(self, trade: Trade, stop_price: float, rate: float) ->
:return: True if the order succeeded, and False in case of problems.
"""
try:
stoploss_order = self.exchange.stoploss_limit(pair=trade.pair, amount=trade.amount,
stop_price=stop_price,
order_types=self.strategy.order_types)
stoploss_order = self.exchange.stoploss(pair=trade.pair, amount=trade.amount,
stop_price=stop_price,
order_types=self.strategy.order_types)
trade.stoploss_order_id = str(stoploss_order['id'])
return True
except InvalidOrderException as e:
Expand Down
20 changes: 10 additions & 10 deletions tests/exchange/test_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def test_stoploss_limit_order(default_conf, mocker):
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')

with pytest.raises(OperationalException):
order = exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=190,
order_types={'stoploss_on_exchange_limit_ratio': 1.05})
order = exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=190,
order_types={'stoploss_on_exchange_limit_ratio': 1.05})

api_mock.create_order.reset_mock()

order = exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
order = exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})

assert 'id' in order
assert 'info' in order
Expand All @@ -48,23 +48,23 @@ def test_stoploss_limit_order(default_conf, mocker):
with pytest.raises(DependencyException):
api_mock.create_order = MagicMock(side_effect=ccxt.InsufficientFunds("0 balance"))
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})

with pytest.raises(InvalidOrderException):
api_mock.create_order = MagicMock(
side_effect=ccxt.InvalidOrder("binance Order would trigger immediately."))
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})

with pytest.raises(TemporaryError):
api_mock.create_order = MagicMock(side_effect=ccxt.NetworkError("No connection"))
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})

with pytest.raises(OperationalException, match=r".*DeadBeef.*"):
api_mock.create_order = MagicMock(side_effect=ccxt.BaseError("DeadBeef"))
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')
exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})


def test_stoploss_limit_order_dry_run(default_conf, mocker):
Expand All @@ -77,12 +77,12 @@ def test_stoploss_limit_order_dry_run(default_conf, mocker):
exchange = get_patched_exchange(mocker, default_conf, api_mock, 'binance')

with pytest.raises(OperationalException):
order = exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=190,
order_types={'stoploss_on_exchange_limit_ratio': 1.05})
order = exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=190,
order_types={'stoploss_on_exchange_limit_ratio': 1.05})

api_mock.create_order.reset_mock()

order = exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
order = exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})

assert 'id' in order
assert 'info' in order
Expand Down
2 changes: 1 addition & 1 deletion tests/exchange/test_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ def test_get_fee(default_conf, mocker, exchange_name):
def test_stoploss_limit_order_unsupported_exchange(default_conf, mocker):
exchange = get_patched_exchange(mocker, default_conf, 'bittrex')
with pytest.raises(OperationalException, match=r"stoploss_limit is not implemented .*"):
exchange.stoploss_limit(pair='ETH/BTC', amount=1, stop_price=220, order_types={})
exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})


def test_merge_ft_has_dict(default_conf, mocker):
Expand Down

0 comments on commit 256fc2e

Please sign in to comment.