diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-04-20 20:20:02 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-04-21 00:42:16 +0200 |
commit | 1593c7a9f58ffaea8933f30f683f67c2b155f6b2 (patch) | |
tree | 1191b8438f1f7d52aa7ef736ec2def0595e311d0 /main.py | |
parent | ceb7fc4c9e76857fefbe1dfe3f4dd3830d065a6f (diff) | |
download | Trader-1593c7a9f58ffaea8933f30f683f67c2b155f6b2.tar.gz Trader-1593c7a9f58ffaea8933f30f683f67c2b155f6b2.tar.zst Trader-1593c7a9f58ffaea8933f30f683f67c2b155f6b2.zip |
Store some information to redis
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 33 |
1 files changed, 28 insertions, 5 deletions
@@ -95,13 +95,25 @@ def parse_config(args): | |||
95 | del(args.db_password) | 95 | del(args.db_password) |
96 | del(args.db_database) | 96 | del(args.db_database) |
97 | 97 | ||
98 | redis_config = { | ||
99 | "host": args.redis_host, | ||
100 | "port": args.redis_port, | ||
101 | "db": args.redis_database, | ||
102 | } | ||
103 | if redis_config["host"].startswith("/"): | ||
104 | redis_config["unix_socket_path"] = redis_config.pop("host") | ||
105 | del(redis_config["port"]) | ||
106 | del(args.redis_host) | ||
107 | del(args.redis_port) | ||
108 | del(args.redis_database) | ||
109 | |||
98 | report_path = args.report_path | 110 | report_path = args.report_path |
99 | 111 | ||
100 | if report_path is not None and not \ | 112 | if report_path is not None and not \ |
101 | os.path.exists(report_path): | 113 | os.path.exists(report_path): |
102 | os.makedirs(report_path) | 114 | os.makedirs(report_path) |
103 | 115 | ||
104 | return pg_config | 116 | return pg_config, redis_config |
105 | 117 | ||
106 | def parse_args(argv): | 118 | def parse_args(argv): |
107 | parser = configargparse.ArgumentParser( | 119 | parser = configargparse.ArgumentParser( |
@@ -134,6 +146,10 @@ def parse_args(argv): | |||
134 | help="Store report to database (default)") | 146 | help="Store report to database (default)") |
135 | parser.add_argument("--no-report-db", action='store_false', dest="report_db", | 147 | parser.add_argument("--no-report-db", action='store_false', dest="report_db", |
136 | help="Don't store report to database") | 148 | help="Don't store report to database") |
149 | parser.add_argument("--report-redis", action='store_true', default=False, dest="report_redis", | ||
150 | help="Store report to redis") | ||
151 | parser.add_argument("--no-report-redis", action='store_false', dest="report_redis", | ||
152 | help="Don't store report to redis (default)") | ||
137 | parser.add_argument("--report-path", required=False, | 153 | parser.add_argument("--report-path", required=False, |
138 | help="Where to store the reports (default: absent, don't store)") | 154 | help="Where to store the reports (default: absent, don't store)") |
139 | parser.add_argument("--no-report-path", action='store_const', dest='report_path', const=None, | 155 | parser.add_argument("--no-report-path", action='store_const', dest='report_path', const=None, |
@@ -148,17 +164,24 @@ def parse_args(argv): | |||
148 | help="Password access to database (default: cryptoportfolio)") | 164 | help="Password access to database (default: cryptoportfolio)") |
149 | parser.add_argument("--db-database", default="cryptoportfolio", | 165 | parser.add_argument("--db-database", default="cryptoportfolio", |
150 | help="Database access to database (default: cryptoportfolio)") | 166 | help="Database access to database (default: cryptoportfolio)") |
167 | parser.add_argument("--redis-host", default="localhost", | ||
168 | help="Host access to database (default: localhost). Use path for socket") | ||
169 | parser.add_argument("--redis-port", default=6379, | ||
170 | help="Port access to redis (default: 6379)") | ||
171 | parser.add_argument("--redis-database", default=0, | ||
172 | help="Redis database to use (default: 0)") | ||
151 | 173 | ||
152 | parsed = parser.parse_args(argv) | 174 | parsed = parser.parse_args(argv) |
153 | if parsed.action is None: | 175 | if parsed.action is None: |
154 | parsed.action = ["sell_all"] | 176 | parsed.action = ["sell_all"] |
155 | return parsed | 177 | return parsed |
156 | 178 | ||
157 | def process(market_config, market_id, user_id, args, pg_config): | 179 | def process(market_config, market_id, user_id, args, pg_config, redis_config): |
158 | try: | 180 | try: |
159 | market.Market\ | 181 | market.Market\ |
160 | .from_config(market_config, args, market_id=market_id, | 182 | .from_config(market_config, args, market_id=market_id, |
161 | pg_config=pg_config, user_id=user_id)\ | 183 | pg_config=pg_config, redis_config=redis_config, |
184 | user_id=user_id)\ | ||
162 | .process(args.action, before=args.before, after=args.after) | 185 | .process(args.action, before=args.before, after=args.after) |
163 | except Exception as e: | 186 | except Exception as e: |
164 | print("{}: {}".format(e.__class__.__name__, e)) | 187 | print("{}: {}".format(e.__class__.__name__, e)) |
@@ -166,7 +189,7 @@ def process(market_config, market_id, user_id, args, pg_config): | |||
166 | def main(argv): | 189 | def main(argv): |
167 | args = parse_args(argv) | 190 | args = parse_args(argv) |
168 | 191 | ||
169 | pg_config = parse_config(args) | 192 | pg_config, redis_config = parse_config(args) |
170 | 193 | ||
171 | market.Portfolio.report.set_verbose(not args.quiet) | 194 | market.Portfolio.report.set_verbose(not args.quiet) |
172 | 195 | ||
@@ -183,7 +206,7 @@ def main(argv): | |||
183 | process_ = process | 206 | process_ = process |
184 | 207 | ||
185 | for market_id, market_config, user_id in fetch_markets(pg_config, args.user): | 208 | for market_id, market_config, user_id in fetch_markets(pg_config, args.user): |
186 | process_(market_config, market_id, user_id, args, pg_config) | 209 | process_(market_config, market_id, user_id, args, pg_config, redis_config) |
187 | 210 | ||
188 | if args.parallel: | 211 | if args.parallel: |
189 | for thread in threads: | 212 | for thread in threads: |