use deepcopy

This commit is contained in:
gcarq 2017-09-30 17:02:07 +02:00
parent 898ab5a370
commit 4b42e1af4b

View File

@ -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)