Add --endx option, tidy up options. Add --type option.
This commit is contained in:
parent
58d37463c6
commit
4c8b739c0c
1 changed files with 62 additions and 21 deletions
|
@ -93,6 +93,11 @@ def build_parser():
|
||||||
msg = "Not a valid date: '{0}'.".format(s)
|
msg = "Not a valid date: '{0}'.".format(s)
|
||||||
raise argparse.ArgumentTypeError(msg)
|
raise argparse.ArgumentTypeError(msg)
|
||||||
|
|
||||||
|
def previous_valid_date(s):
|
||||||
|
return str(
|
||||||
|
datetime.strptime(valid_date(s), "%Y-%m-%d").date() - timedelta(days=1)
|
||||||
|
)
|
||||||
|
|
||||||
def following_valid_date(s):
|
def following_valid_date(s):
|
||||||
return str(
|
return str(
|
||||||
datetime.strptime(valid_date(s), "%Y-%m-%d").date() + timedelta(days=1)
|
datetime.strptime(valid_date(s), "%Y-%m-%d").date() + timedelta(days=1)
|
||||||
|
@ -101,7 +106,14 @@ def build_parser():
|
||||||
def today():
|
def today():
|
||||||
return str(datetime.now().date())
|
return str(datetime.now().date())
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Fetch historical price data")
|
def formatter(prog):
|
||||||
|
return argparse.HelpFormatter(prog, max_help_position=50)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog="pricehist",
|
||||||
|
description="Fetch historical price data",
|
||||||
|
formatter_class=formatter,
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v",
|
"-v",
|
||||||
|
@ -112,9 +124,17 @@ def build_parser():
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(title="commands", dest="command")
|
subparsers = parser.add_subparsers(title="commands", dest="command")
|
||||||
|
|
||||||
subparsers.add_parser("sources", help="list sources")
|
subparsers.add_parser(
|
||||||
|
"sources",
|
||||||
|
help="list sources",
|
||||||
|
formatter_class=formatter,
|
||||||
|
)
|
||||||
|
|
||||||
source_parser = subparsers.add_parser("source", help="show source details")
|
source_parser = subparsers.add_parser(
|
||||||
|
"source",
|
||||||
|
help="show source details",
|
||||||
|
formatter_class=formatter,
|
||||||
|
)
|
||||||
source_parser.add_argument(
|
source_parser.add_argument(
|
||||||
"identifier",
|
"identifier",
|
||||||
metavar="SOURCE",
|
metavar="SOURCE",
|
||||||
|
@ -127,13 +147,14 @@ def build_parser():
|
||||||
"fetch",
|
"fetch",
|
||||||
help="fetch prices",
|
help="fetch prices",
|
||||||
usage=(
|
usage=(
|
||||||
"pricehist fetch SOURCE PAIR "
|
"pricehist fetch SOURCE PAIR [-h] "
|
||||||
"[-h] (-s DATE | -sx DATE) [-e DATE] [-o FMT] "
|
"[--type TYPE] (-s DATE | -sx DATE) [-e DATE | -ex DATE] [-o FMT] "
|
||||||
|
"[--invert] [--quantize INT] "
|
||||||
"[--rename-base SYM] [--rename-quote SYM] [--rename-time TIME] "
|
"[--rename-base SYM] [--rename-quote SYM] [--rename-time TIME] "
|
||||||
"[--format-decimal CHAR] [--format-thousands CHAR] "
|
"[--format-decimal CHAR] [--format-thousands CHAR] "
|
||||||
"[--format-symbol rightspace|right|leftspace|left] [--format-datesep CHAR] "
|
"[--format-symbol rightspace|right|leftspace|left] [--format-datesep CHAR]"
|
||||||
"[--quantize INT]"
|
|
||||||
),
|
),
|
||||||
|
formatter_class=formatter,
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"source",
|
"source",
|
||||||
|
@ -148,6 +169,14 @@ def build_parser():
|
||||||
type=str,
|
type=str,
|
||||||
help="pair, usually BASE/QUOTE, e.g. BTC/USD",
|
help="pair, usually BASE/QUOTE, e.g. BTC/USD",
|
||||||
)
|
)
|
||||||
|
fetch_parser.add_argument(
|
||||||
|
"-t",
|
||||||
|
"--type",
|
||||||
|
dest="type",
|
||||||
|
metavar="TYPE",
|
||||||
|
type=str,
|
||||||
|
help="price type, e.g. close",
|
||||||
|
)
|
||||||
fetch_start_group = fetch_parser.add_mutually_exclusive_group(required=True)
|
fetch_start_group = fetch_parser.add_mutually_exclusive_group(required=True)
|
||||||
fetch_start_group.add_argument(
|
fetch_start_group.add_argument(
|
||||||
"-s",
|
"-s",
|
||||||
|
@ -165,7 +194,9 @@ def build_parser():
|
||||||
type=following_valid_date,
|
type=following_valid_date,
|
||||||
help="start date, exclusive",
|
help="start date, exclusive",
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
|
||||||
|
fetch_end_group = fetch_parser.add_mutually_exclusive_group(required=False)
|
||||||
|
fetch_end_group.add_argument(
|
||||||
"-e",
|
"-e",
|
||||||
"--end",
|
"--end",
|
||||||
dest="end",
|
dest="end",
|
||||||
|
@ -174,6 +205,16 @@ def build_parser():
|
||||||
default=today(),
|
default=today(),
|
||||||
help="end date, inclusive (default: today)",
|
help="end date, inclusive (default: today)",
|
||||||
)
|
)
|
||||||
|
fetch_end_group.add_argument(
|
||||||
|
"-ex",
|
||||||
|
"--endx",
|
||||||
|
dest="end",
|
||||||
|
metavar="DATE",
|
||||||
|
type=previous_valid_date,
|
||||||
|
default=today(),
|
||||||
|
help="end date, exclusive",
|
||||||
|
)
|
||||||
|
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
"--output",
|
"--output",
|
||||||
|
@ -189,6 +230,13 @@ def build_parser():
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="invert the price, swapping base and quote",
|
help="invert the price, swapping base and quote",
|
||||||
)
|
)
|
||||||
|
fetch_parser.add_argument(
|
||||||
|
"--quantize",
|
||||||
|
dest="quantize",
|
||||||
|
metavar="INT",
|
||||||
|
type=int,
|
||||||
|
help="quantize to the given number of decimal places",
|
||||||
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"--rename-base",
|
"--rename-base",
|
||||||
dest="renamebase",
|
dest="renamebase",
|
||||||
|
@ -208,43 +256,36 @@ def build_parser():
|
||||||
dest="renametime",
|
dest="renametime",
|
||||||
metavar="TIME",
|
metavar="TIME",
|
||||||
type=str,
|
type=str,
|
||||||
help="set a particular time of day, e.g. 23:59:59",
|
help="set a particular time of day (default: 00:00:00)",
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"--format-decimal",
|
"--format-decimal",
|
||||||
dest="formatdecimal",
|
dest="formatdecimal",
|
||||||
metavar="CHAR",
|
metavar="CHAR",
|
||||||
type=str,
|
type=str,
|
||||||
help="decimal point",
|
help="decimal point (default: '.')",
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"--format-thousands",
|
"--format-thousands",
|
||||||
dest="formatthousands",
|
dest="formatthousands",
|
||||||
metavar="CHAR",
|
metavar="CHAR",
|
||||||
type=str,
|
type=str,
|
||||||
help="thousands separator",
|
help="thousands separator (default: '')",
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"--format-symbol",
|
"--format-symbol",
|
||||||
dest="formatsymbol",
|
dest="formatsymbol",
|
||||||
metavar="CHAR",
|
metavar="LOC",
|
||||||
type=str,
|
type=str,
|
||||||
choices=["rightspace", "right", "leftspace", "left"],
|
choices=["rightspace", "right", "leftspace", "left"],
|
||||||
help="placement of the quote's commodity symbol relative to its amount",
|
help="commodity symbol placement (default: rightspace)",
|
||||||
)
|
)
|
||||||
fetch_parser.add_argument(
|
fetch_parser.add_argument(
|
||||||
"--format-datesep",
|
"--format-datesep",
|
||||||
dest="formatdatesep",
|
dest="formatdatesep",
|
||||||
metavar="CHAR",
|
metavar="CHAR",
|
||||||
type=str,
|
type=str,
|
||||||
help="date separator",
|
help="date separator (default: '-')",
|
||||||
)
|
|
||||||
fetch_parser.add_argument(
|
|
||||||
"--quantize",
|
|
||||||
dest="quantize",
|
|
||||||
metavar="INT",
|
|
||||||
type=int,
|
|
||||||
help="quantize to given number of decimal places",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
Loading…
Add table
Reference in a new issue