From 6c1538a652ab5faec8133dd42e1c6dec35d989a9 Mon Sep 17 00:00:00 2001 From: psemdel Date: Sat, 23 Mar 2024 20:31:38 +0100 Subject: [PATCH] Migration error #36, ml_model_name, USED_API_FOR_ORDER_PERF --- py-trading-bot/core/caller.py | 69 +++++++++++++++---------- py-trading-bot/kubernetes/configmap.yml | 4 +- py-trading-bot/kubernetes/django.yml | 16 +++++- py-trading-bot/orders/apps.py | 7 ++- py-trading-bot/trading_bot/settings.py | 4 +- 5 files changed, 66 insertions(+), 34 deletions(-) diff --git a/py-trading-bot/core/caller.py b/py-trading-bot/core/caller.py index f645118..1325720 100644 --- a/py-trading-bot/core/caller.py +++ b/py-trading-bot/core/caller.py @@ -5,12 +5,18 @@ @author: maxime """ -from ml import ml +try: + from ml import ml + ml_loaded=True +except ImportError: + ml_loaded=False + from core import strat, strat_legacy, presel import sys def name_to_ust_or_presel( ust_or_presel_name: str, + ml_model_name: str, period: str, it_is_index:bool=False, st=None, @@ -21,43 +27,52 @@ def name_to_ust_or_presel( Arguments ---------- ust_or_presel_name: Name of the underlying strategy or preselection strategy to be called + ml_model_name: Name of the machine learning model to use period: period of time in year for which we shall retrieve the data it_is_index: is it indexes that are provided st: strategy associated ''' try: - if ust_or_presel_name[:6]=="Presel": - if not it_is_index: #Presel for index makes no sense - if ust_or_presel_name[6:8].lower()=="wq": - nb=int(ust_or_presel_name[8:]) - pr=presel.PreselWQ(period,nb=nb,st=st,**kwargs) - elif ust_or_presel_name[6:8].lower()=="ml": - PR=getattr(ml,ust_or_presel_name) - pr=PR(period,st=st,**kwargs) - else: - PR=getattr(presel,ust_or_presel_name) - pr=PR(period,st=st,**kwargs) - + if ml_model_name is not None: + if ml_loaded: + pr=ml.PreselMLCustom(period,ml_model_name,**kwargs) pr.run() return pr else: - return None - elif ust_or_presel_name[:5]=="Strat": - try: - UST=getattr(strat,ust_or_presel_name) - except: + raise ImportError("Ml cannot be loaded, check you installed Keras") + else: + if ust_or_presel_name[:6]=="Presel": + if not it_is_index: #Presel for index makes no sense + if ust_or_presel_name[6:8].lower()=="wq": + nb=int(ust_or_presel_name[8:]) + pr=presel.PreselWQ(period,nb=nb,st=st,**kwargs) + elif ust_or_presel_name[6:8].lower()=="ml": + PR=getattr(ml,ust_or_presel_name) + pr=PR(period,st=st,**kwargs) + else: + PR=getattr(presel,ust_or_presel_name) + pr=PR(period,st=st,**kwargs) + + pr.run() + return pr + else: + return None + elif ust_or_presel_name[:5]=="Strat": try: - UST=getattr(strat_legacy,ust_or_presel_name) + UST=getattr(strat,ust_or_presel_name) except: - raise ValueError(ust_or_presel_name + " underlying strategy not found") - ust=UST(period,st=st,it_is_index=it_is_index,**kwargs) - ust.run() - return ust - else: - print("Class " +ust_or_presel_name + " does not respect the convention of starting with Presel or Strat") - return None + try: + UST=getattr(strat_legacy,ust_or_presel_name) + except: + raise ValueError(ust_or_presel_name + " underlying strategy not found") + ust=UST(period,st=st,it_is_index=it_is_index,**kwargs) + ust.run() + return ust + else: + print("Class " +ust_or_presel_name + " does not respect the convention of starting with Presel or Strat") + return None except Exception as e: _, e_, exc_tb = sys.exc_info() print(e) - print("line " + str(exc_tb.tb_lineno)) \ No newline at end of file + print("line " + str(exc_tb.tb_lineno)) diff --git a/py-trading-bot/kubernetes/configmap.yml b/py-trading-bot/kubernetes/configmap.yml index 36cd900..d8d0ac2 100644 --- a/py-trading-bot/kubernetes/configmap.yml +++ b/py-trading-bot/kubernetes/configmap.yml @@ -5,6 +5,8 @@ metadata: data: postgres_db: "testdb" ib_port: "4001" - use_ib_for_data : "false" + used_api_for_order_perf : "IB" + used_api_for_data_alerting : "IB" + used_api_for_data_reporting : "YF" diff --git a/py-trading-bot/kubernetes/django.yml b/py-trading-bot/kubernetes/django.yml index 1bf21a5..0dce512 100755 --- a/py-trading-bot/kubernetes/django.yml +++ b/py-trading-bot/kubernetes/django.yml @@ -23,6 +23,8 @@ spec: ports: - containerPort: 8000 env: + - name: DEBUG + value: "False" - name: POSTGRES_USER valueFrom: secretKeyRef: @@ -65,11 +67,21 @@ spec: name: py-trading-bot-configmap key: ib_port - - name: USE_IB_FOR_DATA + - name: USED_API_FOR_ORDER_PERF valueFrom: configMapKeyRef: name: py-trading-bot-configmap - key: use_ib_for_data + key: used_api_for_order_perf + - name: USED_API_FOR_DATA_ALERTING + valueFrom: + configMapKeyRef: + name: py-trading-bot-configmap + key: used_api_for_data_alerting + - name: USED_API_FOR_DATA_REPORTING + valueFrom: + configMapKeyRef: + name: py-trading-bot-configmap + key: used_api_for_data_reporting --- kind: Service diff --git a/py-trading-bot/orders/apps.py b/py-trading-bot/orders/apps.py index 18e3585..cd9ae2e 100644 --- a/py-trading-bot/orders/apps.py +++ b/py-trading-bot/orders/apps.py @@ -10,6 +10,9 @@ def ready(self): from orders.models import StockStatus from reporting.views import create_ss_sub - if len(StockStatus.objects.all())==0: - create_ss_sub() + try: + if len(StockStatus.objects.all())==0: + create_ss_sub() + except: + pass \ No newline at end of file diff --git a/py-trading-bot/trading_bot/settings.py b/py-trading-bot/trading_bot/settings.py index b1cd83a..8630fa9 100644 --- a/py-trading-bot/trading_bot/settings.py +++ b/py-trading-bot/trading_bot/settings.py @@ -104,7 +104,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.environ.get('DEBUG',True) -if DEBUG and DEBUG!="False": +if DEBUG and not (isinstance(DEBUG,str) and DEBUG.lower()=="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: @@ -172,7 +172,7 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': os.getenv('POSTGRES_DB','pgtradingbotdb2023'), + 'NAME': os.getenv('POSTGRES_DB','migdb'), 'USER': DB_USER, 'PASSWORD': DB_SECRET_KEY, 'HOST': os.getenv('POSTGRES_HOST', 'localhost'),