diff --git a/models/BotConfig.py b/models/BotConfig.py index f2801465..95dd9e5d 100644 --- a/models/BotConfig.py +++ b/models/BotConfig.py @@ -51,6 +51,7 @@ def __init__(self, *args, **kwargs): self.smart_switch = 1 self.telegram = False self.telegramdatafolder = "" + self.logbuysellinjson = False self.buypercent = 100 self.sellpercent = 100 self.last_action = None @@ -516,6 +517,7 @@ def _parse_arguments(self): help="Enable Machine Learning E.g. seasonal ARIMA model for predictions", ) parser.add_argument("--websocket", action="store_true", help="Enable websocket") + parser.add_argument("--logbuysellinjson", action="store_true", help="Enable logging orders in json format") # pylint: disable=unused-variable args, unknown = parser.parse_known_args() diff --git a/models/PyCryptoBot.py b/models/PyCryptoBot.py index cfda048f..ae2a7a71 100644 --- a/models/PyCryptoBot.py +++ b/models/PyCryptoBot.py @@ -805,6 +805,9 @@ def enableML(self) -> bool: def enableWebsocket(self) -> bool: return self.websocket + def enabledLogBuySellInJson(self) -> bool: + return self.logbuysellinjson + def setGranularity(self, granularity: int): if granularity in [60, 300, 900, 3600, 21600, 86400]: self.granularity = granularity @@ -1354,6 +1357,10 @@ def _generate_banner(self) -> None: str(self.enableinsufficientfundslogging) + " --enableinsufficientfundslogging", ) + text_box.line( + "Log Buy and Sell orders in JSON", + str(self.logbuysellinjson) + " --logbuysellinjson" + ) if self.getBuyMaxSize(): text_box.line( diff --git a/models/config/default_parser.py b/models/config/default_parser.py index 45301230..5a3b8e5a 100644 --- a/models/config/default_parser.py +++ b/models/config/default_parser.py @@ -461,3 +461,10 @@ def defaultConfigParse(app, config): app.buymaxsize = config["buymaxsize"] else: raise TypeError("buymaxsize must be of type int or float") + + if "logbuysellinjson" in config: + if isinstance(config["logbuysellinjson"], int): + if bool(config["logbuysellinjson"]): + app.logbuysellinjson = True + else: + raise TypeError("logbuysellinjson must be of type int") \ No newline at end of file diff --git a/pycryptobot.py b/pycryptobot.py index f9bf1ad7..0262deca 100755 --- a/pycryptobot.py +++ b/pycryptobot.py @@ -1393,6 +1393,11 @@ def executeJob( _state.last_df_index = str(df_last.index.format()[0]) + if _app.enabledLogBuySellInJson() == True \ + and _state.action in ["BUY", "SELL"] \ + and len(_app.trade_tracker) > 0: + Logger.info( _app.trade_tracker.loc[len(_app.trade_tracker)-1].to_json()) + if not _app.isLive() and _state.iterations == len(df): simulation = { "config": {}, @@ -1675,6 +1680,7 @@ def executeJob( def main(): try: + _websocket = None message = "Starting " if app.getExchange() == Exchange.COINBASEPRO.value: message += "Coinbase Pro bot"