Skip to content

Commit

Permalink
Use named arguments for stoploss create_order call
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Jan 19, 2020
1 parent 16b34e1 commit e6f1912
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions freqtrade/exchange/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def stoploss(self, pair: str, amount: float, stop_price: float, order_types: Dic

rate = self.price_to_precision(pair, rate)

order = self._api.create_order(pair, ordertype, 'sell',
amount, rate, params)
order = self._api.create_order(symbol=pair, type=ordertype, side='sell',
amount=amount, price=stop_price, params=params)
logger.info('stoploss limit order added for %s. '
'stop price: %s. limit: %s', pair, stop_price, rate)
return order
Expand Down
15 changes: 8 additions & 7 deletions tests/exchange/test_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tests.conftest import get_patched_exchange


def test_stoploss_limit_order(default_conf, mocker):
def test_stoploss_order_binance(default_conf, mocker):
api_mock = MagicMock()
order_id = 'test_prod_buy_{}'.format(randint(0, 10 ** 6))
order_type = 'stop_loss_limit'
Expand Down Expand Up @@ -38,11 +38,12 @@ def test_stoploss_limit_order(default_conf, mocker):
assert 'id' in order
assert 'info' in order
assert order['id'] == order_id
assert api_mock.create_order.call_args[0][0] == 'ETH/BTC'
assert api_mock.create_order.call_args[0][1] == order_type
assert api_mock.create_order.call_args[0][2] == 'sell'
assert api_mock.create_order.call_args[0][3] == 1
assert api_mock.create_order.call_args[0][5] == {'stopPrice': 220}
assert api_mock.create_order.call_args_list[0][1]['symbol'] == 'ETH/BTC'
assert api_mock.create_order.call_args_list[0][1]['type'] == order_type
assert api_mock.create_order.call_args_list[0][1]['side'] == 'sell'
assert api_mock.create_order.call_args_list[0][1]['amount'] == 1
assert api_mock.create_order.call_args_list[0][1]['price'] == 220
assert api_mock.create_order.call_args_list[0][1]['params'] == {'stopPrice': 220}

# test exception handling
with pytest.raises(DependencyException):
Expand All @@ -67,7 +68,7 @@ def test_stoploss_limit_order(default_conf, mocker):
exchange.stoploss(pair='ETH/BTC', amount=1, stop_price=220, order_types={})


def test_stoploss_limit_order_dry_run(default_conf, mocker):
def test_stoploss_order_dry_run_binance(default_conf, mocker):
api_mock = MagicMock()
order_type = 'stop_loss_limit'
default_conf['dry_run'] = True
Expand Down

0 comments on commit e6f1912

Please sign in to comment.