X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=main.py;h=446219247cc2f8c9211032d1c03a9f1d96986a40;hb=90d7423eec074a0ed0af680c223180f8d7e1d4e6;hp=55981bf94d82c966aea93e3f89ea25a01cdb7c79;hpb=07fa7a4bf8f7a6f799120fb9a5965a09bea6c38e;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git diff --git a/main.py b/main.py index 55981bf..4462192 100644 --- a/main.py +++ b/main.py @@ -62,18 +62,20 @@ def make_order(market, value, currency, action="acquire", def get_user_market(config_path, user_id, debug=False): pg_config, report_path = parse_config(config_path) - market_config = list(fetch_markets(pg_config, str(user_id)))[0][0] + market_id, market_config, user_id = list(fetch_markets(pg_config, str(user_id)))[0] args = type('Args', (object,), { "debug": debug, "quiet": False })() - return market.Market.from_config(market_config, args, user_id=user_id, report_path=report_path) + return market.Market.from_config(market_config, args, + pg_config=pg_config, market_id=market_id, + user_id=user_id, report_path=report_path) def fetch_markets(pg_config, user): connection = psycopg2.connect(**pg_config) cursor = connection.cursor() if user is None: - cursor.execute("SELECT config,user_id FROM market_configs") + cursor.execute("SELECT id,config,user_id FROM market_configs") else: - cursor.execute("SELECT config,user_id FROM market_configs WHERE user_id = %s", user) + cursor.execute("SELECT id,config,user_id FROM market_configs WHERE user_id = %s", user) for row in cursor: yield row @@ -132,10 +134,12 @@ def parse_args(argv): return args -def process(market_config, user_id, report_path, args): +def process(market_config, market_id, user_id, args, report_path, pg_config): try: market.Market\ - .from_config(market_config, args, user_id=user_id, report_path=report_path)\ + .from_config(market_config, args, + pg_config=pg_config, market_id=market_id, + user_id=user_id, report_path=report_path)\ .process(args.action, before=args.before, after=args.after) except Exception as e: print("{}: {}".format(e.__class__.__name__, e)) @@ -149,11 +153,13 @@ def main(argv): import threading market.Portfolio.start_worker() - for market_config, user_id in fetch_markets(pg_config, args.user): - threading.Thread(target=process, args=[market_config, user_id, report_path, args]).start() + def process_(*args): + threading.Thread(target=process, args=args).start() else: - for market_config, user_id in fetch_markets(pg_config, args.user): - process(market_config, user_id, report_path, args) + process_ = process + + for market_id, market_config, user_id in fetch_markets(pg_config, args.user): + process_(market_config, market_id, user_id, args, report_path, pg_config) if __name__ == '__main__': # pragma: no cover main(sys.argv[1:])