Skip to content

Commit

Permalink
Merge pull request #552 from byymster/add-buy-sell-json-logs
Browse files Browse the repository at this point in the history
Add logs for orders in json format
  • Loading branch information
whittlem authored Nov 5, 2021
2 parents 1110432 + cb8282d commit 6da2c93
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions models/BotConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions models/PyCryptoBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions models/config/default_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
6 changes: 6 additions & 0 deletions pycryptobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -1675,6 +1680,7 @@ def executeJob(

def main():
try:
_websocket = None
message = "Starting "
if app.getExchange() == Exchange.COINBASEPRO.value:
message += "Coinbase Pro bot"
Expand Down

0 comments on commit 6da2c93

Please sign in to comment.