psemdel / py-trading-bot

Trading-bot in python using django, vertorbt lib and interactive-brokers
MIT License
141 stars 34 forks source link

No module named 'core' #16

Closed ben1628 closed 1 year ago

ben1628 commented 1 year ago

Trying to run the bt.ipynb and get the above error

any ideas?

ben1628 commented 1 year ago

it looks like it fails on orders/models.py at line 10

from backports.zoneinfo import ZoneInfo

I'm using python 3.10.6, the following seems to be the proper syntax

from zoneinfo import ZoneInfo

There are other modules that have similar problems

However, the error still occurred if I tried to run the same script again, don't know what's wrong with it.

psemdel commented 1 year ago

Hi, first all jupyter scripts need to be moved one folder higher to work (still haven't found a solution to that, the classic one is to integrate my tool in pip and let you install it from there). This is what I meant with MOVE_THEM_TO_ROOT_TO_USE_THEM. I did not put all scripts there from the beginning, otherwise it looks very messy.

For the zoneinfo, you are right with Python 3.8 and below you need the backports, with newer Python zoneinfo works directly. I will put a "if" there.

ben1628 commented 1 year ago

Okay, I resolved the problem by doing the following

import sys
sys.path.append(".")

from core import strat, indicators, bt

and then modify the settings.py at line 145

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

...

if DEBUG and DEBUG!="False":
    with open(os.path.join(BASE_DIR, 'trading_bot/etc/DJANGO_SECRET')) as f:
        SECRET_KEY = f.read().strip()
    with open(os.path.join(BASE_DIR, 'trading_bot/etc/DB_SECRET')) as f:
        DB_SECRET_KEY = f.read().strip()
    with open(os.path.join(BASE_DIR, 'trading_bot/etc/DB_USER')) as f:
        DB_USER = f.read().strip()

BASE_DIR is the new settings.py as of Django 4.1.6 when I created the website from scratch.

psemdel commented 1 year ago

The os.path.join(BASE_DIR, is a good idea indeed, I neglected this point. However with the sys append(".") I am not able to start the jupyter scripts from a subordner, so I don't really see the change in comparison to before. Maybe I misunderstand your actions.

ben1628 commented 1 year ago

may be try it with two dots like this

import sys
sys.path.append("..")

from core import strat, indicators, bt

It did worked for me.

psemdel commented 1 year ago

It made my day, many thx!

ben1628 commented 1 year ago

Many thanks to you, you're a great help for me! :)