Skip to content

Commit b46935b

Browse files
committed
update cli
1 parent 4a4e5cc commit b46935b

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/emtl/cli.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
"""
2-
Module that contains the command line app.
3-
4-
Why does this file exist, and why not put this in __main__?
5-
6-
You might be tempted to import things from __main__ later, but that will cause
7-
problems: the code will get executed twice:
1+
import argparse
82

9-
- When you run `python -memtl` python will execute
10-
``__main__.py`` as a script. That means there will not be any
11-
``emtl.__main__`` in ``sys.modules``.
12-
- When you import __main__ it will get executed again (as a module) because
13-
there"s no ``emtl.__main__`` in ``sys.modules``.
3+
from .core import login
4+
from .utils import get_logger
145

15-
Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
16-
"""
6+
logger = get_logger(__name__)
177

18-
import argparse
19-
20-
from .core import emt
218

9+
logger.info("cli")
2210
parser = argparse.ArgumentParser(prog="emt", description="东方财富交易接口", epilog="东方财富交易接口")
23-
parser.add_argument("-u", "--user", required=True)
24-
parser.add_argument("-p", "--password", required=True)
11+
parser.add_argument("-u", "--user", required=False)
12+
parser.add_argument("-p", "--password", required=False)
13+
group = parser.add_mutually_exclusive_group()
14+
group.add_argument("-b", "--buy", help="买入股票,格式为:代码-价格-数量。例子买入一手平安银行:000001-10.21-100")
15+
group.add_argument("-s", "--sell", help="卖出股票,格式为:代码-价格-数量。卖一手平安银行:000001-10.21-100")
16+
group.add_argument("-q", "--query", type=str, choices=["asset", "order", "trade"], help="查询账户的资产、挂单、成交")
2517

2618

2719
def run(args=None):
20+
logger.info(args)
2821
args = parser.parse_args(args=args)
29-
print(emt(args.user, args.password))
22+
logger.info(args)
23+
login(args.user, args.password)
3024
parser.exit(0)
25+
26+
27+
if __name__ == "__main__":
28+
run()

0 commit comments

Comments
 (0)