示例#1
0
def test_process_trade_handling(default_conf, ticker, limit_buy_order, health,
                                mocker) -> None:
    """
    Test _process()
    """
    patch_get_signal(mocker)
    patch_RPCManager(mocker)
    patch_coinmarketcap(mocker, value={'price_usd': 12345.0})
    mocker.patch.multiple('freqtrade.freqtradebot.exchange',
                          validate_pairs=MagicMock(),
                          get_ticker=ticker,
                          get_wallet_health=health,
                          buy=MagicMock(return_value='mocked_limit_buy'),
                          get_order=MagicMock(return_value=limit_buy_order))
    freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))

    trades = Trade.query.filter(Trade.is_open.is_(True)).all()
    assert not trades
    result = freqtrade._process()
    assert result is True
    trades = Trade.query.filter(Trade.is_open.is_(True)).all()
    assert len(trades) == 1

    result = freqtrade._process()
    assert result is False
示例#2
0
def test_process_exchange_failures(default_conf, ticker, health,
                                   mocker) -> None:
    """
    Test _process() method when a RequestException happens
    """
    patch_get_signal(mocker)
    patch_RPCManager(mocker)
    patch_coinmarketcap(mocker, value={'price_usd': 12345.0})
    mocker.patch.multiple(
        'freqtrade.freqtradebot.exchange',
        validate_pairs=MagicMock(),
        get_ticker=ticker,
        get_wallet_health=health,
        buy=MagicMock(side_effect=requests.exceptions.RequestException))
    sleep_mock = mocker.patch('time.sleep', side_effect=lambda _: None)

    freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
    result = freqtrade._process()
    assert result is False
    assert sleep_mock.has_calls()
示例#3
0
def test_process_operational_exception(default_conf, ticker, health,
                                       mocker) -> None:
    """
    Test _process() method when an OperationalException happens
    """
    patch_get_signal(mocker)
    msg_mock = patch_RPCManager(mocker)
    patch_coinmarketcap(mocker, value={'price_usd': 12345.0})
    mocker.patch.multiple('freqtrade.freqtradebot.exchange',
                          validate_pairs=MagicMock(),
                          get_ticker=ticker,
                          get_wallet_health=health,
                          buy=MagicMock(side_effect=OperationalException))
    freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
    assert freqtrade.state == State.RUNNING

    result = freqtrade._process()
    assert result is False
    assert freqtrade.state == State.STOPPED
    assert 'OperationalException' in msg_mock.call_args_list[-1][0][0]
示例#4
0
def test_process_trade_creation(default_conf, ticker, limit_buy_order, health,
                                mocker, caplog) -> None:
    """
    Test the trade creation in _process() method
    """
    patch_get_signal(mocker)
    patch_RPCManager(mocker)
    patch_coinmarketcap(mocker, value={'price_usd': 12345.0})
    mocker.patch.multiple('freqtrade.freqtradebot.exchange',
                          validate_pairs=MagicMock(),
                          get_ticker=ticker,
                          get_wallet_health=health,
                          buy=MagicMock(return_value='mocked_limit_buy'),
                          get_order=MagicMock(return_value=limit_buy_order))
    freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))

    trades = Trade.query.filter(Trade.is_open.is_(True)).all()
    assert not trades

    result = freqtrade._process()
    assert result is True

    trades = Trade.query.filter(Trade.is_open.is_(True)).all()
    assert len(trades) == 1
    trade = trades[0]
    assert trade is not None
    assert trade.stake_amount == default_conf['stake_amount']
    assert trade.is_open
    assert trade.open_date is not None
    assert trade.exchange == Exchanges.BITTREX.name
    assert trade.open_rate == 0.00001099
    assert trade.amount == 90.99181073703367

    assert log_has(
        'Checking buy signals to create a new trade with stake_amount: 0.001000 ...',
        caplog.record_tuples)