add argparse and implement basic arguments
This commit is contained in:
parent
a1b91ad1ea
commit
e01c85bb3a
@ -10,8 +10,6 @@ from freqtrade import exchange
|
|||||||
from freqtrade.exchange import Bittrex, get_ticker_history
|
from freqtrade.exchange import Bittrex, get_ticker_history
|
||||||
from freqtrade.vendor.qtpylib.indicators import awesome_oscillator
|
from freqtrade.vendor.qtpylib.indicators import awesome_oscillator
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,21 +5,19 @@ import logging
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, Optional
|
|
||||||
from signal import signal, SIGINT, SIGABRT, SIGTERM
|
from signal import signal, SIGINT, SIGABRT, SIGTERM
|
||||||
|
from typing import Dict, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
|
|
||||||
from freqtrade import __version__, exchange, persistence
|
from freqtrade import __version__, exchange, persistence
|
||||||
from freqtrade.analyze import get_buy_signal
|
from freqtrade.analyze import get_buy_signal
|
||||||
from freqtrade.misc import CONF_SCHEMA, State, get_state, update_state
|
from freqtrade.misc import CONF_SCHEMA, State, get_state, update_state, build_arg_parser
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.rpc import telegram
|
from freqtrade.rpc import telegram
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
logger = logging.getLogger('freqtrade')
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
_CONF = {}
|
_CONF = {}
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ def _process() -> bool:
|
|||||||
Trade.session.add(trade)
|
Trade.session.add(trade)
|
||||||
state_changed = True
|
state_changed = True
|
||||||
else:
|
else:
|
||||||
logging.info('Got no buy signal...')
|
logger.info('Got no buy signal...')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.exception('Unable to create trade')
|
logger.exception('Unable to create trade')
|
||||||
|
|
||||||
@ -163,7 +161,10 @@ def create_trade(stake_amount: float) -> Optional[Trade]:
|
|||||||
if one pair triggers the buy_signal a new trade record gets created
|
if one pair triggers the buy_signal a new trade record gets created
|
||||||
:param stake_amount: amount of btc to spend
|
:param stake_amount: amount of btc to spend
|
||||||
"""
|
"""
|
||||||
logger.info('Creating new trade with stake_amount: %f ...', stake_amount)
|
logger.info(
|
||||||
|
'Checking buy signals to create a new trade with stake_amount: %f ...',
|
||||||
|
stake_amount
|
||||||
|
)
|
||||||
whitelist = copy.deepcopy(_CONF['exchange']['pair_whitelist'])
|
whitelist = copy.deepcopy(_CONF['exchange']['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:
|
||||||
@ -255,15 +256,28 @@ def main():
|
|||||||
Loads and validates the config and handles the main loop
|
Loads and validates the config and handles the main loop
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
logger.info('Starting freqtrade %s', __version__)
|
|
||||||
|
|
||||||
global _CONF
|
global _CONF
|
||||||
with open('config.json') as file:
|
args = build_arg_parser().parse_args()
|
||||||
_CONF = json.load(file)
|
|
||||||
|
|
||||||
|
# Initialize logger
|
||||||
|
logging.basicConfig(
|
||||||
|
level=args.loglevel,
|
||||||
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
'Starting freqtrade %s (loglevel=%s)',
|
||||||
|
__version__,
|
||||||
|
logging.getLevelName(args.loglevel)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Load and validate configuration
|
||||||
|
with open(args.config) as file:
|
||||||
|
_CONF = json.load(file)
|
||||||
logger.info('Validating configuration ...')
|
logger.info('Validating configuration ...')
|
||||||
validate(_CONF, CONF_SCHEMA)
|
validate(_CONF, CONF_SCHEMA)
|
||||||
|
|
||||||
|
# Initialize all modules and start main loop
|
||||||
init(_CONF)
|
init(_CONF)
|
||||||
old_state = get_state()
|
old_state = get_state()
|
||||||
logger.info('Initial State: %s', old_state)
|
logger.info('Initial State: %s', old_state)
|
||||||
@ -273,7 +287,7 @@ def main():
|
|||||||
# Log state transition
|
# Log state transition
|
||||||
if new_state != old_state:
|
if new_state != old_state:
|
||||||
telegram.send_msg('*Status:* `{}`'.format(new_state.name.lower()))
|
telegram.send_msg('*Status:* `{}`'.format(new_state.name.lower()))
|
||||||
logging.info('Changing state to: %s', new_state.name)
|
logger.info('Changing state to: %s', new_state.name)
|
||||||
|
|
||||||
if new_state == State.STOPPED:
|
if new_state == State.STOPPED:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
|
import argparse
|
||||||
import enum
|
import enum
|
||||||
|
import logging
|
||||||
|
|
||||||
from wrapt import synchronized
|
from wrapt import synchronized
|
||||||
|
|
||||||
|
from freqtrade import __version__
|
||||||
|
|
||||||
|
|
||||||
class State(enum.Enum):
|
class State(enum.Enum):
|
||||||
RUNNING = 0
|
RUNNING = 0
|
||||||
@ -32,6 +36,35 @@ def get_state() -> State:
|
|||||||
return _STATE
|
return _STATE
|
||||||
|
|
||||||
|
|
||||||
|
def build_arg_parser() -> argparse.ArgumentParser:
|
||||||
|
""" Builds and returns an ArgumentParser instance """
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Simple High Frequency Trading Bot for crypto currencies'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-c', '--config',
|
||||||
|
help='specify configuration file (default: config.json)',
|
||||||
|
dest='config',
|
||||||
|
default='config.json',
|
||||||
|
type=str,
|
||||||
|
metavar='PATH',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-v', '--verbose',
|
||||||
|
help='be verbose',
|
||||||
|
action='store_const',
|
||||||
|
dest='loglevel',
|
||||||
|
const=logging.DEBUG,
|
||||||
|
default=logging.INFO,
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--version',
|
||||||
|
action='version',
|
||||||
|
version='%(prog)s {}'.format(__version__),
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
# Required json-schema for user specified config
|
# Required json-schema for user specified config
|
||||||
CONF_SCHEMA = {
|
CONF_SCHEMA = {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
|
@ -9,8 +9,6 @@ from sqlalchemy.ext.declarative import declarative_base
|
|||||||
from sqlalchemy.orm.scoping import scoped_session
|
from sqlalchemy.orm.scoping import scoped_session
|
||||||
from sqlalchemy.orm.session import sessionmaker
|
from sqlalchemy.orm.session import sessionmaker
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_CONF = {}
|
_CONF = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user