Cryptrality / backtester

3 stars 2 forks source link

Downloading data raises a FileNotFoundError #3

Open c0indev3l opened 1 year ago

c0indev3l commented 1 year ago

Hello,

Downloading data raise a FileNotFoundError

>cryptrality download_year -k 1h -y 2022 -e binance_spot BTCUSDT
Traceback (most recent call last):
  File "C:\tools\Anaconda3\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\tools\Anaconda3\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\w4c\AppData\Roaming\Python\Python310\Scripts\cryptrality.exe\__main__.py", line 7, in <module>
  File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\cryptrality\commands.py", line 34, in main
    modules[args.module](subparsers, args.module, extra)
  File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\cryptrality\subcommands\download_year.py", line 88, in download_year
    with xopen(file_out, "wt") as file_1:
  File "C:\Users\w4c\AppData\Roaming\Python\Python310\site-packages\cryptrality\misc.py", line 46, in xopen
    return gzip.open(filename, mode)
  File "C:\tools\Anaconda3\lib\gzip.py", line 58, in open
    binary_file = GzipFile(filename, gz_mode, compresslevel)
  File "C:\tools\Anaconda3\lib\gzip.py", line 174, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'cached_klines\\binance_spot_BTCUSDT_1h_1_1_22_31_12_22.csv.gz'
ffavero commented 1 year ago

can you check if you have the folder cached_klines in the same directory where you are running the command?

c0indev3l commented 1 year ago

Good catch !

Maybe adding something like

import pathlib

...

        cached_klines_path = pathlib.Path(CACHED_KLINES_PATH)
        p.mkdir(parents=True, exist_ok=False)
        file_out = cached_klines_path / file_out_1

at

https://github.com/Cryptrality/backtester/blob/f0c1fe7f524e04f54422c2e666cc3a0d05677b34/cryptrality/subcommands/download_year.py#L87

could help

PS : pathlib is great https://docs.python.org/3/library/pathlib.html