more advanced use of --timerange
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
||||
import logging
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
from typing import Any, Callable, Dict, List
|
||||
|
||||
from jsonschema import Draft4Validator, validate
|
||||
@@ -192,9 +193,9 @@ def build_subcommands(parser: argparse.ArgumentParser) -> None:
|
||||
)
|
||||
backtesting_cmd.add_argument(
|
||||
'--timerange',
|
||||
help='Use the last N ticks of data.',
|
||||
help='Specify what timerange of data to use.',
|
||||
default=None,
|
||||
type=int,
|
||||
type=str,
|
||||
dest='timerange',
|
||||
)
|
||||
|
||||
@@ -224,14 +225,44 @@ def build_subcommands(parser: argparse.ArgumentParser) -> None:
|
||||
metavar='INT',
|
||||
)
|
||||
hyperopt_cmd.add_argument(
|
||||
'-tp', '--timerange',
|
||||
help='Use the last N ticks of data.',
|
||||
'--timerange',
|
||||
help='Specify what timerange of data to use.',
|
||||
default=None,
|
||||
type=int,
|
||||
type=str,
|
||||
dest='timerange',
|
||||
)
|
||||
|
||||
|
||||
def parse_timerange(text):
|
||||
if text is None:
|
||||
return None
|
||||
syntax = [('^-(\d{8})$', (None, 'date')),
|
||||
('^(\d{8})-$', ('date', None)),
|
||||
('^(\d{8})-(\d{8})$', ('date', 'date')),
|
||||
('^(-\d+)$', (None, 'line')),
|
||||
('^(\d+)-$', ('line', None)),
|
||||
('^(\d+)-(\d+)$', ('index', 'index'))]
|
||||
for rex, stype in syntax:
|
||||
# Apply the regular expression to text
|
||||
m = re.match(rex, text)
|
||||
if m: # Regex has matched
|
||||
rvals = m.groups()
|
||||
n = 0
|
||||
start = None
|
||||
stop = None
|
||||
if stype[0]:
|
||||
start = rvals[n]
|
||||
if stype[0] != 'date':
|
||||
start = int(start)
|
||||
n += 1
|
||||
if stype[1]:
|
||||
stop = rvals[n]
|
||||
if stype[1] != 'date':
|
||||
stop = int(stop)
|
||||
return (stype, start, stop)
|
||||
raise Exception('Incorrect syntax for timerange "%s"' % text)
|
||||
|
||||
|
||||
# Required json-schema for user specified config
|
||||
CONF_SCHEMA = {
|
||||
'type': 'object',
|
||||
|
Reference in New Issue
Block a user