whittlem / pycryptobot

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

FileNotFoundError when using docker-compose #684

Closed devinat1 closed 1 year ago

devinat1 commented 2 years ago

Following the exact steps as listed in the documentation for docker-compose with pycryptobot, I am getting a: FileNotFoundError: [Errno 2] No such file or directory: 'coinbase.key'

This is my docker-compose.yml:

version: "3.9"

services:
  pycrypto:
      build:
        context: .
      container_name: btcusd
      volumes:
        - ./market/BTCUSD/coinbase.key:/app/coinbase.key.json
        - ./market/BTCUSD/config.json:/app/config.json
        - ./market/BTCUSD/pycryptobot.log:/app/pycryptobot.log
        - ./market/BTCUSD/graphs:/app/graphs
        - /etc/localtime:/etc/localtime:ro
      environment:
        - PYTHONUNBUFFERED=1
      deploy:
        restart_policy:
          condition: on-failure

And my tree in the market folder:

market
├── BTCUSD
│   ├── coinbase.key
│   ├── config.json
│   ├── graphs
│   └── pycryptobot.log
└── template
    ├── config.json
    ├── graphs
    │   └── readme.txt
    └── pycryptobot.log

The full error:

Attaching to btcusd
btcusd  | Traceback (most recent call last):
btcusd  |   File "/app/models/config/coinbase_pro_parser.py", line 61, in parser
btcusd  |     with open( api_key_file, 'r') as f :
btcusd  | FileNotFoundError: [Errno 2] No such file or directory: 'coinbase.key'
btcusd  | 
btcusd  | During handling of the above exception, another exception occurred:
btcusd  | 
btcusd  | Traceback (most recent call last):
btcusd  |   File "/app/models/config/coinbase_pro_parser.py", line 69, in parser
btcusd  |     raise RuntimeError(f"Unable to read {api_key_file}")
btcusd  | RuntimeError: Unable to read coinbase.key
btcusd exited with code 1

The command I entered: docker compose up -d Environment: Ubuntu 20.4 WSL with Docker Desktop on Windows 11 Latest pycryptobot version pulled from official branch (6.0.0)

Config.json:

{
    "coinbasepro": {
        "api_url": "https://api.pro.coinbase.com",
        "config": {
            "base_currency": "BTC",
            "quote_currency": "USD",
            "autorestart": 1,
            "live": 1,
            "sellatloss" : 1,
            "selllowerpcnt" : -10,
            "trailingstoploss" : -1.5,
            "sellatresistance" : 0,
            "disablebullonly" : 0,
            "disablebuynearhigh" : 1,
            "disablebuymacd" : 0,
            "disablebuyobv" : 0,
            "disablebuyelderray" : 0,
            "disablefailsafefibonaccilow" : 1,
            "disableprofitbankreversal" : 1,
            "disabletracker" : 1,
            "graphs" : 0,
            "verbose" : 0,
            "stats" : 0,
            "buymaxsize": 50
        },
        "api_key_file": "coinbase.key"
    }
}

Full tree in pycryptobot:

pycryptobot/
├── CHANGELOG.md
├── Dockerfile
├── Dockerfile-websvc
├── LICENSE
├── README.md
├── chart
│   ├── Chart.yaml
│   ├── files
│   ├── templates
│   │   ├── NOTES.txt
│   │   ├── _helpers.tpl
│   │   ├── configmap.yaml
│   │   ├── deployment.yaml
│   │   ├── secret.yaml
│   │   └── serviceaccount.yaml
│   └── values.yaml
├── config.json.sample
├── config.yaml.sample
├── create-graphs.py
├── docker-compose.yaml
├── docs
│   ├── DockerBotSetup.md
│   ├── TelegramBotScanner.md
│   ├── TelegramBotSetup.md
│   ├── UbuntuSystemdService.md
│   └── images
│       ├── applying_patch.png
│       └── folder_structure.png
├── graphs
├── gui.py
├── guihelp.txt
├── logs
├── market
│   ├── BTCUSD
│   │   ├── coinbase.key
│   │   ├── config.json
│   │   ├── graphs
│   │   └── pycryptobot.log
│   └── template
│       ├── config.json
│       ├── graphs
│       │   └── readme.txt
│       └── pycryptobot.log
├── models
│   ├── AppState.py
│   ├── BotConfig.py
│   ├── ConfigBuilder.py
│   ├── Github.py
│   ├── PyCryptoBot.py
│   ├── Stats.py
│   ├── Strategy.py
│   ├── Trading.py
│   ├── TradingAccount.py
│   ├── __init__.py
│   ├── chat
│   │   ├── __init__.py
│   │   └── telegram.py
│   ├── config
│   │   ├── __init__.py
│   │   ├── binance_parser.py
│   │   ├── coinbase_pro_parser.py
│   │   ├── default_parser.py
│   │   ├── dummy_parser.py
│   │   ├── kucoin_parser.py
│   │   └── logger_parser.py
│   ├── exchange
│   │   ├── ExchangesEnum.py
│   │   ├── Granularity.py
│   │   ├── __init__.py
│   │   ├── binance
│   │   │   ├── __init__.py
│   │   │   └── api.py
│   │   ├── coinbase_pro
│   │   │   ├── __init__.py
│   │   │   └── api.py
│   │   └── kucoin
│   │       ├── __init__.py
│   │       └── api.py
│   ├── helper
│   │   ├── LogHelper.py
│   │   ├── MarginHelper.py
│   │   ├── TelegramBotHelper.py
│   │   ├── TextBoxHelper.py
│   │   └── __init__.py
│   └── telegram
│       ├── __init__.py
│       ├── actions.py
│       ├── callbacktags.py
│       ├── config.py
│       ├── control.py
│       ├── handler.py
│       ├── helper.py
│       └── settings.py
├── pycryptobot.py
├── pytest.ini
├── requirements.txt
├── sandbox-tracker.py
├── scanner.json
├── scanner.json.sample
├── scanner.py
├── screener.json.sample
├── screener.py
├── script-binance-webhooks-historical.py
├── script-binance-webhooks-ticker.py
├── script-binance-webhooks.py
├── script-binance_v2.py
├── script-coinbasepro-webhooks-historical.py
├── script-coinbasepro-webhooks-ticker.py
├── script-coinbasepro-webhooks.py
├── script-dummy_exchange.py
├── script-get_fees.py
├── script-get_orders.py
├── script-get_time.py
├── script-kucoin.py
├── script-technical-analysis.py
├── scripts
│   └── docker-pull-and-create-container.sh
├── telegram_bot.py
├── tests
│   ├── integration_tests
│   │   ├── test_model_exchange_binance.py
│   │   └── test_model_exchange_coinbase_pro.py
│   └── unit_tests
│       ├── binance_config.json.skip
│       ├── data
│       │   └── telegram_data
│       │       └── TESTUSDT.json
│       ├── responses
│       │   └── account1.json
│       ├── test_binance.py.skip
│       ├── test_config.py
│       ├── test_exchange_binance.py
│       ├── test_exchange_coinbase.py
│       ├── test_exchange_enum.py
│       ├── test_formatting.py
│       ├── test_granularity_enum.py
│       ├── test_margin_calculation.py
│       ├── test_model_pycryptobot.py.skip
│       ├── test_telegram_bot.py
│       └── trading
│           ├── __init__.py
│           └── test_trading_indicators.py
├── troubleshoot.py
├── views
│   ├── TradingGraphs.py
│   └── __init__.py
├── websvc
│   ├── __init__.py
│   └── app
│       ├── __init__.py
│       ├── css
│       │   └── app.css
│       ├── js
│       │   └── app.js
│       └── pages
│           ├── __init__.py
│           └── pages.py
└── websvc.py

36 directories, 122 files
devinat1 commented 2 years ago

Ok, to fix this issue, I removed the "api_key_file": "coinbasepro.key" from the config.json since docker uses volumes in the case of docker compose. However, now I am met with a new problem which is that if I attempt to create the volume:

    - ./market/BTCUSD/pycryptobot.log:/app/pycryptobot.log

I am hit with a "Error response from daemon: not a directory". I have searched around and don't know how to resolve this. My fix was to simply remove that volume in the docker-compose yaml but am not sure if that creates unintended consequences.

warrmr commented 2 years ago

./market/BTCUSD/pycryptobot.log is a directory on your filesystem.

  1. Stop docker container

  2. delete ./market/BTCUSD/pycryptobot.log

  3. create ./market/BTCUSD/pycryptobot.log as an empty file

  4. restart docker container