diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-26 11:13:38 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-26 11:13:38 +0100 |
commit | 516a2517aa428596199e56cc105c7b0132064ade (patch) | |
tree | e1be799f8635cb45242ae1a8993139f6cdf8ccb5 /helper.py | |
parent | be54a20157119438c6450b345e4a70d71964ec2e (diff) | |
download | Trader-516a2517aa428596199e56cc105c7b0132064ade.tar.gz Trader-516a2517aa428596199e56cc105c7b0132064ade.tar.zst Trader-516a2517aa428596199e56cc105c7b0132064ade.zip |
Add user and action for main actions
Diffstat (limited to 'helper.py')
-rw-r--r-- | helper.py | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -24,6 +24,11 @@ def main_parse_args(argv): | |||
24 | parser.add_argument("--debug", | 24 | parser.add_argument("--debug", |
25 | default=False, action='store_const', const=True, | 25 | default=False, action='store_const', const=True, |
26 | help="Run in debug mode") | 26 | help="Run in debug mode") |
27 | parser.add_argument("--user", | ||
28 | default=None, required=False, help="Only run for that user") | ||
29 | parser.add_argument("--action", | ||
30 | default=None, required=False, | ||
31 | help="Do a different action than trading") | ||
27 | 32 | ||
28 | args = parser.parse_args(argv) | 33 | args = parser.parse_args(argv) |
29 | 34 | ||
@@ -51,21 +56,31 @@ def main_parse_config(config_file): | |||
51 | 56 | ||
52 | return [config["postgresql"], report_path] | 57 | return [config["postgresql"], report_path] |
53 | 58 | ||
54 | def main_fetch_markets(pg_config): | 59 | def main_fetch_markets(pg_config, user): |
55 | connection = psycopg2.connect(**pg_config) | 60 | connection = psycopg2.connect(**pg_config) |
56 | cursor = connection.cursor() | 61 | cursor = connection.cursor() |
57 | 62 | ||
58 | cursor.execute("SELECT config,user_id FROM market_configs") | 63 | if user is None: |
64 | cursor.execute("SELECT config,user_id FROM market_configs") | ||
65 | else: | ||
66 | cursor.execute("SELECT config,user_id FROM market_configs WHERE user_id = %s", user) | ||
59 | 67 | ||
60 | for row in cursor: | 68 | for row in cursor: |
61 | yield row | 69 | yield row |
62 | 70 | ||
63 | def main_process_market(user_market, before=False, after=False): | 71 | def main_process_market(user_market, action, before=False, after=False): |
64 | if before: | 72 | if action is None: |
65 | process_sell_all__1_all_sell(user_market) | 73 | if before: |
66 | if after: | 74 | process_sell_all__1_all_sell(user_market) |
67 | portfolio.Portfolio.wait_for_recent(user_market) | 75 | if after: |
68 | process_sell_all__2_all_buy(user_market) | 76 | portfolio.Portfolio.wait_for_recent(user_market) |
77 | process_sell_all__2_all_buy(user_market) | ||
78 | elif action == "print_balances": | ||
79 | print_balances(user_market) | ||
80 | elif action == "print_orders": | ||
81 | print_orders(user_market) | ||
82 | else: | ||
83 | raise NotImplementedError("Unknown action {}".format(action)) | ||
69 | 84 | ||
70 | def main_store_report(report_path, user_id, user_market): | 85 | def main_store_report(report_path, user_id, user_market): |
71 | try: | 86 | try: |