rpc: make freqtrade a private variable

This commit is contained in:
gcarq 2018-06-09 00:20:10 +02:00
parent 34e10a145c
commit 6c1bb7983b

View File

@ -34,7 +34,7 @@ class RPC(object):
:param freqtrade: Instance of a freqtrade bot :param freqtrade: Instance of a freqtrade bot
:return: None :return: None
""" """
self.freqtrade = freqtrade self._freqtrade = freqtrade
@abstractmethod @abstractmethod
def cleanup(self) -> None: def cleanup(self) -> None:
@ -56,7 +56,7 @@ class RPC(object):
""" """
# Fetch open trade # Fetch open trade
trades = Trade.query.filter(Trade.is_open.is_(True)).all() trades = Trade.query.filter(Trade.is_open.is_(True)).all()
if self.freqtrade.state != State.RUNNING: if self._freqtrade.state != State.RUNNING:
raise RPCException('*Status:* `trader is not running`') raise RPCException('*Status:* `trader is not running`')
elif not trades: elif not trades:
raise RPCException('*Status:* `no active trade`') raise RPCException('*Status:* `no active trade`')
@ -102,7 +102,7 @@ class RPC(object):
def _rpc_status_table(self) -> DataFrame: def _rpc_status_table(self) -> DataFrame:
trades = Trade.query.filter(Trade.is_open.is_(True)).all() trades = Trade.query.filter(Trade.is_open.is_(True)).all()
if self.freqtrade.state != State.RUNNING: if self._freqtrade.state != State.RUNNING:
raise RPCException('*Status:* `trader is not running`') raise RPCException('*Status:* `trader is not running`')
elif not trades: elif not trades:
raise RPCException('*Status:* `no active order`') raise RPCException('*Status:* `no active order`')
@ -132,7 +132,7 @@ class RPC(object):
if not (isinstance(timescale, int) and timescale > 0): if not (isinstance(timescale, int) and timescale > 0):
raise RPCException('*Daily [n]:* `must be an integer greater than 0`') raise RPCException('*Daily [n]:* `must be an integer greater than 0`')
fiat = self.freqtrade.fiat_converter fiat = self._freqtrade.fiat_converter
for day in range(0, timescale): for day in range(0, timescale):
profitday = today - timedelta(days=day) profitday = today - timedelta(days=day)
trades = Trade.query \ trades = Trade.query \
@ -216,7 +216,7 @@ class RPC(object):
# FIX: we want to keep fiatconverter in a state/environment, # FIX: we want to keep fiatconverter in a state/environment,
# doing this will utilize its caching functionallity, instead we reinitialize it here # doing this will utilize its caching functionallity, instead we reinitialize it here
fiat = self.freqtrade.fiat_converter fiat = self._freqtrade.fiat_converter
# Prepare data to display # Prepare data to display
profit_closed_coin = round(sum(profit_closed_coin), 8) profit_closed_coin = round(sum(profit_closed_coin), 8)
profit_closed_percent = round(nan_to_num(mean(profit_closed_percent)) * 100, 2) profit_closed_percent = round(nan_to_num(mean(profit_closed_percent)) * 100, 2)
@ -277,23 +277,23 @@ class RPC(object):
if total == 0.0: if total == 0.0:
raise RPCException('`All balances are zero.`') raise RPCException('`All balances are zero.`')
fiat = self.freqtrade.fiat_converter fiat = self._freqtrade.fiat_converter
symbol = fiat_display_currency symbol = fiat_display_currency
value = fiat.convert_amount(total, 'BTC', symbol) value = fiat.convert_amount(total, 'BTC', symbol)
return output, total, symbol, value return output, total, symbol, value
def _rpc_start(self) -> str: def _rpc_start(self) -> str:
""" Handler for start """ """ Handler for start """
if self.freqtrade.state == State.RUNNING: if self._freqtrade.state == State.RUNNING:
return '*Status:* `already running`' return '*Status:* `already running`'
self.freqtrade.state = State.RUNNING self._freqtrade.state = State.RUNNING
return '`Starting trader ...`' return '`Starting trader ...`'
def _rpc_stop(self) -> str: def _rpc_stop(self) -> str:
""" Handler for stop """ """ Handler for stop """
if self.freqtrade.state == State.RUNNING: if self._freqtrade.state == State.RUNNING:
self.freqtrade.state = State.STOPPED self._freqtrade.state = State.STOPPED
return '`Stopping trader ...`' return '`Stopping trader ...`'
return '*Status:* `already stopped`' return '*Status:* `already stopped`'
@ -333,10 +333,10 @@ class RPC(object):
# Get current rate and execute sell # Get current rate and execute sell
current_rate = exchange.get_ticker(trade.pair, False)['bid'] current_rate = exchange.get_ticker(trade.pair, False)['bid']
self.freqtrade.execute_sell(trade, current_rate) self._freqtrade.execute_sell(trade, current_rate)
# ---- EOF def _exec_forcesell ---- # ---- EOF def _exec_forcesell ----
if self.freqtrade.state != State.RUNNING: if self._freqtrade.state != State.RUNNING:
raise RPCException('`trader is not running`') raise RPCException('`trader is not running`')
if trade_id == 'all': if trade_id == 'all':
@ -364,7 +364,7 @@ class RPC(object):
Handler for performance. Handler for performance.
Shows a performance statistic from finished trades Shows a performance statistic from finished trades
""" """
if self.freqtrade.state != State.RUNNING: if self._freqtrade.state != State.RUNNING:
raise RPCException('`trader is not running`') raise RPCException('`trader is not running`')
pair_rates = Trade.session.query(Trade.pair, pair_rates = Trade.session.query(Trade.pair,
@ -381,7 +381,7 @@ class RPC(object):
def _rpc_count(self) -> List[Trade]: def _rpc_count(self) -> List[Trade]:
""" Returns the number of trades running """ """ Returns the number of trades running """
if self.freqtrade.state != State.RUNNING: if self._freqtrade.state != State.RUNNING:
raise RPCException('`trader is not running`') raise RPCException('`trader is not running`')
return Trade.query.filter(Trade.is_open.is_(True)).all() return Trade.query.filter(Trade.is_open.is_(True)).all()