Make Pylint Happy chapter 1
This commit is contained in:
parent
d274f13480
commit
390501bac0
@ -1,11 +1,11 @@
|
||||
"""
|
||||
Functions to analyze ticker data with indicators and produce buy and sell signals
|
||||
"""
|
||||
import arrow
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
from pandas import DataFrame, to_datetime
|
||||
from typing import Dict, List
|
||||
import arrow
|
||||
from pandas import DataFrame, to_datetime
|
||||
from freqtrade.exchange import get_ticker_history
|
||||
from freqtrade.logger import Logger
|
||||
from freqtrade.strategy.strategy import Strategy
|
||||
@ -188,7 +188,6 @@ class Analyze(object):
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def tickerdata_to_dataframe(self, tickerdata: Dict[str, List]) -> Dict[str, DataFrame]:
|
||||
"""
|
||||
Creates a dataframe and populates indicators for given ticker data
|
||||
|
@ -2,16 +2,15 @@
|
||||
Freqtrade is the main module of this bot. It contains the class Freqtrade()
|
||||
"""
|
||||
|
||||
import logging
|
||||
import arrow
|
||||
import copy
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
import traceback
|
||||
from cachetools import cached, TTLCache
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Optional, Any, Callable
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import arrow
|
||||
from cachetools import cached, TTLCache
|
||||
from freqtrade.analyze import Analyze
|
||||
from freqtrade.constants import Constants
|
||||
from freqtrade.fiat_convert import CryptoToFiatConverter
|
||||
|
@ -97,10 +97,11 @@ def download_pairs(datadir, pairs: List[str], ticker_interval: int) -> bool:
|
||||
try:
|
||||
download_backtesting_testdata(datadir, pair=pair, interval=ticker_interval)
|
||||
except BaseException:
|
||||
logger.info('Failed to download the pair: "{pair}", Interval: {interval} min'.format(
|
||||
pair=pair,
|
||||
interval=ticker_interval,
|
||||
))
|
||||
logger.info(
|
||||
'Failed to download the pair: "%s", Interval: %s min',
|
||||
pair,
|
||||
ticker_interval
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
@ -115,10 +116,11 @@ def download_backtesting_testdata(datadir: str, pair: str, interval: int = 5) ->
|
||||
"""
|
||||
|
||||
path = make_testdata_path(datadir)
|
||||
logger.info('Download the pair: "{pair}", Interval: {interval} min'.format(
|
||||
pair=pair,
|
||||
interval=interval,
|
||||
))
|
||||
logger.info(
|
||||
'Download the pair: "%s", Interval: %s min',
|
||||
pair,
|
||||
interval
|
||||
)
|
||||
|
||||
filepair = pair.replace("-", "_")
|
||||
filename = os.path.join(path, '{pair}-{interval}.json'.format(
|
||||
@ -129,8 +131,8 @@ def download_backtesting_testdata(datadir: str, pair: str, interval: int = 5) ->
|
||||
if os.path.isfile(filename):
|
||||
with open(filename, "rt") as file:
|
||||
data = json.load(file)
|
||||
logger.debug("Current Start: {}".format(data[1]['T']))
|
||||
logger.debug("Current End: {}".format(data[-1:][0]['T']))
|
||||
logger.debug("Current Start: %s", data[1]['T'])
|
||||
logger.debug("Current End: %s", data[-1:][0]['T'])
|
||||
else:
|
||||
data = []
|
||||
logger.debug("Current Start: None")
|
||||
@ -140,8 +142,8 @@ def download_backtesting_testdata(datadir: str, pair: str, interval: int = 5) ->
|
||||
for row in new_data:
|
||||
if row not in data:
|
||||
data.append(row)
|
||||
logger.debug("New Start: {}".format(data[1]['T']))
|
||||
logger.debug("New End: {}".format(data[-1:][0]['T']))
|
||||
logger.debug("New Start: %s", data[1]['T'])
|
||||
logger.debug("New End: %s", data[-1:][0]['T'])
|
||||
data = sorted(data, key=lambda data: data['T'])
|
||||
|
||||
misc.file_dump_json(filename, data)
|
||||
|
@ -25,7 +25,7 @@ import freqtrade.vendor.qtpylib.indicators as qtpylib
|
||||
from freqtrade.configuration import Configuration
|
||||
from freqtrade.optimize import load_data
|
||||
from freqtrade.arguments import Arguments
|
||||
from freqtrade.optimize.backtesting import Backtesting, setup_configuration
|
||||
from freqtrade.optimize.backtesting import Backtesting
|
||||
from freqtrade.logger import Logger
|
||||
from user_data.hyperopt_conf import hyperopt_optimize_conf
|
||||
|
||||
@ -46,7 +46,6 @@ class Hyperopt(Backtesting):
|
||||
self.logging = Logger(name=__name__, level=config['loglevel'])
|
||||
self.logger = self.logging.get_logger()
|
||||
|
||||
|
||||
# set TARGET_TRADES to suit your number concurrent trades so its realistic
|
||||
# to the number of days
|
||||
self.target_trades = 600
|
||||
@ -353,6 +352,9 @@ class Hyperopt(Backtesting):
|
||||
Define the buy strategy parameters to be used by hyperopt
|
||||
"""
|
||||
def populate_buy_trend(dataframe: DataFrame) -> DataFrame:
|
||||
"""
|
||||
Buy strategy Hyperopt will build and use
|
||||
"""
|
||||
conditions = []
|
||||
# GUARDS AND TRENDS
|
||||
if 'uptrend_long_ema' in params and params['uptrend_long_ema']['enabled']:
|
||||
@ -513,8 +515,9 @@ class Hyperopt(Backtesting):
|
||||
self.current_tries = len(self.trials.results)
|
||||
self.total_tries += self.current_tries
|
||||
self.logger.info(
|
||||
'Continuing with trials. Current: {}, Total: {}'
|
||||
.format(self.current_tries, self.total_tries)
|
||||
'Continuing with trials. Current: %d, Total: %d',
|
||||
self.current_tries,
|
||||
self.total_tries
|
||||
)
|
||||
|
||||
try:
|
||||
@ -557,7 +560,10 @@ class Hyperopt(Backtesting):
|
||||
"""
|
||||
Hyperopt SIGINT handler
|
||||
"""
|
||||
self.logger.info('Hyperopt received {}'.format(signal.Signals(sig).name))
|
||||
self.logger.info(
|
||||
'Hyperopt received %s',
|
||||
signal.Signals(sig).name
|
||||
)
|
||||
|
||||
self.save_trials()
|
||||
self.log_trials_result()
|
||||
@ -580,9 +586,7 @@ def start(args) -> None:
|
||||
logger.info('Starting freqtrade in Hyperopt mode')
|
||||
|
||||
# Initialize configuration
|
||||
#config = setup_configuration(args)
|
||||
|
||||
# Monkey patch of the configuration with hyperopt_conf.py
|
||||
# Monkey patch the configuration with hyperopt_conf.py
|
||||
configuration = Configuration(args)
|
||||
optimize_config = hyperopt_optimize_conf()
|
||||
config = configuration._load_backtesting_config(optimize_config)
|
||||
|
@ -1,3 +1,7 @@
|
||||
"""
|
||||
This module contains the class to persist trades into SQLite
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from decimal import Decimal, getcontext
|
||||
@ -72,6 +76,9 @@ def clean_dry_run_db() -> None:
|
||||
|
||||
|
||||
class Trade(_DECL_BASE):
|
||||
"""
|
||||
Class used to define a trade structure
|
||||
"""
|
||||
__tablename__ = 'trades'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
|
@ -2,9 +2,9 @@
|
||||
This module contains class to define a RPC communications
|
||||
"""
|
||||
|
||||
import arrow
|
||||
from decimal import Decimal
|
||||
from datetime import datetime, timedelta
|
||||
import arrow
|
||||
from pandas import DataFrame
|
||||
import sqlalchemy as sql
|
||||
from freqtrade.logger import Logger
|
||||
@ -18,7 +18,6 @@ class RPC(object):
|
||||
"""
|
||||
RPC class can be used to have extra feature, like bot data, and access to DB data
|
||||
"""
|
||||
|
||||
def __init__(self, freqtrade) -> None:
|
||||
"""
|
||||
Initializes all enabled rpc modules
|
||||
@ -147,7 +146,10 @@ class RPC(object):
|
||||
),
|
||||
symbol=fiat_display_currency
|
||||
),
|
||||
'{value} trade{s}'.format(value=value['trades'], s='' if value['trades'] < 2 else 's'),
|
||||
'{value} trade{s}'.format(
|
||||
value=value['trades'],
|
||||
s='' if value['trades'] < 2 else 's'
|
||||
),
|
||||
]
|
||||
for key, value in profit_days.items()
|
||||
]
|
||||
@ -182,15 +184,18 @@ class RPC(object):
|
||||
current_rate = exchange.get_ticker(trade.pair, False)['bid']
|
||||
profit_percent = trade.calc_profit_percent(rate=current_rate)
|
||||
|
||||
profit_all_coin.append(trade.calc_profit(rate=Decimal(trade.close_rate or current_rate)))
|
||||
profit_all_coin.append(
|
||||
trade.calc_profit(rate=Decimal(trade.close_rate or current_rate))
|
||||
)
|
||||
profit_all_percent.append(profit_percent)
|
||||
|
||||
best_pair = Trade.session.query(Trade.pair,
|
||||
sql.func.sum(Trade.close_profit).label('profit_sum')) \
|
||||
best_pair = Trade.session.query(
|
||||
Trade.pair,
|
||||
sql.func.sum(Trade.close_profit).label('profit_sum')
|
||||
)\
|
||||
.filter(Trade.is_open.is_(False))\
|
||||
.group_by(Trade.pair)\
|
||||
.order_by(sql.text('profit_sum DESC')) \
|
||||
.first()
|
||||
.order_by(sql.text('profit_sum DESC')).first()
|
||||
|
||||
if not best_pair:
|
||||
return (True, '*Status:* `no closed trade`')
|
||||
@ -258,12 +263,15 @@ class RPC(object):
|
||||
currency["Rate"] = exchange.get_ticker('BTC_' + coin, False)['bid']
|
||||
currency['BTC'] = currency["Rate"] * currency["Balance"]
|
||||
total = total + currency['BTC']
|
||||
output.append({'currency': currency['Currency'],
|
||||
output.append(
|
||||
{
|
||||
'currency': currency['Currency'],
|
||||
'available': currency['Available'],
|
||||
'balance': currency['Balance'],
|
||||
'pending': currency['Pending'],
|
||||
'est_btc': currency['BTC']
|
||||
})
|
||||
}
|
||||
)
|
||||
fiat = self.freqtrade.fiat_converter
|
||||
symbol = fiat_display_currency
|
||||
value = fiat.convert_amount(total, 'BTC', symbol)
|
||||
@ -275,7 +283,7 @@ class RPC(object):
|
||||
"""
|
||||
if self.freqtrade.get_state() == State.RUNNING:
|
||||
return (True, '*Status:* `already running`')
|
||||
else:
|
||||
|
||||
self.freqtrade.update_state(State.RUNNING)
|
||||
return (False, '`Starting trader ...`')
|
||||
|
||||
@ -286,7 +294,7 @@ class RPC(object):
|
||||
if self.freqtrade.get_state() == State.RUNNING:
|
||||
self.freqtrade.update_state(State.STOPPED)
|
||||
return (False, '`Stopping trader ...`')
|
||||
else:
|
||||
|
||||
return (True, '*Status:* `already stopped`')
|
||||
|
||||
# FIX: no test for this!!!!
|
||||
|
@ -10,7 +10,6 @@ class RPCManager(object):
|
||||
"""
|
||||
Class to manage RPC objects (Telegram, Slack, ...)
|
||||
"""
|
||||
|
||||
def __init__(self, freqtrade) -> None:
|
||||
"""
|
||||
Initializes all enabled rpc modules
|
||||
|
@ -1,14 +1,16 @@
|
||||
# pragma pylint: disable=unused-argument, unused-variable, protected-access, invalid-name
|
||||
|
||||
"""
|
||||
This module manage Telegram communication
|
||||
"""
|
||||
|
||||
from typing import Any, Callable
|
||||
from freqtrade.rpc.rpc import RPC
|
||||
from tabulate import tabulate
|
||||
from telegram import Bot, ParseMode, ReplyKeyboardMarkup, Update
|
||||
from telegram.error import NetworkError, TelegramError
|
||||
from telegram.ext import CommandHandler, Updater
|
||||
from freqtrade.__init__ import __version__
|
||||
from freqtrade.rpc.rpc import RPC
|
||||
|
||||
|
||||
def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[..., Any]:
|
||||
@ -17,10 +19,10 @@ def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[
|
||||
:param command_handler: Telegram CommandHandler
|
||||
:return: decorated function
|
||||
"""
|
||||
|
||||
#def wrapper(self, bot: Bot, update: Update):
|
||||
def wrapper(self, *args, **kwargs):
|
||||
|
||||
"""
|
||||
Decorator logic
|
||||
"""
|
||||
update = kwargs.get('update') or args[1]
|
||||
|
||||
# Reject unauthorized messages
|
||||
@ -45,6 +47,7 @@ def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
class Telegram(RPC):
|
||||
"""
|
||||
Telegram, this class send messages to Telegram
|
||||
@ -57,7 +60,7 @@ class Telegram(RPC):
|
||||
"""
|
||||
super().__init__(freqtrade)
|
||||
|
||||
self._updater = Updater = None
|
||||
self._updater = None
|
||||
self._config = freqtrade.config
|
||||
self._init()
|
||||
|
||||
@ -294,7 +297,6 @@ class Telegram(RPC):
|
||||
(error, msg) = self.rpc_stop()
|
||||
self.send_msg(msg, bot=bot)
|
||||
|
||||
# FIX: no test for this!!!!
|
||||
@authorized_only
|
||||
def _forcesell(self, bot: Bot, update: Update) -> None:
|
||||
"""
|
||||
@ -370,10 +372,12 @@ class Telegram(RPC):
|
||||
"*/status [table]:* `Lists all open trades`\n" \
|
||||
" *table :* `will display trades in a table`\n" \
|
||||
"*/profit:* `Lists cumulative profit from all finished trades`\n" \
|
||||
"*/forcesell <trade_id>|all:* `Instantly sells the given trade or all trades, regardless of profit`\n" \
|
||||
"*/forcesell <trade_id>|all:* `Instantly sells the given trade or all trades, " \
|
||||
"regardless of profit`\n" \
|
||||
"*/performance:* `Show performance of each finished trade grouped by pair`\n" \
|
||||
"*/daily <n>:* `Shows profit or loss per day, over the last n days`\n" \
|
||||
"*/count:* `Show number of trades running compared to allowed number of trades`\n" \
|
||||
"*/count:* `Show number of trades running compared to allowed number of trades`" \
|
||||
"\n" \
|
||||
"*/balance:* `Show account balance per currency`\n" \
|
||||
"*/help:* `This help message`\n" \
|
||||
"*/version:* `Show version`"
|
||||
@ -391,7 +395,8 @@ class Telegram(RPC):
|
||||
"""
|
||||
self.send_msg('*Version:* `{}`'.format(__version__), bot=bot)
|
||||
|
||||
def send_msg(self, msg: str, bot: Bot = None, parse_mode: ParseMode = ParseMode.MARKDOWN) -> None:
|
||||
def send_msg(self, msg: str, bot: Bot = None,
|
||||
parse_mode: ParseMode = ParseMode.MARKDOWN) -> None:
|
||||
"""
|
||||
Send given markdown message
|
||||
:param msg: message
|
||||
|
@ -1,14 +1,8 @@
|
||||
# pragma pylint: disable=missing-docstring,W0212,C0103
|
||||
import logging
|
||||
import os
|
||||
import pytest
|
||||
from copy import deepcopy
|
||||
|
||||
#from freqtrade.optimize.hyperopt import EXPECTED_MAX_PROFIT, start, \
|
||||
# log_results, save_trials, read_trials, generate_roi_table
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from freqtrade.optimize.hyperopt import Hyperopt, start
|
||||
from freqtrade.optimize.hyperopt import Hyperopt
|
||||
import freqtrade.tests.conftest as tt # test tools
|
||||
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
# pragma pylint: disable=protected-access, invalid-name
|
||||
|
||||
"""
|
||||
Unit test file for configuration.py
|
||||
"""
|
||||
@ -270,4 +271,3 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
||||
'Parameter --export detected: {} ...'.format(config['export']),
|
||||
caplog.record_tuples
|
||||
)
|
||||
|
||||
|
@ -8,7 +8,6 @@ from freqtrade.constants import Constants
|
||||
def test_constant_object() -> None:
|
||||
"""
|
||||
Test the Constants object has the mandatory Constants
|
||||
:return: None
|
||||
"""
|
||||
assert hasattr(Constants, 'CONF_SCHEMA')
|
||||
assert hasattr(Constants, 'DYNAMIC_WHITELIST')
|
||||
@ -19,11 +18,9 @@ def test_constant_object() -> None:
|
||||
assert hasattr(Constants, 'DEFAULT_STRATEGY')
|
||||
|
||||
|
||||
|
||||
def test_conf_schema() -> None:
|
||||
"""
|
||||
Test the CONF_SCHEMA is from the right type
|
||||
:return:
|
||||
"""
|
||||
constant = Constants()
|
||||
assert isinstance(constant.CONF_SCHEMA, dict)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
import pandas
|
||||
from freqtrade.optimize import load_data
|
||||
from freqtrade.analyze import Analyze, SignalType
|
||||
from freqtrade.analyze import Analyze
|
||||
|
||||
_pairs = ['BTC_ETH']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user