aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/main.py b/main.py
index ab523be..a7ad8f7 100644
--- a/main.py
+++ b/main.py
@@ -64,19 +64,30 @@ def get_user_market(config_path, user_id, debug=False):
64 args.append("--debug") 64 args.append("--debug")
65 args = parse_args(args) 65 args = parse_args(args)
66 parse_config(args) 66 parse_config(args)
67 market_id, market_config, user_id = list(fetch_markets(str(user_id)))[0] 67 market_id, market_config, user_id, options = list(fetch_markets(str(user_id)))[0]
68 return market.Market.from_config(market_config, args, user_id=user_id) 68 return market.Market.from_config(market_config, args, user_id=user_id, options=options)
69 69
70def fetch_markets(user): 70def fetch_markets(user):
71 cursor = dbs.psql.cursor() 71 cursor = dbs.psql.cursor()
72 72
73 if user is None: 73 if user is None:
74 cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled'") 74 cursor.execute("SELECT id,config,user_id,portfolio_profile FROM market_configs_augmented WHERE status='enabled'")
75 else: 75 else:
76 cursor.execute("SELECT id,config,user_id FROM market_configs WHERE status='enabled' AND user_id = %s", [user]) 76 cursor.execute("SELECT id,config,user_id,portfolio_profile FROM market_configs_augmented WHERE status='enabled' AND user_id = %s", [user])
77 77
78 for row in cursor: 78 for row in cursor:
79 yield row 79 options = {
80 "liquidity": parse_liquidity(row[3])
81 }
82 yield row[0:3] + (options,)
83
84def parse_liquidity(value):
85 if value == "high-liquidity":
86 return "high"
87 elif value == "medium-liquidity":
88 return "medium"
89 else:
90 return None
80 91
81def parse_config(args): 92def parse_config(args):
82 if args.db_host is not None: 93 if args.db_host is not None:
@@ -152,11 +163,11 @@ def parse_args(argv):
152 parsed.action = ["sell_all"] 163 parsed.action = ["sell_all"]
153 return parsed 164 return parsed
154 165
155def process(market_config, market_id, user_id, args): 166def process(market_config, market_id, user_id, args, options):
156 try: 167 try:
157 market.Market\ 168 market.Market\
158 .from_config(market_config, args, market_id=market_id, 169 .from_config(market_config, args, market_id=market_id,
159 user_id=user_id)\ 170 user_id=user_id, options=options)\
160 .process(args.action, before=args.before, after=args.after) 171 .process(args.action, before=args.before, after=args.after)
161 except Exception as e: 172 except Exception as e:
162 print("{}: {}".format(e.__class__.__name__, e)) 173 print("{}: {}".format(e.__class__.__name__, e))
@@ -180,8 +191,8 @@ def main(argv):
180 else: 191 else:
181 process_ = process 192 process_ = process
182 193
183 for market_id, market_config, user_id in fetch_markets(args.user): 194 for market_id, market_config, user_id, options in fetch_markets(args.user):
184 process_(market_config, market_id, user_id, args) 195 process_(market_config, market_id, user_id, args, options)
185 196
186 if args.parallel: 197 if args.parallel:
187 for thread in threads: 198 for thread in threads: