Skip to content

Commit

Permalink
Migration error #36, ml_model_name, USED_API_FOR_ORDER_PERF
Browse files Browse the repository at this point in the history
  • Loading branch information
psemdel committed Mar 23, 2024
1 parent b172289 commit 6c1538a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 34 deletions.
69 changes: 42 additions & 27 deletions py-trading-bot/core/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
print("line " + str(exc_tb.tb_lineno))
4 changes: 3 additions & 1 deletion py-trading-bot/kubernetes/configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"


16 changes: 14 additions & 2 deletions py-trading-bot/kubernetes/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ spec:
ports:
- containerPort: 8000
env:
- name: DEBUG
value: "False"
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions py-trading-bot/orders/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions py-trading-bot/trading_bot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 6c1538a

Please sign in to comment.