Add handling for market orders

fixes #1427 and #1428
This commit is contained in:
Matthias
2018-12-27 11:19:26 +01:00
parent 20cdabbe9c
commit 9af2fca718
2 changed files with 23 additions and 6 deletions

View File

@@ -62,7 +62,7 @@ def test_init_dryrun_db(default_conf, mocker):
@pytest.mark.usefixtures("init_persistence")
def test_update_with_bittrex(limit_buy_order, limit_sell_order, fee):
def test_update_with_bittrex(limit_buy_order, limit_sell_order, fee, caplog):
"""
On this test we will buy and sell a crypto currency.
@@ -91,6 +91,7 @@ def test_update_with_bittrex(limit_buy_order, limit_sell_order, fee):
"""
trade = Trade(
id=2,
pair='ETH/BTC',
stake_amount=0.001,
fee_open=fee.return_value,
@@ -108,18 +109,26 @@ def test_update_with_bittrex(limit_buy_order, limit_sell_order, fee):
assert trade.open_rate == 0.00001099
assert trade.close_profit is None
assert trade.close_date is None
assert log_has("LIMIT_BUY has been fulfilled for Trade(id=2, "
"pair=ETH/BTC, amount=90.99181073, open_rate=0.00001099, open_since=closed).",
caplog.record_tuples)
caplog.clear()
trade.open_order_id = 'something'
trade.update(limit_sell_order)
assert trade.open_order_id is None
assert trade.close_rate == 0.00001173
assert trade.close_profit == 0.06201058
assert trade.close_date is not None
assert log_has("LIMIT_SELL has been fulfilled for Trade(id=2, "
"pair=ETH/BTC, amount=90.99181073, open_rate=0.00001099, open_since=closed).",
caplog.record_tuples)
@pytest.mark.usefixtures("init_persistence")
def test_update_market_order(market_buy_order, market_sell_order, fee):
def test_update_market_order(market_buy_order, market_sell_order, fee, caplog):
trade = Trade(
id=1,
pair='ETH/BTC',
stake_amount=0.001,
fee_open=fee.return_value,
@@ -133,13 +142,20 @@ def test_update_market_order(market_buy_order, market_sell_order, fee):
assert trade.open_rate == 0.00004099
assert trade.close_profit is None
assert trade.close_date is None
assert log_has("MARKET_BUY has been fulfilled for Trade(id=1, "
"pair=ETH/BTC, amount=91.99181073, open_rate=0.00004099, open_since=closed).",
caplog.record_tuples)
caplog.clear()
trade.open_order_id = 'something'
trade.update(market_sell_order)
assert trade.open_order_id is None
assert trade.close_rate == 0.00004173
assert trade.close_profit == 0.01297561
assert trade.close_date is not None
assert log_has("MARKET_SELL has been fulfilled for Trade(id=1, "
"pair=ETH/BTC, amount=91.99181073, open_rate=0.00004099, open_since=closed).",
caplog.record_tuples)
@pytest.mark.usefixtures("init_persistence")