-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
141 lines (115 loc) Β· 3.94 KB
/
config.py
File metadata and controls
141 lines (115 loc) Β· 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""
Configuration settings for Market Rover system.
"""
import os
from pathlib import Path
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Project Root
PROJECT_ROOT = Path(__file__).parent
# API Keys
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", "")
NEWS_API_KEY = os.getenv("NEWS_API_KEY", "")
# System Settings
MAX_ITERATIONS = int(os.getenv("MAX_ITERATIONS", "5"))
LOOKBACK_DAYS = int(os.getenv("LOOKBACK_DAYS", "7"))
PORTFOLIO_FILE = os.getenv("PORTFOLIO_FILE", "Portfolio.csv")
# Report Settings
# In production (Cloud Run), /app is read-only. Use /tmp instead for ephemeral files.
if os.getenv("K_SERVICE"): # Standard Cloud Run env var
REPORT_DIR = Path("/tmp/reports")
else:
REPORT_DIR = PROJECT_ROOT / os.getenv("REPORT_DIR", "reports")
CONVERT_TO_CRORES = os.getenv("CONVERT_TO_CRORES", "true").lower() == "true"
# Create reports directory if it doesn't exist (Defensive check)
try:
REPORT_DIR.mkdir(parents=True, exist_ok=True)
except Exception:
# Fallback to /tmp if still failing
REPORT_DIR = Path("/tmp/reports")
REPORT_DIR.mkdir(parents=True, exist_ok=True)
# NSE Stock Symbol Settings
NSE_SUFFIX = ".NS"
BSE_SUFFIX = ".BO"
# Sentiment Thresholds
SENTIMENT_POSITIVE_THRESHOLD = 0.3
SENTIMENT_NEGATIVE_THRESHOLD = -0.3
# Parallel Execution Settings (Market-Rover 2.0)
MAX_PARALLEL_STOCKS = int(os.getenv("MAX_PARALLEL_STOCKS", "5"))
RATE_LIMIT_DELAY = float(os.getenv("RATE_LIMIT_DELAY", "1.0"))
# Web UI Settings (Market-Rover 2.0)
if os.getenv("K_SERVICE"):
UPLOAD_DIR = Path("/tmp/uploads")
else:
UPLOAD_DIR = PROJECT_ROOT / os.getenv("UPLOAD_DIR", "uploads")
WEB_PORT = int(os.getenv("WEB_PORT", "8501"))
WEB_HOST = os.getenv("WEB_HOST", "0.0.0.0")
# Create upload directory if it doesn't exist
try:
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
except Exception:
UPLOAD_DIR = Path("/tmp/uploads")
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
# News Sources
MONEYCONTROL_BASE_URL = "https://www.moneycontrol.com"
ONE_LAKH = 100_000
ONE_CRORE = 10_000_000
THOUSAND_CRORE = 10_000_000_000
def convert_to_crores(amount: float) -> str:
"""
Convert amount to Crores format.
Args:
amount: Amount in regular units
Returns:
Formatted string in Crores
"""
if amount >= THOUSAND_CRORE:
return f"βΉ{amount / THOUSAND_CRORE:.2f} Thousand Crore"
elif amount >= ONE_CRORE:
return f"βΉ{amount / ONE_CRORE:.2f} Crore"
elif amount >= ONE_LAKH:
return f"βΉ{amount / ONE_LAKH:.2f} Lakh"
else:
return f"βΉ{amount:,.2f}"
def ensure_nse_suffix(symbol: str) -> str:
"""
Ensure stock symbol has .NS suffix for NSE.
Args:
symbol: Stock symbol
Returns:
Symbol with .NS suffix
"""
symbol = symbol.replace("$", "").strip().upper()
if not symbol.endswith(NSE_SUFFIX) and not symbol.endswith(BSE_SUFFIX):
symbol += NSE_SUFFIX
return symbol
# Issue triage defaults
# Mapping of keyword -> list of GitHub usernames to assign
ISSUE_OWNERS = {
'Visualizer': ['SankarGaneshb'],
'OptionChain': ['SankarGaneshb'],
'Gemini': ['SankarGaneshb'],
'Network': ['SankarGaneshb'],
'MarketData': ['SankarGaneshb'],
'Investbrand': ['SankarGaneshb', 'Jayasreesankarganesh'],
'PledgeRover': ['SankarGaneshb'],
'HILRover': ['SankarGaneshb', 'Jayasreesankarganesh'],
}
# Label rules: substring -> label
LABEL_RULES = [
('Visualizer', 'area:visualizer'),
('OptionChain', 'area:options'),
('nse_option', 'area:options'),
('Gemini', 'area:llm'),
('Investbrand', 'module:investbrand'),
('PledgeRover', 'module:pledgerover'),
('HILRover', 'module:hilrover'),
('timeout', 'type:timeout'),
('ConnectionError', 'type:network'),
('ValueError', 'type:data'),
('KeyError', 'type:data'),
]
# Application Limits
MAX_STOCKS_PER_PORTFOLIO = int(os.getenv("MAX_STOCKS_PER_PORTFOLIO", "20"))
MAX_PORTFOLIOS_PER_USER = int(os.getenv("MAX_PORTFOLIOS_PER_USER", "3"))