whittlem / pycryptobot

Python Crypto Bot (PyCryptoBot)
Apache License 2.0
1.96k stars 739 forks source link

Run tests using config files #798

Closed krzysztofMajchrzak-GIT closed 1 year ago

krzysztofMajchrzak-GIT commented 1 year ago

I was trying to run a few tests using configuration files but can't get it to work. So it seems like it is impossible to run bot with config file without providing API key. How to run tests using json files?

My command (I am locally build docker image): sudo docker run -it -v ./001.json:/app/config.json --rm --user pycryptobot pycryptobot/pycryptobot

My Json config file:

"binance": {
    "config": {
        "exchange": binance,
        "market": ETHUSDT,
        "autorestart": 1,
        "base_currency": "ETH",
        "disablebuynearhigh": 1,
        "granularity": "15m",
        "nobuynearhighpcnt": 1,
        "nosellmaxpcnt": 3,
        "nosellminpcnt": -9,
        "quote_currency": "USDT",
        "sellatresistance": 1,
        "selllowerpcnt": -12,
        "trailingbuypcnt": 1,
        "trailingstoploss": -1,
        "trailingstoplosstrigger": 3,
        "sim": fast,
        "simstartingdate": "2023-01-01"
    }
}

And the error i get:

Traceback (most recent call last):
  File "/app/models/config/binance_parser.py", line 105, in parser
    with open(app.api_key_file, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'binance.key'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/pycryptobot.py", line 21, in <module>
    main()
  File "/app/pycryptobot.py", line 12, in main
    app = PyCryptoBot()
  File "/app/controllers/PyCryptoBot.py", line 78, in __init__
    super(PyCryptoBot, self).__init__(filename=self.config_file, exchange=exchange)
  File "/app/models/BotConfig.py", line 180, in __init__
    self.read_config()
  File "/app/models/BotConfig.py", line 230, in read_config
    binanceConfigParser(self, self.config[self.exchange.value], self.cli_args)
  File "/app/models/config/binance_parser.py", line 111, in parser
    raise RuntimeError(f"Unable to read {app.api_key_file}")
RuntimeError: Unable to read binance.key

Thank you in advance.

whittlem commented 1 year ago

I am on holiday now. I will respond when I am back. Take a look at the unit tests. You can see how it was done there.

krzysztofMajchrzak-GIT commented 1 year ago

Ok i get it. To everyone interested. The trick was to provide API key filled with zeros.

Config:


{
    "binance": {
        "config": {
            "exchange": "binance",
            "api_url": "https://api.binance.com",
            "buypercent": 15
        },
        "api_key_file": "binance.key"
    }
}

api key file:

"api_key": "0000000000000000000000000000000000000000000000000000000000000000",
"api_secret": "0000000000000000000000000000000000000000000000000000000000000000"

And the command is:

sudo docker run -it -v ./002.json:/app/config.json -v ./binance.key:/app/binance.key --rm --user pycryptobot pycryptobot/pycryptobot

Thank you for your hint. When you are back from your vacation would you answer me another question?

One more thing i cant use properly is logging and graphs. using this command: sudo docker run -it --rm -v ./graphs:/app/graphs -v ./testlog.log:/app/pycryptobot.log -v ./testtrade.csv:/app/trades.csv --user pycryptobot pycryptobot/pycryptobot bash --exchange binance --market ETHUSDT --granularity 15m --sim fast --autorestart 1 --base_currency "ETH" --quote_currency "USDT" --disablebuynearhigh 1 --nobuynearhighpcnt 1 --sellatresistance 1 --selllowerpcnt -5 --trailingbuypcnt 1 --trailingstoploss -1 --trailingstoplosstrigger 3 --simstartdate "2022-01-01" --simenddate "2022-02-01" --predictions 1 --preventloss 1 --logs 0 --tradetracker 1 --logbuysellinjson 1

i get logfile that is a copy of terminal output, no graphs and no json files. I want to have pure json file with only transactions not all logs.

I asked this question on Q&A forum: Link

Thank you in advance