|
|
|
|
@ -1,26 +1,51 @@ |
|
|
|
|
import os |
|
|
|
|
import time |
|
|
|
|
from datetime import datetime, date, timedelta |
|
|
|
|
from urllib.parse import urlparse |
|
|
|
|
|
|
|
|
|
# PARAMETERS |
|
|
|
|
CONFIGS = { |
|
|
|
|
"SECRET_KEY": os.urandom(30), # Set the secret key for session authentication |
|
|
|
|
"PERMANENT_SESSION_LIFETIME": timedelta(minutes=60) |
|
|
|
|
"SECRET_KEY": os.environ.get("SECRET_KEY", os.urandom(30).hex()), # Set the secret key for session authentication |
|
|
|
|
"PERMANENT_SESSION_LIFETIME": timedelta(minutes=60) |
|
|
|
|
} |
|
|
|
|
SQL_CONFIG = dict( |
|
|
|
|
|
|
|
|
|
# PostgreSQL config - support both Railway and local Docker |
|
|
|
|
DATABASE_URL = os.environ.get('DATABASE_URL') |
|
|
|
|
if DATABASE_URL: |
|
|
|
|
# Railway provides DATABASE_URL |
|
|
|
|
url = urlparse(DATABASE_URL) |
|
|
|
|
SQL_CONFIG = dict( |
|
|
|
|
database=url.path[1:], |
|
|
|
|
user=url.username, |
|
|
|
|
host=url.hostname, |
|
|
|
|
port=url.port or 5432, |
|
|
|
|
password=url.password |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
# Local Docker fallback |
|
|
|
|
SQL_CONFIG = dict( |
|
|
|
|
database="portfolio_platform", |
|
|
|
|
user="postgres", |
|
|
|
|
host="db", |
|
|
|
|
port="5432", |
|
|
|
|
password="thiispassword1qaz!QAZ" |
|
|
|
|
) |
|
|
|
|
CACHE_CONFIG = { |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# Redis config - support both Railway and local Docker |
|
|
|
|
REDIS_URL = os.environ.get('REDIS_URL') |
|
|
|
|
if REDIS_URL: |
|
|
|
|
# Railway provides REDIS_URL |
|
|
|
|
CACHE_CONFIG = { |
|
|
|
|
'CACHE_TYPE': 'redis', |
|
|
|
|
'CACHE_REDIS_URL': REDIS_URL, |
|
|
|
|
} |
|
|
|
|
else: |
|
|
|
|
# Local Docker fallback |
|
|
|
|
CACHE_CONFIG = { |
|
|
|
|
'CACHE_TYPE': 'redis', |
|
|
|
|
# 'CACHE_REDIS_USER': 'default', |
|
|
|
|
'CACHE_REDIS_HOST': 'redis', |
|
|
|
|
'CACHE_REDIS_PORT': 6379, |
|
|
|
|
# 'CACHE_REDIS_PASSWORD': '5rP99RevPMW94rswBXAL', |
|
|
|
|
# 'CACHE_KEY_PREFIX': 'railway_redis_' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
role_map = dict(max_sharpe='最大化夏普比率', |
|
|
|
|
max_sortino='最大化索提諾比率', |
|
|
|
|
min_volatility='最小化波動率', |
|
|
|
|
|