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][1]
+ 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)
return args
-def process(market_id, market_config, user_id, report_path, args, pg_config):
+def process(market_config, market_id, user_id, args, report_path, pg_config):
try:
market.Market\
.from_config(market_config, args,
import threading
market.Portfolio.start_worker()
- for row in fetch_markets(pg_config, args.user):
- threading.Thread(target=process, args=[
- *row, report_path, args, pg_config
- ]).start()
+ def process_(*args):
+ threading.Thread(target=process, args=args).start()
else:
- for row in fetch_markets(pg_config, args.user):
- process(*row, report_path, args, pg_config)
+ 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:])
trades = None
balances = None
- def __init__(self, ccxt_instance, args,
- user_id=None, market_id=None,
- report_path=None, pg_config=None):
+ def __init__(self, ccxt_instance, args, **kwargs):
self.args = args
self.debug = args.debug
self.ccxt = ccxt_instance
self.balances = BalanceStore(self)
self.processor = Processor(self)
- self.user_id = user_id
- self.market_id = market_id
- self.report_path = report_path
- self.pg_config = pg_config
+ for key in ["user_id", "market_id", "report_path", "pg_config"]:
+ setattr(self, key, kwargs.get(key, None))
@classmethod
- def from_config(cls, config, args,
- user_id=None, market_id=None, report_path=None, pg_config=None):
+ def from_config(cls, config, args, **kwargs):
config["apiKey"] = config.pop("key", None)
ccxt_instance = ccxt.poloniexE(config)
ccxt_instance.session.request = request_wrap.__get__(ccxt_instance.session,
ccxt_instance.session.__class__)
- return cls(ccxt_instance, args,
- user_id=user_id, market_id=market_id,
- pg_config=pg_config, report_path=report_path)
+ return cls(ccxt_instance, args, **kwargs)
def store_report(self):
self.report.merge(Portfolio.report)
args_mock.after = "after"
self.assertEqual("", stdout_mock.getvalue())
- main.process(3, "config", 1, "report_path", args_mock, "pg_config")
+ main.process("config", 3, 1, args_mock, "report_path", "pg_config")
market_mock.from_config.assert_has_calls([
mock.call("config", args_mock, pg_config="pg_config", market_id=3, user_id=1, report_path="report_path"),
self.assertEqual(2, process.call_count)
process.assert_has_calls([
- mock.call(3, "config1", 1, "report_path", args_mock, "pg_config"),
- mock.call(1, "config2", 2, "report_path", args_mock, "pg_config"),
+ mock.call("config1", 3, 1, args_mock, "report_path", "pg_config"),
+ mock.call("config2", 1, 2, args_mock, "report_path", "pg_config"),
])
with self.subTest(parallel=True):
with mock.patch("main.parse_args") as parse_args,\
self.assertEqual(2, process.call_count)
process.assert_has_calls([
mock.call.__bool__(),
- mock.call(3, "config1", 1, "report_path", args_mock, "pg_config"),
+ mock.call("config1", 3, 1, args_mock, "report_path", "pg_config"),
mock.call.__bool__(),
- mock.call(1, "config2", 2, "report_path", args_mock, "pg_config"),
+ mock.call("config2", 1, 2, args_mock, "report_path", "pg_config"),
])
@mock.patch.object(main.sys, "exit")