trades = None
balances = None
- def __init__(self, ccxt_instance, debug=False, user_id=None, report_path=None):
- self.debug = debug
+ def __init__(self, ccxt_instance, args, user_id=None, report_path=None):
+ self.args = args
+ self.debug = args.debug
self.ccxt = ccxt_instance
self.ccxt._market = self
- self.report = ReportStore(self)
+ self.report = ReportStore(self, verbose_print=(not args.quiet))
self.trades = TradeStore(self)
self.balances = BalanceStore(self)
self.processor = Processor(self)
self.report_path = report_path
@classmethod
- def from_config(cls, config, debug=False, user_id=None, report_path=None):
+ def from_config(cls, config, args, user_id=None, report_path=None):
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, debug=debug, user_id=user_id, report_path=report_path)
+ return cls(ccxt_instance, args, user_id=user_id, report_path=report_path)
def store_report(self):
+ self.report.merge(Portfolio.report)
try:
if self.report_path is not None:
- report_file = "{}/{}_{}.json".format(self.report_path, datetime.now().isoformat(), self.user_id)
- with open(report_file, "w") as f:
+ report_file = "{}/{}_{}".format(self.report_path, datetime.now().isoformat(), self.user_id)
+ with open(report_file + ".json", "w") as f:
f.write(self.report.to_json())
+ with open(report_file + ".log", "w") as f:
+ f.write("\n".join(map(lambda x: x[1], self.report.print_logs)))
except Exception as e:
print("impossible to store report file: {}; {}".format(e.__class__.__name__, e))
class Processor:
scenarios = {
+ "wait_for_cryptoportfolio": [
+ {
+ "name": "wait",
+ "number": 1,
+ "before": False,
+ "after": True,
+ "wait_for_recent": {},
+ },
+ ],
+ "print_orders": [
+ {
+ "name": "wait",
+ "number": 1,
+ "before": False,
+ "after": True,
+ "wait_for_recent": {},
+ },
+ {
+ "name": "make_orders",
+ "number": 2,
+ "before": False,
+ "after": True,
+ "fetch_balances": ["begin"],
+ "prepare_trades": { "compute_value": "average" },
+ "prepare_orders": { "compute_value": "average" },
+ },
+ ],
"sell_needed": [
{
"name": "wait",
import inspect
if action == "wait_for_recent":
- method = portfolio.Portfolio.wait_for_recent
+ method = Portfolio.wait_for_recent
elif action == "prepare_trades":
method = self.market.prepare_trades
elif action == "prepare_orders":
def run_action(self, action, default_args, kwargs):
method, args = self.parse_args(action, default_args, kwargs)
- if action == "wait_for_recent":
- method(self.market, **args)
- else:
- method(**args)
-
+ method(**args)