Files

1 line
266 KiB
JSON

{"repo": "anupamvm/mcube-ai", "files": {"mcube_ai/settings.py": {"363a364f8b834c1451b31dff8181aa4fecc45fa4": {"t": 1785746918.4732172, "n": 18995, "h": "8f94b685b3d74531", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n# Base URL used for constructing absolute links in Telegram button URLs.\n# Override with SITE_URL env var in production.\nSITE_URL = env('SITE_URL', default='http://localhost:8000')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # Third-party\n 'rest_framework',\n 'corsheaders',\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.llmskill.apps.LlmskillConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n 'apps.hedging.apps.HedgingConfig',\n\n # Family Portfolio Intelligence\n 'apps.investments.apps.InvestmentsConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'corsheaders.middleware.CorsMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\nTELEGRAM_CHAT_IDS = env('TELEGRAM_CHAT_IDS', default='') # comma-separated list of authorized chat IDs\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\nimport os as _os\n\n# Log directory layout:\n# logs/\n# errors.log — ERROR+ from ALL modules (copy-paste to Claude)\n# warnings.log — WARNING from ALL modules\n# celery_beat.log — Celery beat process (written by celery process itself)\n# celery_worker.log — Celery worker process (written by celery process itself)\n# app/ — Web/service layer (views, services, models)\n# django.log — Django framework (requests, ORM, migrations)\n# brokers.log — apps.brokers.*\n# trading.log — apps.trading.*\n# strategies.log — apps.strategies.*\n# positions.log — apps.positions.*\n# analytics.log — apps.analytics.*\n# data.log — apps.data.*\n# alerts.log — apps.alerts.*\n# risk.log — apps.risk.*\n# llm.log — apps.llm.*\n# core.log — apps.core.*\n# accounts.log — apps.accounts.*\n# algo_test.log — apps.algo_test.*\n# tasks/ — Background task layer (Celery, TaskLogger)\n# data.log — data-category tasks (fetch_market_data, etc.)\n# strategies.log — strategy tasks (run_futures_algorithm, etc.)\n# trading.log — transaction tasks (start_options_trade, etc.)\n# analytics.log — analytics tasks (llm analysis, reports, etc.)\n# risk.log — risk-monitoring tasks\n# monitoring.log — system/health monitoring tasks\n# llm.log — LLM processing tasks\n# other.log — uncategorised tasks\n\nLOG_DIR = BASE_DIR / 'logs'\nLOG_APP_DIR = LOG_DIR / 'app'\nLOG_TASKS_DIR = LOG_DIR / 'tasks'\nLOG_RETENTION_DAYS = 7 # daily rotation, keep 7 days\n\n_os.makedirs(LOG_DIR, exist_ok=True)\n_os.makedirs(LOG_APP_DIR, exist_ok=True)\n_os.makedirs(LOG_TASKS_DIR, exist_ok=True)\n\n\ndef _fh(filepath, level='DEBUG', filters=None):\n \"\"\"Build a TimedRotatingFileHandler config — daily rotation, 7-day retention.\"\"\"\n h = {\n 'class': 'logging.handlers.TimedRotatingFileHandler',\n 'filename': str(filepath),\n 'when': 'midnight',\n 'backupCount': LOG_RETENTION_DAYS,\n 'formatter': 'module',\n 'encoding': 'utf-8',\n 'level': level,\n }\n if filters:\n h['filters'] = filters\n return h\n\n\ndef _app_logger(handler_name):\n \"\"\"Web/service layer logger: own module file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\ndef _task_logger(handler_name):\n \"\"\"Background task logger: own task-category file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n # Rich format for file logs — easy to read and paste to Claude\n 'module': {\n 'format': '[%(asctime)s] %(levelname)-8s | %(name)s | %(filename)s:%(lineno)d | %(funcName)s | %(message)s',\n 'datefmt': '%Y-%m-%d %H:%M:%S',\n },\n # Compact format for console output\n 'console': {\n 'format': '[%(asctime)s] %(levelname)s %(module)s: %(message)s',\n 'datefmt': '%H:%M:%S',\n },\n },\n 'filters': {\n 'errors_only': {\n '()': 'apps.core.utils.log_filters.ErrorOnlyFilter',\n },\n 'warnings_only': {\n '()': 'apps.core.utils.log_filters.WarningOnlyFilter',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'console',\n 'level': 'DEBUG',\n },\n # Aggregated cross-module logs — start here when debugging\n 'errors_agg': _fh(LOG_DIR / 'errors.log', 'ERROR', ['errors_only']),\n 'warnings_agg': _fh(LOG_DIR / 'warnings.log', 'WARNING', ['warnings_only']),\n # Framework\n 'django_fh': _fh(LOG_APP_DIR / 'django.log', 'INFO'),\n # Per-module app handlers\n 'brokers_fh': _fh(LOG_APP_DIR / 'brokers.log'),\n 'trading_fh': _fh(LOG_APP_DIR / 'trading.log'),\n 'strategies_fh': _fh(LOG_APP_DIR / 'strategies.log'),\n 'positions_fh': _fh(LOG_APP_DIR / 'positions.log'),\n 'analytics_fh': _fh(LOG_APP_DIR / 'analytics.log'),\n 'data_fh': _fh(LOG_APP_DIR / 'data.log'),\n 'alerts_fh': _fh(LOG_APP_DIR / 'alerts.log'),\n 'risk_fh': _fh(LOG_APP_DIR / 'risk.log'),\n 'llm_fh': _fh(LOG_APP_DIR / 'llm.log'),\n 'core_fh': _fh(LOG_APP_DIR / 'core.log'),\n 'accounts_fh': _fh(LOG_APP_DIR / 'accounts.log'),\n 'algo_test_fh': _fh(LOG_APP_DIR / 'algo_test.log'),\n # Per-category background task handlers (logs/tasks/)\n 'tasks_data_fh': _fh(LOG_TASKS_DIR / 'data.log'),\n 'tasks_strategies_fh': _fh(LOG_TASKS_DIR / 'strategies.log'),\n 'tasks_trading_fh': _fh(LOG_TASKS_DIR / 'trading.log'),\n 'tasks_analytics_fh': _fh(LOG_TASKS_DIR / 'analytics.log'),\n 'tasks_risk_fh': _fh(LOG_TASKS_DIR / 'risk.log'),\n 'tasks_monitoring_fh': _fh(LOG_TASKS_DIR / 'monitoring.log'),\n 'tasks_llm_fh': _fh(LOG_TASKS_DIR / 'llm.log'),\n 'tasks_other_fh': _fh(LOG_TASKS_DIR / 'other.log'),\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'django_fh', 'errors_agg', 'warnings_agg'],\n 'level': 'INFO',\n 'propagate': False,\n },\n # Celery process writes its own log files via --logfile flag;\n # we only capture WARNING+ here so errors surface in errors.log\n 'celery': {\n 'handlers': ['console', 'errors_agg', 'warnings_agg'],\n 'level': 'WARNING',\n 'propagate': False,\n },\n # Background task loggers — routed via TaskLogger using apps.tasks.{category}\n # Each maps to logs/tasks/{category}.log + aggregated errors/warnings\n 'apps.tasks.data': _task_logger('tasks_data_fh'),\n 'apps.tasks.strategies': _task_logger('tasks_strategies_fh'),\n 'apps.tasks.strategy': _task_logger('tasks_strategies_fh'), # variant used in codebase\n 'apps.tasks.transactions': _task_logger('tasks_trading_fh'),\n 'apps.tasks.transaction': _task_logger('tasks_trading_fh'), # variant used in codebase\n 'apps.tasks.analytics': _task_logger('tasks_analytics_fh'),\n 'apps.tasks.risk': _task_logger('tasks_risk_fh'),\n 'apps.tasks.monitoring': _task_logger('tasks_monitoring_fh'),\n 'apps.tasks.llm': _task_logger('tasks_llm_fh'),\n 'apps.tasks': _task_logger('tasks_other_fh'), # fallback for unknown categories\n # Per-module app loggers\n 'apps.brokers': _app_logger('brokers_fh'),\n 'apps.trading': _app_logger('trading_fh'),\n 'apps.strategies': _app_logger('strategies_fh'),\n 'apps.positions': _app_logger('positions_fh'),\n 'apps.analytics': _app_logger('analytics_fh'),\n 'apps.data': _app_logger('data_fh'),\n 'apps.alerts': _app_logger('alerts_fh'),\n 'apps.risk': _app_logger('risk_fh'),\n 'apps.llm': _app_logger('llm_fh'),\n 'apps.core': _app_logger('core_fh'),\n 'apps.accounts': _app_logger('accounts_fh'),\n 'apps.algo_test': _app_logger('algo_test_fh'),\n 'apps.investments': _app_logger('core_fh'),\n },\n}\n\n\n# =============================================================================\n# DJANGO REST FRAMEWORK\n# =============================================================================\n\nREST_FRAMEWORK = {\n 'DEFAULT_AUTHENTICATION_CLASSES': [\n 'rest_framework.authentication.SessionAuthentication',\n ],\n 'DEFAULT_PERMISSION_CLASSES': [\n 'rest_framework.permissions.IsAuthenticated',\n ],\n 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',\n 'PAGE_SIZE': 50,\n 'DEFAULT_RENDERER_CLASSES': [\n 'rest_framework.renderers.JSONRenderer',\n ],\n}\n\n\n# =============================================================================\n# CORS (for Next.js frontend dev server at localhost:3001)\n# =============================================================================\n\nCORS_ALLOWED_ORIGINS = [\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001',\n]\nCORS_ALLOW_CREDENTIALS = True\n\n\n# =============================================================================\n# INVESTMENTS APP (Family Portfolio Intelligence)\n# =============================================================================\n\n# MFAPI base URL\nMFAPI_BASE_URL = 'https://api.mfapi.in/mf'\n\n# Risk-free rate for Sharpe/Sortino calculations (annual, as decimal)\nINVESTMENTS_RISK_FREE_RATE = env.float('INVESTMENTS_RISK_FREE_RATE', default=0.065)\n\n# Redis cache DB for investments (use DB 2 to avoid conflicts with Celery)\nINVESTMENTS_REDIS_URL = env('INVESTMENTS_REDIS_URL', default='redis://localhost:6379/2')\n\n# AES encryption key for CAS file storage (derived from SECRET_KEY if not set)\nINVESTMENTS_ENCRYPTION_KEY = env('INVESTMENTS_ENCRYPTION_KEY', default='')\n\n# Allow JS to read csrftoken cookie (required for Next.js SPA calling Django REST endpoints)\nCSRF_COOKIE_HTTPONLY = False\nCSRF_COOKIE_SAMESITE = 'Lax'\n"}, "71873dc22b01126bd7dc88d07f6adac3a2dfe1d5": {"t": 1785768976.5157056, "n": 18995, "h": "8f94b685b3d74531", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n# Base URL used for constructing absolute links in Telegram button URLs.\n# Override with SITE_URL env var in production.\nSITE_URL = env('SITE_URL', default='http://localhost:8000')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # Third-party\n 'rest_framework',\n 'corsheaders',\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.llmskill.apps.LlmskillConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n 'apps.hedging.apps.HedgingConfig',\n\n # Family Portfolio Intelligence\n 'apps.investments.apps.InvestmentsConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'corsheaders.middleware.CorsMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\nTELEGRAM_CHAT_IDS = env('TELEGRAM_CHAT_IDS', default='') # comma-separated list of authorized chat IDs\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\nimport os as _os\n\n# Log directory layout:\n# logs/\n# errors.log — ERROR+ from ALL modules (copy-paste to Claude)\n# warnings.log — WARNING from ALL modules\n# celery_beat.log — Celery beat process (written by celery process itself)\n# celery_worker.log — Celery worker process (written by celery process itself)\n# app/ — Web/service layer (views, services, models)\n# django.log — Django framework (requests, ORM, migrations)\n# brokers.log — apps.brokers.*\n# trading.log — apps.trading.*\n# strategies.log — apps.strategies.*\n# positions.log — apps.positions.*\n# analytics.log — apps.analytics.*\n# data.log — apps.data.*\n# alerts.log — apps.alerts.*\n# risk.log — apps.risk.*\n# llm.log — apps.llm.*\n# core.log — apps.core.*\n# accounts.log — apps.accounts.*\n# algo_test.log — apps.algo_test.*\n# tasks/ — Background task layer (Celery, TaskLogger)\n# data.log — data-category tasks (fetch_market_data, etc.)\n# strategies.log — strategy tasks (run_futures_algorithm, etc.)\n# trading.log — transaction tasks (start_options_trade, etc.)\n# analytics.log — analytics tasks (llm analysis, reports, etc.)\n# risk.log — risk-monitoring tasks\n# monitoring.log — system/health monitoring tasks\n# llm.log — LLM processing tasks\n# other.log — uncategorised tasks\n\nLOG_DIR = BASE_DIR / 'logs'\nLOG_APP_DIR = LOG_DIR / 'app'\nLOG_TASKS_DIR = LOG_DIR / 'tasks'\nLOG_RETENTION_DAYS = 7 # daily rotation, keep 7 days\n\n_os.makedirs(LOG_DIR, exist_ok=True)\n_os.makedirs(LOG_APP_DIR, exist_ok=True)\n_os.makedirs(LOG_TASKS_DIR, exist_ok=True)\n\n\ndef _fh(filepath, level='DEBUG', filters=None):\n \"\"\"Build a TimedRotatingFileHandler config — daily rotation, 7-day retention.\"\"\"\n h = {\n 'class': 'logging.handlers.TimedRotatingFileHandler',\n 'filename': str(filepath),\n 'when': 'midnight',\n 'backupCount': LOG_RETENTION_DAYS,\n 'formatter': 'module',\n 'encoding': 'utf-8',\n 'level': level,\n }\n if filters:\n h['filters'] = filters\n return h\n\n\ndef _app_logger(handler_name):\n \"\"\"Web/service layer logger: own module file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\ndef _task_logger(handler_name):\n \"\"\"Background task logger: own task-category file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n # Rich format for file logs — easy to read and paste to Claude\n 'module': {\n 'format': '[%(asctime)s] %(levelname)-8s | %(name)s | %(filename)s:%(lineno)d | %(funcName)s | %(message)s',\n 'datefmt': '%Y-%m-%d %H:%M:%S',\n },\n # Compact format for console output\n 'console': {\n 'format': '[%(asctime)s] %(levelname)s %(module)s: %(message)s',\n 'datefmt': '%H:%M:%S',\n },\n },\n 'filters': {\n 'errors_only': {\n '()': 'apps.core.utils.log_filters.ErrorOnlyFilter',\n },\n 'warnings_only': {\n '()': 'apps.core.utils.log_filters.WarningOnlyFilter',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'console',\n 'level': 'DEBUG',\n },\n # Aggregated cross-module logs — start here when debugging\n 'errors_agg': _fh(LOG_DIR / 'errors.log', 'ERROR', ['errors_only']),\n 'warnings_agg': _fh(LOG_DIR / 'warnings.log', 'WARNING', ['warnings_only']),\n # Framework\n 'django_fh': _fh(LOG_APP_DIR / 'django.log', 'INFO'),\n # Per-module app handlers\n 'brokers_fh': _fh(LOG_APP_DIR / 'brokers.log'),\n 'trading_fh': _fh(LOG_APP_DIR / 'trading.log'),\n 'strategies_fh': _fh(LOG_APP_DIR / 'strategies.log'),\n 'positions_fh': _fh(LOG_APP_DIR / 'positions.log'),\n 'analytics_fh': _fh(LOG_APP_DIR / 'analytics.log'),\n 'data_fh': _fh(LOG_APP_DIR / 'data.log'),\n 'alerts_fh': _fh(LOG_APP_DIR / 'alerts.log'),\n 'risk_fh': _fh(LOG_APP_DIR / 'risk.log'),\n 'llm_fh': _fh(LOG_APP_DIR / 'llm.log'),\n 'core_fh': _fh(LOG_APP_DIR / 'core.log'),\n 'accounts_fh': _fh(LOG_APP_DIR / 'accounts.log'),\n 'algo_test_fh': _fh(LOG_APP_DIR / 'algo_test.log'),\n # Per-category background task handlers (logs/tasks/)\n 'tasks_data_fh': _fh(LOG_TASKS_DIR / 'data.log'),\n 'tasks_strategies_fh': _fh(LOG_TASKS_DIR / 'strategies.log'),\n 'tasks_trading_fh': _fh(LOG_TASKS_DIR / 'trading.log'),\n 'tasks_analytics_fh': _fh(LOG_TASKS_DIR / 'analytics.log'),\n 'tasks_risk_fh': _fh(LOG_TASKS_DIR / 'risk.log'),\n 'tasks_monitoring_fh': _fh(LOG_TASKS_DIR / 'monitoring.log'),\n 'tasks_llm_fh': _fh(LOG_TASKS_DIR / 'llm.log'),\n 'tasks_other_fh': _fh(LOG_TASKS_DIR / 'other.log'),\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'django_fh', 'errors_agg', 'warnings_agg'],\n 'level': 'INFO',\n 'propagate': False,\n },\n # Celery process writes its own log files via --logfile flag;\n # we only capture WARNING+ here so errors surface in errors.log\n 'celery': {\n 'handlers': ['console', 'errors_agg', 'warnings_agg'],\n 'level': 'WARNING',\n 'propagate': False,\n },\n # Background task loggers — routed via TaskLogger using apps.tasks.{category}\n # Each maps to logs/tasks/{category}.log + aggregated errors/warnings\n 'apps.tasks.data': _task_logger('tasks_data_fh'),\n 'apps.tasks.strategies': _task_logger('tasks_strategies_fh'),\n 'apps.tasks.strategy': _task_logger('tasks_strategies_fh'), # variant used in codebase\n 'apps.tasks.transactions': _task_logger('tasks_trading_fh'),\n 'apps.tasks.transaction': _task_logger('tasks_trading_fh'), # variant used in codebase\n 'apps.tasks.analytics': _task_logger('tasks_analytics_fh'),\n 'apps.tasks.risk': _task_logger('tasks_risk_fh'),\n 'apps.tasks.monitoring': _task_logger('tasks_monitoring_fh'),\n 'apps.tasks.llm': _task_logger('tasks_llm_fh'),\n 'apps.tasks': _task_logger('tasks_other_fh'), # fallback for unknown categories\n # Per-module app loggers\n 'apps.brokers': _app_logger('brokers_fh'),\n 'apps.trading': _app_logger('trading_fh'),\n 'apps.strategies': _app_logger('strategies_fh'),\n 'apps.positions': _app_logger('positions_fh'),\n 'apps.analytics': _app_logger('analytics_fh'),\n 'apps.data': _app_logger('data_fh'),\n 'apps.alerts': _app_logger('alerts_fh'),\n 'apps.risk': _app_logger('risk_fh'),\n 'apps.llm': _app_logger('llm_fh'),\n 'apps.core': _app_logger('core_fh'),\n 'apps.accounts': _app_logger('accounts_fh'),\n 'apps.algo_test': _app_logger('algo_test_fh'),\n 'apps.investments': _app_logger('core_fh'),\n },\n}\n\n\n# =============================================================================\n# DJANGO REST FRAMEWORK\n# =============================================================================\n\nREST_FRAMEWORK = {\n 'DEFAULT_AUTHENTICATION_CLASSES': [\n 'rest_framework.authentication.SessionAuthentication',\n ],\n 'DEFAULT_PERMISSION_CLASSES': [\n 'rest_framework.permissions.IsAuthenticated',\n ],\n 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',\n 'PAGE_SIZE': 50,\n 'DEFAULT_RENDERER_CLASSES': [\n 'rest_framework.renderers.JSONRenderer',\n ],\n}\n\n\n# =============================================================================\n# CORS (for Next.js frontend dev server at localhost:3001)\n# =============================================================================\n\nCORS_ALLOWED_ORIGINS = [\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001',\n]\nCORS_ALLOW_CREDENTIALS = True\n\n\n# =============================================================================\n# INVESTMENTS APP (Family Portfolio Intelligence)\n# =============================================================================\n\n# MFAPI base URL\nMFAPI_BASE_URL = 'https://api.mfapi.in/mf'\n\n# Risk-free rate for Sharpe/Sortino calculations (annual, as decimal)\nINVESTMENTS_RISK_FREE_RATE = env.float('INVESTMENTS_RISK_FREE_RATE', default=0.065)\n\n# Redis cache DB for investments (use DB 2 to avoid conflicts with Celery)\nINVESTMENTS_REDIS_URL = env('INVESTMENTS_REDIS_URL', default='redis://localhost:6379/2')\n\n# AES encryption key for CAS file storage (derived from SECRET_KEY if not set)\nINVESTMENTS_ENCRYPTION_KEY = env('INVESTMENTS_ENCRYPTION_KEY', default='')\n\n# Allow JS to read csrftoken cookie (required for Next.js SPA calling Django REST endpoints)\nCSRF_COOKIE_HTTPONLY = False\nCSRF_COOKIE_SAMESITE = 'Lax'\n"}, "9267fe914f59927604577ba8dc0f8ab2eba6ceaa": {"t": 1785768979.0881453, "n": 18954, "h": "d2b4c98a9db39bab", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n# Base URL used for constructing absolute links in Telegram button URLs.\n# Override with SITE_URL env var in production.\nSITE_URL = env('SITE_URL', default='http://localhost:8000')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # Third-party\n 'rest_framework',\n 'corsheaders',\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n 'apps.hedging.apps.HedgingConfig',\n\n # Family Portfolio Intelligence\n 'apps.investments.apps.InvestmentsConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'corsheaders.middleware.CorsMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\nTELEGRAM_CHAT_IDS = env('TELEGRAM_CHAT_IDS', default='') # comma-separated list of authorized chat IDs\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\nimport os as _os\n\n# Log directory layout:\n# logs/\n# errors.log — ERROR+ from ALL modules (copy-paste to Claude)\n# warnings.log — WARNING from ALL modules\n# celery_beat.log — Celery beat process (written by celery process itself)\n# celery_worker.log — Celery worker process (written by celery process itself)\n# app/ — Web/service layer (views, services, models)\n# django.log — Django framework (requests, ORM, migrations)\n# brokers.log — apps.brokers.*\n# trading.log — apps.trading.*\n# strategies.log — apps.strategies.*\n# positions.log — apps.positions.*\n# analytics.log — apps.analytics.*\n# data.log — apps.data.*\n# alerts.log — apps.alerts.*\n# risk.log — apps.risk.*\n# llm.log — apps.llm.*\n# core.log — apps.core.*\n# accounts.log — apps.accounts.*\n# algo_test.log — apps.algo_test.*\n# tasks/ — Background task layer (Celery, TaskLogger)\n# data.log — data-category tasks (fetch_market_data, etc.)\n# strategies.log — strategy tasks (run_futures_algorithm, etc.)\n# trading.log — transaction tasks (start_options_trade, etc.)\n# analytics.log — analytics tasks (llm analysis, reports, etc.)\n# risk.log — risk-monitoring tasks\n# monitoring.log — system/health monitoring tasks\n# llm.log — LLM processing tasks\n# other.log — uncategorised tasks\n\nLOG_DIR = BASE_DIR / 'logs'\nLOG_APP_DIR = LOG_DIR / 'app'\nLOG_TASKS_DIR = LOG_DIR / 'tasks'\nLOG_RETENTION_DAYS = 7 # daily rotation, keep 7 days\n\n_os.makedirs(LOG_DIR, exist_ok=True)\n_os.makedirs(LOG_APP_DIR, exist_ok=True)\n_os.makedirs(LOG_TASKS_DIR, exist_ok=True)\n\n\ndef _fh(filepath, level='DEBUG', filters=None):\n \"\"\"Build a TimedRotatingFileHandler config — daily rotation, 7-day retention.\"\"\"\n h = {\n 'class': 'logging.handlers.TimedRotatingFileHandler',\n 'filename': str(filepath),\n 'when': 'midnight',\n 'backupCount': LOG_RETENTION_DAYS,\n 'formatter': 'module',\n 'encoding': 'utf-8',\n 'level': level,\n }\n if filters:\n h['filters'] = filters\n return h\n\n\ndef _app_logger(handler_name):\n \"\"\"Web/service layer logger: own module file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\ndef _task_logger(handler_name):\n \"\"\"Background task logger: own task-category file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n # Rich format for file logs — easy to read and paste to Claude\n 'module': {\n 'format': '[%(asctime)s] %(levelname)-8s | %(name)s | %(filename)s:%(lineno)d | %(funcName)s | %(message)s',\n 'datefmt': '%Y-%m-%d %H:%M:%S',\n },\n # Compact format for console output\n 'console': {\n 'format': '[%(asctime)s] %(levelname)s %(module)s: %(message)s',\n 'datefmt': '%H:%M:%S',\n },\n },\n 'filters': {\n 'errors_only': {\n '()': 'apps.core.utils.log_filters.ErrorOnlyFilter',\n },\n 'warnings_only': {\n '()': 'apps.core.utils.log_filters.WarningOnlyFilter',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'console',\n 'level': 'DEBUG',\n },\n # Aggregated cross-module logs — start here when debugging\n 'errors_agg': _fh(LOG_DIR / 'errors.log', 'ERROR', ['errors_only']),\n 'warnings_agg': _fh(LOG_DIR / 'warnings.log', 'WARNING', ['warnings_only']),\n # Framework\n 'django_fh': _fh(LOG_APP_DIR / 'django.log', 'INFO'),\n # Per-module app handlers\n 'brokers_fh': _fh(LOG_APP_DIR / 'brokers.log'),\n 'trading_fh': _fh(LOG_APP_DIR / 'trading.log'),\n 'strategies_fh': _fh(LOG_APP_DIR / 'strategies.log'),\n 'positions_fh': _fh(LOG_APP_DIR / 'positions.log'),\n 'analytics_fh': _fh(LOG_APP_DIR / 'analytics.log'),\n 'data_fh': _fh(LOG_APP_DIR / 'data.log'),\n 'alerts_fh': _fh(LOG_APP_DIR / 'alerts.log'),\n 'risk_fh': _fh(LOG_APP_DIR / 'risk.log'),\n 'llm_fh': _fh(LOG_APP_DIR / 'llm.log'),\n 'core_fh': _fh(LOG_APP_DIR / 'core.log'),\n 'accounts_fh': _fh(LOG_APP_DIR / 'accounts.log'),\n 'algo_test_fh': _fh(LOG_APP_DIR / 'algo_test.log'),\n # Per-category background task handlers (logs/tasks/)\n 'tasks_data_fh': _fh(LOG_TASKS_DIR / 'data.log'),\n 'tasks_strategies_fh': _fh(LOG_TASKS_DIR / 'strategies.log'),\n 'tasks_trading_fh': _fh(LOG_TASKS_DIR / 'trading.log'),\n 'tasks_analytics_fh': _fh(LOG_TASKS_DIR / 'analytics.log'),\n 'tasks_risk_fh': _fh(LOG_TASKS_DIR / 'risk.log'),\n 'tasks_monitoring_fh': _fh(LOG_TASKS_DIR / 'monitoring.log'),\n 'tasks_llm_fh': _fh(LOG_TASKS_DIR / 'llm.log'),\n 'tasks_other_fh': _fh(LOG_TASKS_DIR / 'other.log'),\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'django_fh', 'errors_agg', 'warnings_agg'],\n 'level': 'INFO',\n 'propagate': False,\n },\n # Celery process writes its own log files via --logfile flag;\n # we only capture WARNING+ here so errors surface in errors.log\n 'celery': {\n 'handlers': ['console', 'errors_agg', 'warnings_agg'],\n 'level': 'WARNING',\n 'propagate': False,\n },\n # Background task loggers — routed via TaskLogger using apps.tasks.{category}\n # Each maps to logs/tasks/{category}.log + aggregated errors/warnings\n 'apps.tasks.data': _task_logger('tasks_data_fh'),\n 'apps.tasks.strategies': _task_logger('tasks_strategies_fh'),\n 'apps.tasks.strategy': _task_logger('tasks_strategies_fh'), # variant used in codebase\n 'apps.tasks.transactions': _task_logger('tasks_trading_fh'),\n 'apps.tasks.transaction': _task_logger('tasks_trading_fh'), # variant used in codebase\n 'apps.tasks.analytics': _task_logger('tasks_analytics_fh'),\n 'apps.tasks.risk': _task_logger('tasks_risk_fh'),\n 'apps.tasks.monitoring': _task_logger('tasks_monitoring_fh'),\n 'apps.tasks.llm': _task_logger('tasks_llm_fh'),\n 'apps.tasks': _task_logger('tasks_other_fh'), # fallback for unknown categories\n # Per-module app loggers\n 'apps.brokers': _app_logger('brokers_fh'),\n 'apps.trading': _app_logger('trading_fh'),\n 'apps.strategies': _app_logger('strategies_fh'),\n 'apps.positions': _app_logger('positions_fh'),\n 'apps.analytics': _app_logger('analytics_fh'),\n 'apps.data': _app_logger('data_fh'),\n 'apps.alerts': _app_logger('alerts_fh'),\n 'apps.risk': _app_logger('risk_fh'),\n 'apps.llm': _app_logger('llm_fh'),\n 'apps.core': _app_logger('core_fh'),\n 'apps.accounts': _app_logger('accounts_fh'),\n 'apps.algo_test': _app_logger('algo_test_fh'),\n 'apps.investments': _app_logger('core_fh'),\n },\n}\n\n\n# =============================================================================\n# DJANGO REST FRAMEWORK\n# =============================================================================\n\nREST_FRAMEWORK = {\n 'DEFAULT_AUTHENTICATION_CLASSES': [\n 'rest_framework.authentication.SessionAuthentication',\n ],\n 'DEFAULT_PERMISSION_CLASSES': [\n 'rest_framework.permissions.IsAuthenticated',\n ],\n 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',\n 'PAGE_SIZE': 50,\n 'DEFAULT_RENDERER_CLASSES': [\n 'rest_framework.renderers.JSONRenderer',\n ],\n}\n\n\n# =============================================================================\n# CORS (for Next.js frontend dev server at localhost:3001)\n# =============================================================================\n\nCORS_ALLOWED_ORIGINS = [\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001',\n]\nCORS_ALLOW_CREDENTIALS = True\n\n\n# =============================================================================\n# INVESTMENTS APP (Family Portfolio Intelligence)\n# =============================================================================\n\n# MFAPI base URL\nMFAPI_BASE_URL = 'https://api.mfapi.in/mf'\n\n# Risk-free rate for Sharpe/Sortino calculations (annual, as decimal)\nINVESTMENTS_RISK_FREE_RATE = env.float('INVESTMENTS_RISK_FREE_RATE', default=0.065)\n\n# Redis cache DB for investments (use DB 2 to avoid conflicts with Celery)\nINVESTMENTS_REDIS_URL = env('INVESTMENTS_REDIS_URL', default='redis://localhost:6379/2')\n\n# AES encryption key for CAS file storage (derived from SECRET_KEY if not set)\nINVESTMENTS_ENCRYPTION_KEY = env('INVESTMENTS_ENCRYPTION_KEY', default='')\n\n# Allow JS to read csrftoken cookie (required for Next.js SPA calling Django REST endpoints)\nCSRF_COOKIE_HTTPONLY = False\nCSRF_COOKIE_SAMESITE = 'Lax'\n"}, "940b3c5a42646e0e08ad60038631885d9663074b": {"t": 1785768982.3173816, "n": 18915, "h": "9e7ebdb2d863c467", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n# Base URL used for constructing absolute links in Telegram button URLs.\n# Override with SITE_URL env var in production.\nSITE_URL = env('SITE_URL', default='http://localhost:8000')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # Third-party\n 'rest_framework',\n 'corsheaders',\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n\n # Family Portfolio Intelligence\n 'apps.investments.apps.InvestmentsConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'corsheaders.middleware.CorsMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\nTELEGRAM_CHAT_IDS = env('TELEGRAM_CHAT_IDS', default='') # comma-separated list of authorized chat IDs\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\nimport os as _os\n\n# Log directory layout:\n# logs/\n# errors.log — ERROR+ from ALL modules (copy-paste to Claude)\n# warnings.log — WARNING from ALL modules\n# celery_beat.log — Celery beat process (written by celery process itself)\n# celery_worker.log — Celery worker process (written by celery process itself)\n# app/ — Web/service layer (views, services, models)\n# django.log — Django framework (requests, ORM, migrations)\n# brokers.log — apps.brokers.*\n# trading.log — apps.trading.*\n# strategies.log — apps.strategies.*\n# positions.log — apps.positions.*\n# analytics.log — apps.analytics.*\n# data.log — apps.data.*\n# alerts.log — apps.alerts.*\n# risk.log — apps.risk.*\n# llm.log — apps.llm.*\n# core.log — apps.core.*\n# accounts.log — apps.accounts.*\n# algo_test.log — apps.algo_test.*\n# tasks/ — Background task layer (Celery, TaskLogger)\n# data.log — data-category tasks (fetch_market_data, etc.)\n# strategies.log — strategy tasks (run_futures_algorithm, etc.)\n# trading.log — transaction tasks (start_options_trade, etc.)\n# analytics.log — analytics tasks (llm analysis, reports, etc.)\n# risk.log — risk-monitoring tasks\n# monitoring.log — system/health monitoring tasks\n# llm.log — LLM processing tasks\n# other.log — uncategorised tasks\n\nLOG_DIR = BASE_DIR / 'logs'\nLOG_APP_DIR = LOG_DIR / 'app'\nLOG_TASKS_DIR = LOG_DIR / 'tasks'\nLOG_RETENTION_DAYS = 7 # daily rotation, keep 7 days\n\n_os.makedirs(LOG_DIR, exist_ok=True)\n_os.makedirs(LOG_APP_DIR, exist_ok=True)\n_os.makedirs(LOG_TASKS_DIR, exist_ok=True)\n\n\ndef _fh(filepath, level='DEBUG', filters=None):\n \"\"\"Build a TimedRotatingFileHandler config — daily rotation, 7-day retention.\"\"\"\n h = {\n 'class': 'logging.handlers.TimedRotatingFileHandler',\n 'filename': str(filepath),\n 'when': 'midnight',\n 'backupCount': LOG_RETENTION_DAYS,\n 'formatter': 'module',\n 'encoding': 'utf-8',\n 'level': level,\n }\n if filters:\n h['filters'] = filters\n return h\n\n\ndef _app_logger(handler_name):\n \"\"\"Web/service layer logger: own module file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\ndef _task_logger(handler_name):\n \"\"\"Background task logger: own task-category file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n # Rich format for file logs — easy to read and paste to Claude\n 'module': {\n 'format': '[%(asctime)s] %(levelname)-8s | %(name)s | %(filename)s:%(lineno)d | %(funcName)s | %(message)s',\n 'datefmt': '%Y-%m-%d %H:%M:%S',\n },\n # Compact format for console output\n 'console': {\n 'format': '[%(asctime)s] %(levelname)s %(module)s: %(message)s',\n 'datefmt': '%H:%M:%S',\n },\n },\n 'filters': {\n 'errors_only': {\n '()': 'apps.core.utils.log_filters.ErrorOnlyFilter',\n },\n 'warnings_only': {\n '()': 'apps.core.utils.log_filters.WarningOnlyFilter',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'console',\n 'level': 'DEBUG',\n },\n # Aggregated cross-module logs — start here when debugging\n 'errors_agg': _fh(LOG_DIR / 'errors.log', 'ERROR', ['errors_only']),\n 'warnings_agg': _fh(LOG_DIR / 'warnings.log', 'WARNING', ['warnings_only']),\n # Framework\n 'django_fh': _fh(LOG_APP_DIR / 'django.log', 'INFO'),\n # Per-module app handlers\n 'brokers_fh': _fh(LOG_APP_DIR / 'brokers.log'),\n 'trading_fh': _fh(LOG_APP_DIR / 'trading.log'),\n 'strategies_fh': _fh(LOG_APP_DIR / 'strategies.log'),\n 'positions_fh': _fh(LOG_APP_DIR / 'positions.log'),\n 'analytics_fh': _fh(LOG_APP_DIR / 'analytics.log'),\n 'data_fh': _fh(LOG_APP_DIR / 'data.log'),\n 'alerts_fh': _fh(LOG_APP_DIR / 'alerts.log'),\n 'risk_fh': _fh(LOG_APP_DIR / 'risk.log'),\n 'llm_fh': _fh(LOG_APP_DIR / 'llm.log'),\n 'core_fh': _fh(LOG_APP_DIR / 'core.log'),\n 'accounts_fh': _fh(LOG_APP_DIR / 'accounts.log'),\n 'algo_test_fh': _fh(LOG_APP_DIR / 'algo_test.log'),\n # Per-category background task handlers (logs/tasks/)\n 'tasks_data_fh': _fh(LOG_TASKS_DIR / 'data.log'),\n 'tasks_strategies_fh': _fh(LOG_TASKS_DIR / 'strategies.log'),\n 'tasks_trading_fh': _fh(LOG_TASKS_DIR / 'trading.log'),\n 'tasks_analytics_fh': _fh(LOG_TASKS_DIR / 'analytics.log'),\n 'tasks_risk_fh': _fh(LOG_TASKS_DIR / 'risk.log'),\n 'tasks_monitoring_fh': _fh(LOG_TASKS_DIR / 'monitoring.log'),\n 'tasks_llm_fh': _fh(LOG_TASKS_DIR / 'llm.log'),\n 'tasks_other_fh': _fh(LOG_TASKS_DIR / 'other.log'),\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'django_fh', 'errors_agg', 'warnings_agg'],\n 'level': 'INFO',\n 'propagate': False,\n },\n # Celery process writes its own log files via --logfile flag;\n # we only capture WARNING+ here so errors surface in errors.log\n 'celery': {\n 'handlers': ['console', 'errors_agg', 'warnings_agg'],\n 'level': 'WARNING',\n 'propagate': False,\n },\n # Background task loggers — routed via TaskLogger using apps.tasks.{category}\n # Each maps to logs/tasks/{category}.log + aggregated errors/warnings\n 'apps.tasks.data': _task_logger('tasks_data_fh'),\n 'apps.tasks.strategies': _task_logger('tasks_strategies_fh'),\n 'apps.tasks.strategy': _task_logger('tasks_strategies_fh'), # variant used in codebase\n 'apps.tasks.transactions': _task_logger('tasks_trading_fh'),\n 'apps.tasks.transaction': _task_logger('tasks_trading_fh'), # variant used in codebase\n 'apps.tasks.analytics': _task_logger('tasks_analytics_fh'),\n 'apps.tasks.risk': _task_logger('tasks_risk_fh'),\n 'apps.tasks.monitoring': _task_logger('tasks_monitoring_fh'),\n 'apps.tasks.llm': _task_logger('tasks_llm_fh'),\n 'apps.tasks': _task_logger('tasks_other_fh'), # fallback for unknown categories\n # Per-module app loggers\n 'apps.brokers': _app_logger('brokers_fh'),\n 'apps.trading': _app_logger('trading_fh'),\n 'apps.strategies': _app_logger('strategies_fh'),\n 'apps.positions': _app_logger('positions_fh'),\n 'apps.analytics': _app_logger('analytics_fh'),\n 'apps.data': _app_logger('data_fh'),\n 'apps.alerts': _app_logger('alerts_fh'),\n 'apps.risk': _app_logger('risk_fh'),\n 'apps.llm': _app_logger('llm_fh'),\n 'apps.core': _app_logger('core_fh'),\n 'apps.accounts': _app_logger('accounts_fh'),\n 'apps.algo_test': _app_logger('algo_test_fh'),\n 'apps.investments': _app_logger('core_fh'),\n },\n}\n\n\n# =============================================================================\n# DJANGO REST FRAMEWORK\n# =============================================================================\n\nREST_FRAMEWORK = {\n 'DEFAULT_AUTHENTICATION_CLASSES': [\n 'rest_framework.authentication.SessionAuthentication',\n ],\n 'DEFAULT_PERMISSION_CLASSES': [\n 'rest_framework.permissions.IsAuthenticated',\n ],\n 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',\n 'PAGE_SIZE': 50,\n 'DEFAULT_RENDERER_CLASSES': [\n 'rest_framework.renderers.JSONRenderer',\n ],\n}\n\n\n# =============================================================================\n# CORS (for Next.js frontend dev server at localhost:3001)\n# =============================================================================\n\nCORS_ALLOWED_ORIGINS = [\n 'http://localhost:3000',\n 'http://localhost:3001',\n 'http://127.0.0.1:3000',\n 'http://127.0.0.1:3001',\n]\nCORS_ALLOW_CREDENTIALS = True\n\n\n# =============================================================================\n# INVESTMENTS APP (Family Portfolio Intelligence)\n# =============================================================================\n\n# MFAPI base URL\nMFAPI_BASE_URL = 'https://api.mfapi.in/mf'\n\n# Risk-free rate for Sharpe/Sortino calculations (annual, as decimal)\nINVESTMENTS_RISK_FREE_RATE = env.float('INVESTMENTS_RISK_FREE_RATE', default=0.065)\n\n# Redis cache DB for investments (use DB 2 to avoid conflicts with Celery)\nINVESTMENTS_REDIS_URL = env('INVESTMENTS_REDIS_URL', default='redis://localhost:6379/2')\n\n# AES encryption key for CAS file storage (derived from SECRET_KEY if not set)\nINVESTMENTS_ENCRYPTION_KEY = env('INVESTMENTS_ENCRYPTION_KEY', default='')\n\n# Allow JS to read csrftoken cookie (required for Next.js SPA calling Django REST endpoints)\nCSRF_COOKIE_HTTPONLY = False\nCSRF_COOKIE_SAMESITE = 'Lax'\n"}, "5e2920e77cf468449bb4990b876d6cb3e23fa4c1": {"t": 1785768985.314121, "n": 16771, "h": "afa765a6fcc4440b", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n# Base URL used for constructing absolute links in Telegram button URLs.\n# Override with SITE_URL env var in production.\nSITE_URL = env('SITE_URL', default='http://localhost:8000')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\nTELEGRAM_CHAT_IDS = env('TELEGRAM_CHAT_IDS', default='') # comma-separated list of authorized chat IDs\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\nimport os as _os\n\n# Log directory layout:\n# logs/\n# errors.log — ERROR+ from ALL modules (copy-paste to Claude)\n# warnings.log — WARNING from ALL modules\n# celery_beat.log — Celery beat process (written by celery process itself)\n# celery_worker.log — Celery worker process (written by celery process itself)\n# app/ — Web/service layer (views, services, models)\n# django.log — Django framework (requests, ORM, migrations)\n# brokers.log — apps.brokers.*\n# trading.log — apps.trading.*\n# strategies.log — apps.strategies.*\n# positions.log — apps.positions.*\n# analytics.log — apps.analytics.*\n# data.log — apps.data.*\n# alerts.log — apps.alerts.*\n# risk.log — apps.risk.*\n# llm.log — apps.llm.*\n# core.log — apps.core.*\n# accounts.log — apps.accounts.*\n# algo_test.log — apps.algo_test.*\n# tasks/ — Background task layer (Celery, TaskLogger)\n# data.log — data-category tasks (fetch_market_data, etc.)\n# strategies.log — strategy tasks (run_futures_algorithm, etc.)\n# trading.log — transaction tasks (start_options_trade, etc.)\n# analytics.log — analytics tasks (llm analysis, reports, etc.)\n# risk.log — risk-monitoring tasks\n# monitoring.log — system/health monitoring tasks\n# llm.log — LLM processing tasks\n# other.log — uncategorised tasks\n\nLOG_DIR = BASE_DIR / 'logs'\nLOG_APP_DIR = LOG_DIR / 'app'\nLOG_TASKS_DIR = LOG_DIR / 'tasks'\nLOG_RETENTION_DAYS = 7 # daily rotation, keep 7 days\n\n_os.makedirs(LOG_DIR, exist_ok=True)\n_os.makedirs(LOG_APP_DIR, exist_ok=True)\n_os.makedirs(LOG_TASKS_DIR, exist_ok=True)\n\n\ndef _fh(filepath, level='DEBUG', filters=None):\n \"\"\"Build a TimedRotatingFileHandler config — daily rotation, 7-day retention.\"\"\"\n h = {\n 'class': 'logging.handlers.TimedRotatingFileHandler',\n 'filename': str(filepath),\n 'when': 'midnight',\n 'backupCount': LOG_RETENTION_DAYS,\n 'formatter': 'module',\n 'encoding': 'utf-8',\n 'level': level,\n }\n if filters:\n h['filters'] = filters\n return h\n\n\ndef _app_logger(handler_name):\n \"\"\"Web/service layer logger: own module file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\ndef _task_logger(handler_name):\n \"\"\"Background task logger: own task-category file + aggregated error/warning + console.\"\"\"\n return {\n 'handlers': ['console', handler_name, 'errors_agg', 'warnings_agg'],\n 'level': 'DEBUG',\n 'propagate': False,\n }\n\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n # Rich format for file logs — easy to read and paste to Claude\n 'module': {\n 'format': '[%(asctime)s] %(levelname)-8s | %(name)s | %(filename)s:%(lineno)d | %(funcName)s | %(message)s',\n 'datefmt': '%Y-%m-%d %H:%M:%S',\n },\n # Compact format for console output\n 'console': {\n 'format': '[%(asctime)s] %(levelname)s %(module)s: %(message)s',\n 'datefmt': '%H:%M:%S',\n },\n },\n 'filters': {\n 'errors_only': {\n '()': 'apps.core.utils.log_filters.ErrorOnlyFilter',\n },\n 'warnings_only': {\n '()': 'apps.core.utils.log_filters.WarningOnlyFilter',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'console',\n 'level': 'DEBUG',\n },\n # Aggregated cross-module logs — start here when debugging\n 'errors_agg': _fh(LOG_DIR / 'errors.log', 'ERROR', ['errors_only']),\n 'warnings_agg': _fh(LOG_DIR / 'warnings.log', 'WARNING', ['warnings_only']),\n # Framework\n 'django_fh': _fh(LOG_APP_DIR / 'django.log', 'INFO'),\n # Per-module app handlers\n 'brokers_fh': _fh(LOG_APP_DIR / 'brokers.log'),\n 'trading_fh': _fh(LOG_APP_DIR / 'trading.log'),\n 'strategies_fh': _fh(LOG_APP_DIR / 'strategies.log'),\n 'positions_fh': _fh(LOG_APP_DIR / 'positions.log'),\n 'analytics_fh': _fh(LOG_APP_DIR / 'analytics.log'),\n 'data_fh': _fh(LOG_APP_DIR / 'data.log'),\n 'alerts_fh': _fh(LOG_APP_DIR / 'alerts.log'),\n 'risk_fh': _fh(LOG_APP_DIR / 'risk.log'),\n 'llm_fh': _fh(LOG_APP_DIR / 'llm.log'),\n 'core_fh': _fh(LOG_APP_DIR / 'core.log'),\n 'accounts_fh': _fh(LOG_APP_DIR / 'accounts.log'),\n 'algo_test_fh': _fh(LOG_APP_DIR / 'algo_test.log'),\n # Per-category background task handlers (logs/tasks/)\n 'tasks_data_fh': _fh(LOG_TASKS_DIR / 'data.log'),\n 'tasks_strategies_fh': _fh(LOG_TASKS_DIR / 'strategies.log'),\n 'tasks_trading_fh': _fh(LOG_TASKS_DIR / 'trading.log'),\n 'tasks_analytics_fh': _fh(LOG_TASKS_DIR / 'analytics.log'),\n 'tasks_risk_fh': _fh(LOG_TASKS_DIR / 'risk.log'),\n 'tasks_monitoring_fh': _fh(LOG_TASKS_DIR / 'monitoring.log'),\n 'tasks_llm_fh': _fh(LOG_TASKS_DIR / 'llm.log'),\n 'tasks_other_fh': _fh(LOG_TASKS_DIR / 'other.log'),\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'django_fh', 'errors_agg', 'warnings_agg'],\n 'level': 'INFO',\n 'propagate': False,\n },\n # Celery process writes its own log files via --logfile flag;\n # we only capture WARNING+ here so errors surface in errors.log\n 'celery': {\n 'handlers': ['console', 'errors_agg', 'warnings_agg'],\n 'level': 'WARNING',\n 'propagate': False,\n },\n # Background task loggers — routed via TaskLogger using apps.tasks.{category}\n # Each maps to logs/tasks/{category}.log + aggregated errors/warnings\n 'apps.tasks.data': _task_logger('tasks_data_fh'),\n 'apps.tasks.strategies': _task_logger('tasks_strategies_fh'),\n 'apps.tasks.strategy': _task_logger('tasks_strategies_fh'), # variant used in codebase\n 'apps.tasks.transactions': _task_logger('tasks_trading_fh'),\n 'apps.tasks.transaction': _task_logger('tasks_trading_fh'), # variant used in codebase\n 'apps.tasks.analytics': _task_logger('tasks_analytics_fh'),\n 'apps.tasks.risk': _task_logger('tasks_risk_fh'),\n 'apps.tasks.monitoring': _task_logger('tasks_monitoring_fh'),\n 'apps.tasks.llm': _task_logger('tasks_llm_fh'),\n 'apps.tasks': _task_logger('tasks_other_fh'), # fallback for unknown categories\n # Per-module app loggers\n 'apps.brokers': _app_logger('brokers_fh'),\n 'apps.trading': _app_logger('trading_fh'),\n 'apps.strategies': _app_logger('strategies_fh'),\n 'apps.positions': _app_logger('positions_fh'),\n 'apps.analytics': _app_logger('analytics_fh'),\n 'apps.data': _app_logger('data_fh'),\n 'apps.alerts': _app_logger('alerts_fh'),\n 'apps.risk': _app_logger('risk_fh'),\n 'apps.llm': _app_logger('llm_fh'),\n 'apps.core': _app_logger('core_fh'),\n 'apps.accounts': _app_logger('accounts_fh'),\n 'apps.algo_test': _app_logger('algo_test_fh'),\n },\n}\n"}, "f4801a2d7274b9dae9b5df526beae61c2a668180": {"t": 1785768990.883823, "n": 10446, "h": "63ee05c69046db0d", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n# Base URL used for constructing absolute links in Telegram button URLs.\n# Override with SITE_URL env var in production.\nSITE_URL = env('SITE_URL', default='http://localhost:8000')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\nTELEGRAM_CHAT_IDS = env('TELEGRAM_CHAT_IDS', default='') # comma-separated list of authorized chat IDs\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "648bdd95f33d3cbbfe19c428b57c18704f9f9dca": {"t": 1785768992.4631662, "n": 10264, "h": "e4ad53f60c55d5ff", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\nTELEGRAM_CHAT_IDS = env('TELEGRAM_CHAT_IDS', default='') # comma-separated list of authorized chat IDs\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "b746c283fb27f7423810fed51fefa53d3f03d8e7": {"t": 1785768993.8877032, "n": 10159, "h": "aab43271eefa9f66", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n try:\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n except Exception:\n # Database may be malformed (e.g. stale -shm/-wal files checked out via git).\n # Skip WAL setup silently — the install script will repair the DB before migrate.\n pass\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "f0513a301229e47917f113f46b657bdaaede9303": {"t": 1785768995.5958543, "n": 9903, "h": "bb9d1b4bde3ec899", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n # ALLOWED_HOSTS is hardcoded below — not read from env\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - defined here as the single source of truth\nALLOWED_HOSTS = [\n 'localhost',\n '127.0.0.1',\n '27.107.134.179',\n '169.254.3.1',\n '192.168.1.32',\n]\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "190ee5edb9070e98cded2e34ddbfe86c96c01dae": {"t": 1785768997.3103104, "n": 9923, "h": "7f11d9b71a795160", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1','27.107.134.179','169.254.3.1','192.168.1.32']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 60, # Wait up to 60s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n cursor.execute(\"PRAGMA busy_timeout=60000;\") # 60s retry on lock at SQLite level\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "efb5bc343009bae39a045ce7a99385ffdbd8af12": {"t": 1785768998.6891189, "n": 9833, "h": "6c054d96c1a3d5ae", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1','27.107.134.179','169.254.3.1','192.168.1.32']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 30, # Wait up to 30s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (loaded from .env)\nTELEGRAM_BOT_TOKEN = env('TELEGRAM_BOT_TOKEN', default='')\nTELEGRAM_CHAT_ID = env('TELEGRAM_CHAT_ID', default='')\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "d78439630054eb53c38d28e4c8b3cc4b3651d4b6": {"t": 1785769001.080764, "n": 9952, "h": "c6d4c995b2a0b47b", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1','27.107.134.179','169.254.3.1','192.168.1.32']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 30, # Wait up to 30s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "01fba0ba667c55d67934de07a17372299525b3e3": {"t": 1785769003.78096, "n": 9945, "h": "b7f3df3362ac7a26", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1','http://27.107.134.179/','169.254.3.1']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 30, # Wait up to 30s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "53afea1ddde79f87ede8fdbf0a3b948df315126f": {"t": 1785769005.3049436, "n": 9906, "h": "a21b5d63740a50f4", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n 'OPTIONS': {\n 'timeout': 30, # Wait up to 30s for DB lock (prevents \"database is locked\")\n },\n }\n}\n\n\n# SQLite performance: enable WAL mode for concurrent read/write access.\n# Prevents \"database is locked\" when Celery workers and web server write simultaneously.\ndef _sqlite_wal_mode(sender, connection, **kwargs):\n if connection.vendor == 'sqlite':\n cursor = connection.cursor()\n cursor.execute(\"PRAGMA journal_mode=WAL;\")\n cursor.execute(\"PRAGMA synchronous=NORMAL;\")\n\nfrom django.db.backends.signals import connection_created\nconnection_created.connect(_sqlite_wal_mode)\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "391f0d7eede3972d92652e15dc2c7dd4c8a24729": {"t": 1785769006.5237463, "n": 9287, "h": "3fa2efb78184749f", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATICFILES_DIRS = [\n BASE_DIR / 'static',\n]\n# STATIC_ROOT should be different from STATICFILES_DIRS for collectstatic\nSTATIC_ROOT = BASE_DIR / 'staticfiles'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "55fd0941bc7dbed6980bfd77ec67a21a4265c51d": {"t": 1785769007.7420735, "n": 9160, "h": "bf4d83255f75a981", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n # Using Celery for background tasks (configured via CELERY_* settings below)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATIC_ROOT = BASE_DIR / 'static'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "c838bcbe4c9bc7fbfae37b0fc57066c1dd221042": {"t": 1785769009.28921, "n": 9151, "h": "01d3dc51b0d4851b", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n 'background_task', # Django background tasks (simpler than Celery)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATIC_ROOT = BASE_DIR / 'static'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "2524f1191a1716af12dcaec7fbfc65d1fe0973b6": {"t": 1785769010.781521, "n": 9188, "h": "a56a5e712ee6fb76", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n 'background_task', # Django background tasks (simpler than Celery)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.orders.apps.OrdersConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATIC_ROOT = BASE_DIR / 'static'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "aaaa43766f97d75a1cee573b5f2f75076b01d610": {"t": 1785769012.5753224, "n": 9153, "h": "6f314fff41148436", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\nConfiguration:\n - Uses django-environ for environment variable management\n - Loads settings from .env file in project root\n - See .env.example for required environment variables\n\"\"\"\n\nfrom pathlib import Path\nimport environ\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n# Initialize environment variables\nenv = environ.Env(\n # Set default values and casting\n DEBUG=(bool, False), # Default to False for production safety\n ALLOWED_HOSTS=(list, ['localhost', '127.0.0.1']),\n)\n\n# Read .env file\nenv_file = BASE_DIR / '.env'\nif env_file.exists():\n environ.Env.read_env(env_file)\nelse:\n # In production, environment variables should be set externally\n # This warning helps catch configuration issues\n import warnings\n warnings.warn(\n \"No .env file found. Using environment variables or defaults. \"\n \"For local development, copy .env.example to .env\",\n UserWarning\n )\n\n\n# SECURITY WARNING: keep the secret key used in production secret!\n# In production, this MUST be set via environment variable\nSECRET_KEY = env('SECRET_KEY', default='django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2')\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# Set DEBUG=False in production .env file\nDEBUG = env('DEBUG')\n\n# Allowed hosts - configure in .env file\n# Example in .env: ALLOWED_HOSTS=example.com,www.example.com,api.example.com\nALLOWED_HOSTS = env('ALLOWED_HOSTS')\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n 'background_task', # Django background tasks (simpler than Celery)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.orders.apps.OrdersConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = 'static/'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "dda673e105939a1da529adeb43fdd8a23675e2ee": {"t": 1785769013.96239, "n": 8172, "h": "827fccf81a07bbd2", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\"\"\"\n\nfrom pathlib import Path\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = 'django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2'\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = True\n\nALLOWED_HOSTS = []\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n 'background_task', # Django background tasks (simpler than Celery)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.orders.apps.OrdersConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = 'static/'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '6386769117:AAHt_4krbiU0KlBdCLhhVgC-TCQVUnzvywo' # @dmcube_bot\nTELEGRAM_CHAT_ID = '788423838' # Will be auto-detected on first message\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "bc2639f094af625cd023a90108603a8afb854aac": {"t": 1785769015.301097, "n": 8132, "h": "3fc21ede8e57004f", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\"\"\"\n\nfrom pathlib import Path\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = 'django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2'\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = True\n\nALLOWED_HOSTS = []\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n 'background_task', # Django background tasks (simpler than Celery)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.orders.apps.OrdersConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n 'apps.trading.apps.TradingConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = 'static/'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '' # TODO: Add your Telegram bot token\nTELEGRAM_CHAT_ID = '' # TODO: Add your Telegram chat ID\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "857ead4cca1e99a035b7c5910174254bcad7f50d": {"t": 1785769018.6368306, "n": 8093, "h": "c7a736a2e26539d8", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\"\"\"\n\nfrom pathlib import Path\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = 'django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2'\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = True\n\nALLOWED_HOSTS = []\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n 'background_task', # Django background tasks (simpler than Celery)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.orders.apps.OrdersConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n # Custom middleware\n 'apps.core.middleware.URLLoggingMiddleware',\n 'apps.core.middleware.ErrorHandlingMiddleware',\n 'apps.core.middleware.SecurityHeadersMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = 'static/'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/' # Use broker login page\nLOGIN_REDIRECT_URL = '/' # Redirect to home page after login\nLOGOUT_REDIRECT_URL = '/' # Redirect to home page after logout\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '' # TODO: Add your Telegram bot token\nTELEGRAM_CHAT_ID = '' # TODO: Add your Telegram chat ID\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}, "94a11f025ac65a01d18618510fa54c2de01208da": {"t": 1785769019.9577744, "n": 7836, "h": "4eb287f50e234ed3", "c": "\"\"\"\nDjango settings for mcube_ai project.\n\nGenerated by 'django-admin startproject' using Django 4.2.2.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.2/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.2/ref/settings/\n\"\"\"\n\nfrom pathlib import Path\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = 'django-insecure-1kl+i4u(*w@#_l5&spm2t$jft9_&fuy&0k)_gs59ueri*(+8u2'\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = True\n\nALLOWED_HOSTS = []\n\n\n# Application definition\n\nINSTALLED_APPS = [\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n\n # Third-party apps\n 'background_task', # Django background tasks (simpler than Celery)\n\n # mCube Trading System Apps\n 'apps.core.apps.CoreConfig',\n 'apps.accounts.apps.AccountsConfig',\n 'apps.positions.apps.PositionsConfig',\n 'apps.orders.apps.OrdersConfig',\n 'apps.strategies.apps.StrategiesConfig',\n 'apps.risk.apps.RiskConfig',\n 'apps.data.apps.DataConfig',\n 'apps.llm.apps.LlmConfig',\n 'apps.analytics.apps.AnalyticsConfig',\n 'apps.alerts.apps.AlertsConfig',\n 'apps.brokers.apps.BrokersConfig',\n]\n\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nROOT_URLCONF = 'mcube_ai.urls'\n\nTEMPLATES = [\n {\n 'BACKEND': 'django.template.backends.django.DjangoTemplates',\n 'DIRS': [BASE_DIR / 'templates'],\n 'APP_DIRS': True,\n 'OPTIONS': {\n 'context_processors': [\n 'django.template.context_processors.debug',\n 'django.template.context_processors.request',\n 'django.contrib.auth.context_processors.auth',\n 'django.contrib.messages.context_processors.messages',\n ],\n },\n },\n]\n\nWSGI_APPLICATION = 'mcube_ai.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.2/ref/settings/#databases\n\nDATABASES = {\n 'default': {\n 'ENGINE': 'django.db.backends.sqlite3',\n 'NAME': BASE_DIR / 'db.sqlite3',\n }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n {\n 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n },\n {\n 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.2/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'Asia/Kolkata' # Indian Standard Time\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.2/howto/static-files/\n\nSTATIC_URL = 'static/'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n\n# Authentication settings\nLOGIN_URL = '/brokers/login/'\nLOGIN_REDIRECT_URL = '/brokers/'\nLOGOUT_REDIRECT_URL = '/brokers/login/'\n\n\n# =============================================================================\n# CELERY CONFIGURATION\n# =============================================================================\n\n# Celery broker URL (Redis)\nCELERY_BROKER_URL = 'redis://localhost:6379/0'\n\n# Celery result backend (Redis)\nCELERY_RESULT_BACKEND = 'redis://localhost:6379/1'\n\n# Celery task serialization\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_ACCEPT_CONTENT = ['json']\n\n# Celery timezone settings\nCELERY_TIMEZONE = 'Asia/Kolkata'\nCELERY_ENABLE_UTC = False\n\n# Celery task settings\nCELERY_TASK_TIME_LIMIT = 300 # 5 minutes max (hard limit)\nCELERY_TASK_SOFT_TIME_LIMIT = 240 # 4 minutes (soft limit - raises exception)\nCELERY_TASK_ACKS_LATE = True # Acknowledge task after execution (not before)\nCELERY_TASK_REJECT_ON_WORKER_LOST = True # Reject task if worker dies\n\n# Celery result settings\nCELERY_RESULT_EXPIRES = 3600 # Results expire after 1 hour\n\n# Celery worker settings\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4 # Prefetch 4 tasks per worker\nCELERY_WORKER_MAX_TASKS_PER_CHILD = 1000 # Restart worker after 1000 tasks (prevent memory leaks)\n\n# Celery Beat schedule is defined in mcube_ai/celery.py\n# This keeps the schedule configuration centralized\n\n\n# =============================================================================\n# TELEGRAM BOT CONFIGURATION\n# =============================================================================\n\n# Telegram Bot API settings (for alerts and notifications)\n# These should be moved to environment variables in production\nTELEGRAM_BOT_TOKEN = '' # TODO: Add your Telegram bot token\nTELEGRAM_CHAT_ID = '' # TODO: Add your Telegram chat ID\n\n\n# =============================================================================\n# LLM CONFIGURATION\n# =============================================================================\n\n# Ollama LLM settings\nOLLAMA_BASE_URL = 'http://localhost:11434' # Default Ollama URL\nOLLAMA_MODEL = 'deepseek-r1:7b' # DeepSeek R1 7B model\n\n# LLM models directory (for downloaded GGUF files)\nLLM_MODELS_DIR = BASE_DIR / 'llm_models'\n\n\n# =============================================================================\n# MARKET DATA CONFIGURATION\n# =============================================================================\n\n# Trendlyne API settings\nTRENDLYNE_API_KEY = '' # TODO: Add your Trendlyne API key\n\n# Market hours (IST)\nMARKET_OPEN_TIME = '09:15'\nMARKET_CLOSE_TIME = '15:30'\n\n# Data refresh intervals (in seconds)\nLIVE_DATA_REFRESH_INTERVAL = 300 # 5 minutes\nPRE_MARKET_REFRESH_INTERVAL = 600 # 10 minutes\n\n\n# =============================================================================\n# LOGGING CONFIGURATION\n# =============================================================================\n\nLOGGING = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'formatters': {\n 'verbose': {\n 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',\n 'style': '{',\n },\n 'simple': {\n 'format': '{levelname} {asctime} {message}',\n 'style': '{',\n },\n },\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n 'formatter': 'simple',\n },\n 'file': {\n 'class': 'logging.FileHandler',\n 'filename': BASE_DIR / 'logs' / 'mcube_ai.log',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'celery': {\n 'handlers': ['console', 'file'],\n 'level': 'INFO',\n 'propagate': True,\n },\n 'apps': {\n 'handlers': ['console', 'file'],\n 'level': 'DEBUG',\n 'propagate': True,\n },\n },\n}\n"}}}}