added tests for IOC and FOK
This commit is contained in:
parent
adcaa8439e
commit
8d8b53f4d1
@ -413,16 +413,16 @@ class FreqtradeBot(object):
|
||||
order_tif, order_type, pair_s, order_status, self.exchange.name,
|
||||
order['filled'], order['amount'], order['remaining']
|
||||
)
|
||||
stake_amount = order['price']
|
||||
stake_amount = order['cost']
|
||||
amount = order['amount']
|
||||
buy_limit_filled_price = order['average']
|
||||
buy_limit_filled_price = order['price']
|
||||
order_id = None
|
||||
|
||||
# in case of FOK the order may be filled immediately and fully
|
||||
elif order_status == 'filled':
|
||||
stake_amount = order['price']
|
||||
elif order_status == 'closed':
|
||||
stake_amount = order['cost']
|
||||
amount = order['amount']
|
||||
buy_limit_filled_price = order['average']
|
||||
buy_limit_filled_price = order['price']
|
||||
order_id = None
|
||||
|
||||
self.rpc.send_msg({
|
||||
|
@ -863,6 +863,13 @@ def test_execute_buy(mocker, default_conf, fee, markets, limit_buy_order) -> Non
|
||||
assert call_args['rate'] == bid
|
||||
assert call_args['amount'] == stake_amount / bid
|
||||
|
||||
# Should create an open trade with an open order id
|
||||
# As the order is not fulfilled yet
|
||||
trade = Trade.query.first()
|
||||
assert trade
|
||||
assert trade.is_open is True
|
||||
assert trade.open_order_id == limit_buy_order['id']
|
||||
|
||||
# Test calling with price
|
||||
fix_price = 0.06
|
||||
assert freqtrade.execute_buy(pair, stake_amount, fix_price)
|
||||
@ -875,6 +882,43 @@ def test_execute_buy(mocker, default_conf, fee, markets, limit_buy_order) -> Non
|
||||
assert call_args['rate'] == fix_price
|
||||
assert call_args['amount'] == stake_amount / fix_price
|
||||
|
||||
# In case of closed order
|
||||
limit_buy_order['status'] = 'closed'
|
||||
limit_buy_order['price'] = 10
|
||||
limit_buy_order['cost'] = 100
|
||||
mocker.patch('freqtrade.exchange.Exchange.buy', MagicMock(return_value=limit_buy_order))
|
||||
assert freqtrade.execute_buy(pair, stake_amount)
|
||||
trade = Trade.query.all()[2]
|
||||
assert trade
|
||||
assert trade.open_order_id is None
|
||||
assert trade.open_rate == 10
|
||||
assert trade.stake_amount == 100
|
||||
|
||||
# In case of rejected or expired order and partially filled
|
||||
limit_buy_order['status'] = 'expired'
|
||||
limit_buy_order['amount'] = 90.99181073
|
||||
limit_buy_order['filled'] = 80.99181073
|
||||
limit_buy_order['remaining'] = 10.00
|
||||
limit_buy_order['price'] = 0.5
|
||||
limit_buy_order['cost'] = 40.495905365
|
||||
mocker.patch('freqtrade.exchange.Exchange.buy', MagicMock(return_value=limit_buy_order))
|
||||
assert freqtrade.execute_buy(pair, stake_amount)
|
||||
trade = Trade.query.all()[3]
|
||||
assert trade
|
||||
assert trade.open_order_id is None
|
||||
assert trade.open_rate == 0.5
|
||||
assert trade.stake_amount == 40.495905365
|
||||
|
||||
# In case of the order is rejected and not filled at all
|
||||
limit_buy_order['status'] = 'rejected'
|
||||
limit_buy_order['amount'] = 90.99181073
|
||||
limit_buy_order['filled'] = 0.0
|
||||
limit_buy_order['remaining'] = 90.99181073
|
||||
limit_buy_order['price'] = 0.5
|
||||
limit_buy_order['cost'] = 0.0
|
||||
mocker.patch('freqtrade.exchange.Exchange.buy', MagicMock(return_value=limit_buy_order))
|
||||
assert not freqtrade.execute_buy(pair, stake_amount)
|
||||
|
||||
|
||||
def test_add_stoploss_on_exchange(mocker, default_conf, limit_buy_order) -> None:
|
||||
patch_RPCManager(mocker)
|
||||
|
Loading…
Reference in New Issue
Block a user