Merge pull request #50 from gcarq/feature/fix-whitelist-vanishing
fix whitelist vanishing
This commit is contained in:
commit
d73c656514
@ -6,6 +6,7 @@ import traceback
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
|
import copy
|
||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
|
|
||||||
from freqtrade import exchange, persistence, __version__
|
from freqtrade import exchange, persistence, __version__
|
||||||
@ -88,11 +89,7 @@ def execute_sell(trade: Trade, current_rate: float) -> None:
|
|||||||
# Get available balance
|
# Get available balance
|
||||||
currency = trade.pair.split('_')[1]
|
currency = trade.pair.split('_')[1]
|
||||||
balance = exchange.get_balance(currency)
|
balance = exchange.get_balance(currency)
|
||||||
whitelist = _CONF[trade.exchange.name.lower()]['pair_whitelist']
|
|
||||||
|
|
||||||
profit = trade.exec_sell_order(current_rate, balance)
|
profit = trade.exec_sell_order(current_rate, balance)
|
||||||
if trade.pair not in whitelist:
|
|
||||||
whitelist.append(trade.pair)
|
|
||||||
message = '*{}:* Selling [{}]({}) at rate `{:f} (profit: {}%)`'.format(
|
message = '*{}:* Selling [{}]({}) at rate `{:f} (profit: {}%)`'.format(
|
||||||
trade.exchange.name,
|
trade.exchange.name,
|
||||||
trade.pair.replace('_', '/'),
|
trade.pair.replace('_', '/'),
|
||||||
@ -161,7 +158,7 @@ def create_trade(stake_amount: float, _exchange: exchange.Exchange) -> Optional[
|
|||||||
:param _exchange: exchange to use
|
:param _exchange: exchange to use
|
||||||
"""
|
"""
|
||||||
logger.info('Creating new trade with stake_amount: %f ...', stake_amount)
|
logger.info('Creating new trade with stake_amount: %f ...', stake_amount)
|
||||||
whitelist = _CONF[_exchange.name.lower()]['pair_whitelist']
|
whitelist = copy.deepcopy(_CONF[_exchange.name.lower()]['pair_whitelist'])
|
||||||
# Check if stake_amount is fulfilled
|
# Check if stake_amount is fulfilled
|
||||||
if exchange.get_balance(_CONF['stake_currency']) < stake_amount:
|
if exchange.get_balance(_CONF['stake_currency']) < stake_amount:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@ -169,11 +166,7 @@ def create_trade(stake_amount: float, _exchange: exchange.Exchange) -> Optional[
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Remove currently opened and latest pairs from whitelist
|
# Remove currently opened and latest pairs from whitelist
|
||||||
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
|
for trade in Trade.query.filter(Trade.is_open.is_(True)).all():
|
||||||
latest_trade = Trade.query.filter(Trade.is_open.is_(False)).order_by(Trade.id.desc()).first()
|
|
||||||
if latest_trade:
|
|
||||||
trades.append(latest_trade)
|
|
||||||
for trade in trades:
|
|
||||||
if trade.pair in whitelist:
|
if trade.pair in whitelist:
|
||||||
whitelist.remove(trade.pair)
|
whitelist.remove(trade.pair)
|
||||||
logger.debug('Ignoring %s in pair whitelist', trade.pair)
|
logger.debug('Ignoring %s in pair whitelist', trade.pair)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock, call
|
||||||
|
|
||||||
|
import copy
|
||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
|
|
||||||
from freqtrade import exchange
|
from freqtrade import exchange
|
||||||
@ -29,7 +30,10 @@ class TestMain(unittest.TestCase):
|
|||||||
"key": "key",
|
"key": "key",
|
||||||
"secret": "secret",
|
"secret": "secret",
|
||||||
"pair_whitelist": [
|
"pair_whitelist": [
|
||||||
"BTC_ETH"
|
"BTC_ETH",
|
||||||
|
"BTC_TKN",
|
||||||
|
"BTC_TRST",
|
||||||
|
"BTC_SWT",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"telegram": {
|
"telegram": {
|
||||||
@ -50,19 +54,27 @@ class TestMain(unittest.TestCase):
|
|||||||
'last': 0.07256061
|
'last': 0.07256061
|
||||||
}),
|
}),
|
||||||
buy=MagicMock(return_value='mocked_order_id')):
|
buy=MagicMock(return_value='mocked_order_id')):
|
||||||
|
# Save state of current whitelist
|
||||||
|
whitelist = copy.deepcopy(self.conf['bittrex']['pair_whitelist'])
|
||||||
|
|
||||||
init(self.conf, 'sqlite://')
|
init(self.conf, 'sqlite://')
|
||||||
trade = create_trade(15.0, exchange.Exchange.BITTREX)
|
for pair in ['BTC_ETH', 'BTC_TKN', 'BTC_TRST', 'BTC_SWT']:
|
||||||
Trade.session.add(trade)
|
trade = create_trade(15.0, exchange.Exchange.BITTREX)
|
||||||
Trade.session.flush()
|
Trade.session.add(trade)
|
||||||
self.assertIsNotNone(trade)
|
Trade.session.flush()
|
||||||
self.assertEqual(trade.open_rate, 0.072661)
|
self.assertIsNotNone(trade)
|
||||||
self.assertEqual(trade.pair, 'BTC_ETH')
|
self.assertEqual(trade.open_rate, 0.072661)
|
||||||
self.assertEqual(trade.exchange, exchange.Exchange.BITTREX)
|
self.assertEqual(trade.pair, pair)
|
||||||
self.assertEqual(trade.amount, 206.43811673387373)
|
self.assertEqual(trade.exchange, exchange.Exchange.BITTREX)
|
||||||
self.assertEqual(trade.stake_amount, 15.0)
|
self.assertEqual(trade.amount, 206.43811673387373)
|
||||||
self.assertEqual(trade.is_open, True)
|
self.assertEqual(trade.stake_amount, 15.0)
|
||||||
self.assertIsNotNone(trade.open_date)
|
self.assertEqual(trade.is_open, True)
|
||||||
buy_signal.assert_called_once_with('BTC_ETH')
|
self.assertIsNotNone(trade.open_date)
|
||||||
|
self.assertEqual(whitelist, self.conf['bittrex']['pair_whitelist'])
|
||||||
|
|
||||||
|
buy_signal.assert_has_calls(
|
||||||
|
[call('BTC_ETH'), call('BTC_TKN'), call('BTC_TRST'), call('BTC_SWT')]
|
||||||
|
)
|
||||||
|
|
||||||
def test_2_handle_trade(self):
|
def test_2_handle_trade(self):
|
||||||
with patch.dict('freqtrade.main._CONF', self.conf):
|
with patch.dict('freqtrade.main._CONF', self.conf):
|
||||||
|
Loading…
Reference in New Issue
Block a user