aboutsummaryrefslogtreecommitdiff
path: root/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'helper.py')
-rw-r--r--helper.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/helper.py b/helper.py
index 4b9ce0d..6d28c3f 100644
--- a/helper.py
+++ b/helper.py
@@ -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
54def main_fetch_markets(pg_config): 59def 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
63def main_process_market(user_market, before=False, after=False): 71def 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
70def main_store_report(report_path, user_id, user_market): 85def main_store_report(report_path, user_id, user_market):
71 try: 86 try: