This commit is contained in:
Michael Egger
2017-10-29 19:23:54 +00:00
committed by GitHub
12 changed files with 110 additions and 63 deletions

View File

@@ -25,7 +25,7 @@ def conf():
"0": 0.02
},
"bid_strategy": {
"ask_last_balance": 0.0
"bid_ask_balance": 1.0
},
"exchange": {
"name": "bittrex",
@@ -48,6 +48,7 @@ def conf():
validate(configuration, CONF_SCHEMA)
return configuration
def test_create_trade(conf, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
buy_signal = mocker.patch('freqtrade.main.get_buy_signal', side_effect=lambda _: True)
@@ -57,7 +58,6 @@ def test_create_trade(conf, mocker):
get_ticker=MagicMock(return_value={
'bid': 0.07256061,
'ask': 0.072661,
'last': 0.07256061
}),
buy=MagicMock(return_value='mocked_order_id'))
# Save state of current whitelist
@@ -82,6 +82,7 @@ def test_create_trade(conf, mocker):
[call('BTC_ETH'), call('BTC_TKN'), call('BTC_TRST'), call('BTC_SWT')]
)
def test_handle_trade(conf, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
mocker.patch.multiple('freqtrade.main.telegram', init=MagicMock(), send_msg=MagicMock())
@@ -90,7 +91,6 @@ def test_handle_trade(conf, mocker):
get_ticker=MagicMock(return_value={
'bid': 0.17256061,
'ask': 0.172661,
'last': 0.17256061
}),
buy=MagicMock(return_value='mocked_order_id'))
trade = Trade.query.filter(Trade.is_open.is_(True)).first()
@@ -101,6 +101,7 @@ def test_handle_trade(conf, mocker):
assert trade.close_date is not None
assert trade.open_order_id == 'dry_run'
def test_close_trade(conf, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
trade = Trade.query.filter(Trade.is_open.is_(True)).first()
@@ -113,14 +114,17 @@ def test_close_trade(conf, mocker):
assert closed
assert not trade.is_open
def test_balance_fully_bid_side(mocker):
mocker.patch.dict('freqtrade.main._CONF', {'bid_strategy': {'bid_ask_balance': 0.0}})
assert get_target_bid({'bid': 10, 'ask': 20}) == 10
def test_balance_fully_ask_side(mocker):
mocker.patch.dict('freqtrade.main._CONF', {'bid_strategy': {'ask_last_balance': 0.0}})
assert get_target_bid({'ask': 20, 'last': 10}) == 20
mocker.patch.dict('freqtrade.main._CONF', {'bid_strategy': {'bid_ask_balance': 1.0}})
assert get_target_bid({'bid': 10, 'ask': 20}) == 20
def test_balance_fully_last_side(mocker):
mocker.patch.dict('freqtrade.main._CONF', {'bid_strategy': {'ask_last_balance': 1.0}})
assert get_target_bid({'ask': 20, 'last': 10}) == 10
def test_balance_when_last_bigger_than_ask(mocker):
mocker.patch.dict('freqtrade.main._CONF', {'bid_strategy': {'ask_last_balance': 1.0}})
assert get_target_bid({'ask': 5, 'last': 10}) == 5
def test_balance_half(mocker):
mocker.patch.dict('freqtrade.main._CONF', {'bid_strategy': {'bid_ask_balance': 0.5}})
assert get_target_bid({'bid': 10, 'ask': 20}) == 15

View File

@@ -25,7 +25,7 @@ def conf():
"0": 0.02
},
"bid_strategy": {
"ask_last_balance": 0.0
"bid_ask_balance": 1.0,
},
"exchange": {
"name": "bittrex",
@@ -46,6 +46,7 @@ def conf():
validate(configuration, CONF_SCHEMA)
return configuration
@pytest.fixture
def update():
_update = Update(0)
@@ -67,7 +68,6 @@ def test_status_handle(conf, update, mocker):
get_ticker=MagicMock(return_value={
'bid': 0.07256061,
'ask': 0.072661,
'last': 0.07256061
}),
buy=MagicMock(return_value='mocked_order_id'))
init(conf, 'sqlite://')
@@ -82,6 +82,7 @@ def test_status_handle(conf, update, mocker):
assert msg_mock.call_count == 2
assert '[BTC_ETH]' in msg_mock.call_args_list[-1][0][0]
def test_profit_handle(conf, update, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
mocker.patch('freqtrade.main.get_buy_signal', side_effect=lambda _: True)
@@ -92,7 +93,6 @@ def test_profit_handle(conf, update, mocker):
get_ticker=MagicMock(return_value={
'bid': 0.07256061,
'ask': 0.072661,
'last': 0.07256061
}),
buy=MagicMock(return_value='mocked_order_id'))
init(conf, 'sqlite://')
@@ -112,6 +112,7 @@ def test_profit_handle(conf, update, mocker):
assert msg_mock.call_count == 2
assert '(100.00%)' in msg_mock.call_args_list[-1][0][0]
def test_forcesell_handle(conf, update, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
mocker.patch('freqtrade.main.get_buy_signal', side_effect=lambda _: True)
@@ -122,7 +123,6 @@ def test_forcesell_handle(conf, update, mocker):
get_ticker=MagicMock(return_value={
'bid': 0.07256061,
'ask': 0.072661,
'last': 0.07256061
}),
buy=MagicMock(return_value='mocked_order_id'))
init(conf, 'sqlite://')
@@ -140,6 +140,7 @@ def test_forcesell_handle(conf, update, mocker):
assert 'Selling [BTC/ETH]' in msg_mock.call_args_list[-1][0][0]
assert '0.072561' in msg_mock.call_args_list[-1][0][0]
def test_performance_handle(conf, update, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
mocker.patch('freqtrade.main.get_buy_signal', side_effect=lambda _: True)
@@ -150,7 +151,6 @@ def test_performance_handle(conf, update, mocker):
get_ticker=MagicMock(return_value={
'bid': 0.07256061,
'ask': 0.072661,
'last': 0.07256061
}),
buy=MagicMock(return_value='mocked_order_id'))
init(conf, 'sqlite://')
@@ -171,6 +171,7 @@ def test_performance_handle(conf, update, mocker):
assert 'Performance' in msg_mock.call_args_list[-1][0][0]
assert 'BTC_ETH 100.00%' in msg_mock.call_args_list[-1][0][0]
def test_start_handle(conf, update, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
msg_mock = MagicMock()
@@ -184,6 +185,7 @@ def test_start_handle(conf, update, mocker):
assert get_state() == State.RUNNING
assert msg_mock.call_count == 0
def test_stop_handle(conf, update, mocker):
mocker.patch.dict('freqtrade.main._CONF', conf)
msg_mock = MagicMock()