Spaces:
Runtime error
Runtime error
Pedot commited on
Commit Β·
28bf275
1
Parent(s): 075cd2c
FCPO: add market depth (OHLC + volume + contract info) from Investing.com via cloudscraper
Browse files- bot.py +26 -2
- collector.py +141 -2
- dashboard.py +44 -2
- requirements.txt +2 -1
bot.py
CHANGED
|
@@ -120,6 +120,7 @@ def generate_report(commodity="gold", groq_client=None):
|
|
| 120 |
collector = DataCollector(commodity=commodity)
|
| 121 |
analyzer = SentimentAnalyzer(commodity=commodity, groq_client=groq_client)
|
| 122 |
price_data = collector.fetch_price()
|
|
|
|
| 123 |
data = collector.collect_all(groq_client=groq_client)
|
| 124 |
result = analyzer.run_full_analysis(data["articles"])
|
| 125 |
|
|
@@ -140,6 +141,27 @@ def generate_report(commodity="gold", groq_client=None):
|
|
| 140 |
arrow = "π’" if chg >= 0 else "π΄"
|
| 141 |
price_line += f" {arrow} {sign}{escape_md2(f'{chg:.2f}')} \\({sign}{escape_md2(f'{pct:.2f}')}%\\)"
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
bias_emoji = {"Strong Buy": "π’π’", "Buy": "π’", "Neutral": "π‘", "Sell": "π΄", "Strong Sell": "π΄π΄"}
|
| 144 |
bias_key = f"final_{sk}_bias"
|
| 145 |
score_key = f"{sk}_sentiment_score"
|
|
@@ -162,7 +184,7 @@ def generate_report(commodity="gold", groq_client=None):
|
|
| 162 |
dxy_line = f"π± *MYR:* {escape_md2(meta.get('myr_bias', 'Neutral'))}"
|
| 163 |
supply_score = meta.get("supply_score", 0)
|
| 164 |
supply_label = "Tight" if supply_score > 0 else "Oversupply" if supply_score < 0 else "Balanced"
|
| 165 |
-
supply_line = f"π΄ *Supply:* {escape_md2(supply_label)} \\({supply_score}\\)"
|
| 166 |
contrarian_line = ""
|
| 167 |
else:
|
| 168 |
dxy_line = f"π΅ *DXY:* {escape_md2(a3['dxy_directional_bias'])}"
|
|
@@ -176,7 +198,7 @@ def generate_report(commodity="gold", groq_client=None):
|
|
| 176 |
report = f"""*{escape_md2(cfg['display_name'])} Sentiment Report*
|
| 177 |
π
{escape_md2(datetime.now(MYT).strftime('%d %b %Y, %H:%M'))} MYT
|
| 178 |
|
| 179 |
-
{price_line}
|
| 180 |
|
| 181 |
*βββ SIGNAL βββ*
|
| 182 |
{be} *{escape_md2(fs[bias_key])}*
|
|
@@ -202,6 +224,8 @@ def generate_report(commodity="gold", groq_client=None):
|
|
| 202 |
|
| 203 |
_Data: Groq AI \\+ VADER \\| {meta['articles_analyzed']} articles_"""
|
| 204 |
|
|
|
|
|
|
|
| 205 |
|
| 206 |
async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 207 |
chat_id = str(update.effective_chat.id)
|
|
|
|
| 120 |
collector = DataCollector(commodity=commodity)
|
| 121 |
analyzer = SentimentAnalyzer(commodity=commodity, groq_client=groq_client)
|
| 122 |
price_data = collector.fetch_price()
|
| 123 |
+
market_data = collector.fcpo_market_data() if commodity == "fcpo" else None
|
| 124 |
data = collector.collect_all(groq_client=groq_client)
|
| 125 |
result = analyzer.run_full_analysis(data["articles"])
|
| 126 |
|
|
|
|
| 141 |
arrow = "π’" if chg >= 0 else "π΄"
|
| 142 |
price_line += f" {arrow} {sign}{escape_md2(f'{chg:.2f}')} \\({sign}{escape_md2(f'{pct:.2f}')}%\\)"
|
| 143 |
|
| 144 |
+
market_data_lines = ""
|
| 145 |
+
if commodity == "fcpo" and market_data:
|
| 146 |
+
md = market_data
|
| 147 |
+
vol_str = md.get("volume_display") or "β"
|
| 148 |
+
vol_line = f"π *Volume:* {escape_md2(str(vol_str))} lots"
|
| 149 |
+
ohlc_parts = []
|
| 150 |
+
if md.get("open"):
|
| 151 |
+
open_fmt = f'{md["open"]:,.2f}'
|
| 152 |
+
ohlc_parts.append(f"Open: {currency}{escape_md2(open_fmt)}")
|
| 153 |
+
if md.get("high"):
|
| 154 |
+
high_fmt = f'{md["high"]:,.2f}'
|
| 155 |
+
ohlc_parts.append(f"High: {currency}{escape_md2(high_fmt)}")
|
| 156 |
+
if md.get("low"):
|
| 157 |
+
low_fmt = f'{md["low"]:,.2f}'
|
| 158 |
+
ohlc_parts.append(f"Low: {currency}{escape_md2(low_fmt)}")
|
| 159 |
+
if md.get("prev_close"):
|
| 160 |
+
close_fmt = f'{md["prev_close"]:,.2f}'
|
| 161 |
+
ohlc_parts.append(f"Close: {currency}{escape_md2(close_fmt)}")
|
| 162 |
+
if ohlc_parts:
|
| 163 |
+
market_data_lines = f"\n\n*βββ MARKET DATA βββ*\n{vol_line}\nπ {' | '.join(ohlc_parts)}"
|
| 164 |
+
|
| 165 |
bias_emoji = {"Strong Buy": "π’π’", "Buy": "π’", "Neutral": "π‘", "Sell": "π΄", "Strong Sell": "π΄π΄"}
|
| 166 |
bias_key = f"final_{sk}_bias"
|
| 167 |
score_key = f"{sk}_sentiment_score"
|
|
|
|
| 184 |
dxy_line = f"π± *MYR:* {escape_md2(meta.get('myr_bias', 'Neutral'))}"
|
| 185 |
supply_score = meta.get("supply_score", 0)
|
| 186 |
supply_label = "Tight" if supply_score > 0 else "Oversupply" if supply_score < 0 else "Balanced"
|
| 187 |
+
supply_line = f"\nπ΄ *Supply:* {escape_md2(supply_label)} \\({supply_score}\\)"
|
| 188 |
contrarian_line = ""
|
| 189 |
else:
|
| 190 |
dxy_line = f"π΅ *DXY:* {escape_md2(a3['dxy_directional_bias'])}"
|
|
|
|
| 198 |
report = f"""*{escape_md2(cfg['display_name'])} Sentiment Report*
|
| 199 |
π
{escape_md2(datetime.now(MYT).strftime('%d %b %Y, %H:%M'))} MYT
|
| 200 |
|
| 201 |
+
{price_line}{market_data_lines}
|
| 202 |
|
| 203 |
*βββ SIGNAL βββ*
|
| 204 |
{be} *{escape_md2(fs[bias_key])}*
|
|
|
|
| 224 |
|
| 225 |
_Data: Groq AI \\+ VADER \\| {meta['articles_analyzed']} articles_"""
|
| 226 |
|
| 227 |
+
return report
|
| 228 |
+
|
| 229 |
|
| 230 |
async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
| 231 |
chat_id = str(update.effective_chat.id)
|
collector.py
CHANGED
|
@@ -4,6 +4,12 @@ from datetime import datetime, timezone
|
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
from config import COMMODITY_CONFIGS
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
class DataCollector:
|
| 9 |
def __init__(self, commodity="gold"):
|
|
@@ -43,7 +49,23 @@ class DataCollector:
|
|
| 43 |
if price and prev:
|
| 44 |
change = price - prev
|
| 45 |
change_pct = (change / prev) * 100
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
except Exception:
|
| 48 |
pass
|
| 49 |
|
|
@@ -51,9 +73,121 @@ class DataCollector:
|
|
| 51 |
return self._fetch_fcpo_price()
|
| 52 |
return None
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def _fetch_fcpo_price(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
try:
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if resp.status_code != 200:
|
| 58 |
return None
|
| 59 |
soup = BeautifulSoup(resp.text, "html.parser")
|
|
@@ -75,6 +209,11 @@ class DataCollector:
|
|
| 75 |
except Exception:
|
| 76 |
return None
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def fetch_rss(self, feed_urls=None):
|
| 79 |
if feed_urls is None:
|
| 80 |
feed_urls = list(dict.fromkeys(self.config["rss_feeds"] + self.config["news_feeds"]))
|
|
|
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
from config import COMMODITY_CONFIGS
|
| 6 |
|
| 7 |
+
try:
|
| 8 |
+
import cloudscraper
|
| 9 |
+
_HAS_CLOUDSCRAPER = True
|
| 10 |
+
except ImportError:
|
| 11 |
+
_HAS_CLOUDSCRAPER = False
|
| 12 |
+
|
| 13 |
|
| 14 |
class DataCollector:
|
| 15 |
def __init__(self, commodity="gold"):
|
|
|
|
| 49 |
if price and prev:
|
| 50 |
change = price - prev
|
| 51 |
change_pct = (change / prev) * 100
|
| 52 |
+
volume = meta.get("regularMarketVolume")
|
| 53 |
+
open_ = meta.get("regularMarketOpen")
|
| 54 |
+
high = meta.get("regularMarketDayHigh")
|
| 55 |
+
low = meta.get("regularMarketDayLow")
|
| 56 |
+
result = {"price": round(price, 2), "change": round(change, 2), "change_pct": round(change_pct, 2), "source": "yahoo", "currency": currency}
|
| 57 |
+
if open_:
|
| 58 |
+
result["open"] = round(open_, 2)
|
| 59 |
+
if high:
|
| 60 |
+
result["high"] = round(high, 2)
|
| 61 |
+
if low:
|
| 62 |
+
result["low"] = round(low, 2)
|
| 63 |
+
if prev:
|
| 64 |
+
result["prev_close"] = round(prev, 2)
|
| 65 |
+
if volume is not None:
|
| 66 |
+
result["volume"] = volume
|
| 67 |
+
result["volume_display"] = f"{volume:,}" if isinstance(volume, int) else str(volume)
|
| 68 |
+
return result
|
| 69 |
except Exception:
|
| 70 |
pass
|
| 71 |
|
|
|
|
| 73 |
return self._fetch_fcpo_price()
|
| 74 |
return None
|
| 75 |
|
| 76 |
+
def _fetch_fcpo_market_data(self):
|
| 77 |
+
try:
|
| 78 |
+
if _HAS_CLOUDSCRAPER:
|
| 79 |
+
scraper = cloudscraper.create_scraper()
|
| 80 |
+
resp = scraper.get("https://www.investing.com/commodities/palm-oil", timeout=20)
|
| 81 |
+
else:
|
| 82 |
+
resp = self.session.get("https://www.investing.com/commodities/palm-oil", timeout=15)
|
| 83 |
+
if resp.status_code != 200:
|
| 84 |
+
return None
|
| 85 |
+
soup = BeautifulSoup(resp.text, "html.parser")
|
| 86 |
+
|
| 87 |
+
def _val(test_id):
|
| 88 |
+
el = soup.select_one(f'[data-test="{test_id}"]')
|
| 89 |
+
if not el:
|
| 90 |
+
return None
|
| 91 |
+
txt = el.text.strip().replace(",", "").replace("%", "").strip()
|
| 92 |
+
try:
|
| 93 |
+
return float(txt)
|
| 94 |
+
except ValueError:
|
| 95 |
+
return txt if txt else None
|
| 96 |
+
|
| 97 |
+
price = _val("instrument-price-last")
|
| 98 |
+
if price is None:
|
| 99 |
+
return None
|
| 100 |
+
if isinstance(price, float):
|
| 101 |
+
price = round(price, 2)
|
| 102 |
+
|
| 103 |
+
prev = _val("prevClose")
|
| 104 |
+
open_ = _val("open")
|
| 105 |
+
daily_range = _val("dailyRange")
|
| 106 |
+
weekly_range = _val("weekRange")
|
| 107 |
+
volume = _val("volume")
|
| 108 |
+
settlement_type = _val("settlement_type")
|
| 109 |
+
contract_size = _val("contract_size")
|
| 110 |
+
point_value = _val("point_value")
|
| 111 |
+
tick_size = _val("tick_size")
|
| 112 |
+
tick_value = _val("tick_value")
|
| 113 |
+
|
| 114 |
+
def _safe_float(v, default=None):
|
| 115 |
+
if v is None:
|
| 116 |
+
return default
|
| 117 |
+
try:
|
| 118 |
+
return float(v)
|
| 119 |
+
except (ValueError, TypeError):
|
| 120 |
+
return default
|
| 121 |
+
|
| 122 |
+
prev_f = _safe_float(prev, price)
|
| 123 |
+
change = round(_safe_float(price, 0) - prev_f, 2) if isinstance(price, (int, float)) else 0
|
| 124 |
+
change_pct = round((change / prev_f) * 100, 2) if prev_f else 0
|
| 125 |
+
|
| 126 |
+
high = None
|
| 127 |
+
low = None
|
| 128 |
+
if daily_range and isinstance(daily_range, str) and "-" in daily_range:
|
| 129 |
+
parts = daily_range.split("-")
|
| 130 |
+
try:
|
| 131 |
+
low = float(parts[0].strip().replace(",", ""))
|
| 132 |
+
high = float(parts[1].strip().replace(",", ""))
|
| 133 |
+
except (ValueError, IndexError):
|
| 134 |
+
pass
|
| 135 |
+
|
| 136 |
+
volume_display = volume
|
| 137 |
+
if isinstance(volume, (int, float)):
|
| 138 |
+
volume_display = f"{int(volume):,}"
|
| 139 |
+
elif isinstance(volume, str):
|
| 140 |
+
volume_display = volume
|
| 141 |
+
else:
|
| 142 |
+
volume_display = None
|
| 143 |
+
|
| 144 |
+
return {
|
| 145 |
+
"price": _safe_float(price, 0),
|
| 146 |
+
"open": _safe_float(open_),
|
| 147 |
+
"high": high,
|
| 148 |
+
"low": low,
|
| 149 |
+
"prev_close": prev_f,
|
| 150 |
+
"change": change,
|
| 151 |
+
"change_pct": change_pct,
|
| 152 |
+
"volume": _safe_float(volume),
|
| 153 |
+
"volume_display": volume_display,
|
| 154 |
+
"day_range": str(daily_range) if daily_range else None,
|
| 155 |
+
"week_range_52": str(weekly_range) if weekly_range else None,
|
| 156 |
+
"settlement_type": str(settlement_type) if settlement_type else None,
|
| 157 |
+
"contract_size": str(contract_size) if contract_size else None,
|
| 158 |
+
"point_value": str(point_value) if point_value else None,
|
| 159 |
+
"tick_size": str(tick_size) if tick_size else None,
|
| 160 |
+
"source": "investing.com",
|
| 161 |
+
"currency": "RM",
|
| 162 |
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
| 163 |
+
}
|
| 164 |
+
except Exception:
|
| 165 |
+
return None
|
| 166 |
+
|
| 167 |
def _fetch_fcpo_price(self):
|
| 168 |
+
result = self._fetch_fcpo_market_data()
|
| 169 |
+
if result and result.get("price"):
|
| 170 |
+
return {
|
| 171 |
+
"price": result["price"],
|
| 172 |
+
"change": result.get("change"),
|
| 173 |
+
"change_pct": result.get("change_pct"),
|
| 174 |
+
"source": result.get("source", "investing.com"),
|
| 175 |
+
"currency": result.get("currency", "RM"),
|
| 176 |
+
"open": result.get("open"),
|
| 177 |
+
"high": result.get("high"),
|
| 178 |
+
"low": result.get("low"),
|
| 179 |
+
"prev_close": result.get("prev_close"),
|
| 180 |
+
"volume": result.get("volume"),
|
| 181 |
+
"volume_display": result.get("volume_display"),
|
| 182 |
+
"day_range": result.get("day_range"),
|
| 183 |
+
"week_range_52": result.get("week_range_52"),
|
| 184 |
+
}
|
| 185 |
try:
|
| 186 |
+
if _HAS_CLOUDSCRAPER:
|
| 187 |
+
scraper = cloudscraper.create_scraper()
|
| 188 |
+
resp = scraper.get("https://www.investing.com/commodities/palm-oil", timeout=20)
|
| 189 |
+
else:
|
| 190 |
+
resp = self.session.get("https://www.investing.com/commodities/palm-oil", timeout=15)
|
| 191 |
if resp.status_code != 200:
|
| 192 |
return None
|
| 193 |
soup = BeautifulSoup(resp.text, "html.parser")
|
|
|
|
| 209 |
except Exception:
|
| 210 |
return None
|
| 211 |
|
| 212 |
+
def fcpo_market_data(self):
|
| 213 |
+
if self.commodity != "fcpo":
|
| 214 |
+
return None
|
| 215 |
+
return self._fetch_fcpo_market_data()
|
| 216 |
+
|
| 217 |
def fetch_rss(self, feed_urls=None):
|
| 218 |
if feed_urls is None:
|
| 219 |
feed_urls = list(dict.fromkeys(self.config["rss_feeds"] + self.config["news_feeds"]))
|
dashboard.py
CHANGED
|
@@ -52,6 +52,7 @@ def fetch_and_analyze(commodity="gold"):
|
|
| 52 |
collector = DataCollector(commodity=commodity)
|
| 53 |
analyzer = SentimentAnalyzer(commodity=commodity, groq_client=groq_client)
|
| 54 |
price_data = collector.fetch_price()
|
|
|
|
| 55 |
data = collector.collect_all(groq_client=groq_client)
|
| 56 |
result = analyzer.run_full_analysis(data["articles"])
|
| 57 |
result["collection_meta"] = {
|
|
@@ -61,7 +62,7 @@ def fetch_and_analyze(commodity="gold"):
|
|
| 61 |
"timestamp": data["timestamp"],
|
| 62 |
"price_label": cfg["price_label"],
|
| 63 |
}
|
| 64 |
-
return result, data, price_data
|
| 65 |
|
| 66 |
|
| 67 |
def render_gauge(score, title, min_val=-100, max_val=100):
|
|
@@ -361,7 +362,7 @@ def main():
|
|
| 361 |
st.cache_data.clear()
|
| 362 |
st.rerun()
|
| 363 |
|
| 364 |
-
result, data, price_data = fetch_and_analyze(commodity)
|
| 365 |
|
| 366 |
a1 = result["analysis_1_macro"]
|
| 367 |
a2 = result["analysis_2_sentiment"]
|
|
@@ -436,6 +437,47 @@ def main():
|
|
| 436 |
ca_dc = "#FF9F0A" if a2["contrarian_signal"] == "YES" else "#30D158"
|
| 437 |
st.markdown(metric_card("Contrarian Alert", a2["contrarian_signal"], ca_delta, ca_dc), unsafe_allow_html=True)
|
| 438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
st.markdown("<div style='border-top: 1px solid rgba(255,255,255,0.06); margin: 28px 0;'></div>", unsafe_allow_html=True)
|
| 440 |
|
| 441 |
col_gauge, col_bar, col_timeline = st.columns([1, 1, 1.5])
|
|
|
|
| 52 |
collector = DataCollector(commodity=commodity)
|
| 53 |
analyzer = SentimentAnalyzer(commodity=commodity, groq_client=groq_client)
|
| 54 |
price_data = collector.fetch_price()
|
| 55 |
+
market_data = collector.fcpo_market_data() if commodity == "fcpo" else None
|
| 56 |
data = collector.collect_all(groq_client=groq_client)
|
| 57 |
result = analyzer.run_full_analysis(data["articles"])
|
| 58 |
result["collection_meta"] = {
|
|
|
|
| 62 |
"timestamp": data["timestamp"],
|
| 63 |
"price_label": cfg["price_label"],
|
| 64 |
}
|
| 65 |
+
return result, data, price_data, market_data
|
| 66 |
|
| 67 |
|
| 68 |
def render_gauge(score, title, min_val=-100, max_val=100):
|
|
|
|
| 362 |
st.cache_data.clear()
|
| 363 |
st.rerun()
|
| 364 |
|
| 365 |
+
result, data, price_data, market_data = fetch_and_analyze(commodity)
|
| 366 |
|
| 367 |
a1 = result["analysis_1_macro"]
|
| 368 |
a2 = result["analysis_2_sentiment"]
|
|
|
|
| 437 |
ca_dc = "#FF9F0A" if a2["contrarian_signal"] == "YES" else "#30D158"
|
| 438 |
st.markdown(metric_card("Contrarian Alert", a2["contrarian_signal"], ca_delta, ca_dc), unsafe_allow_html=True)
|
| 439 |
|
| 440 |
+
if commodity == "fcpo" and market_data:
|
| 441 |
+
md = market_data
|
| 442 |
+
currency = cfg.get("currency", "RM")
|
| 443 |
+
|
| 444 |
+
vol_display = md.get("volume_display") or "β"
|
| 445 |
+
vol_raw = md.get("volume")
|
| 446 |
+
vol_delta = f"{int(vol_raw):,} lots" if isinstance(vol_raw, (int, float)) and vol_raw else ""
|
| 447 |
+
|
| 448 |
+
open_str = f"{currency}{md['open']:,.2f}" if md.get("open") else "β"
|
| 449 |
+
high_str = f"{currency}{md['high']:,.2f}" if md.get("high") else "β"
|
| 450 |
+
low_str = f"{currency}{md['low']:,.2f}" if md.get("low") else "β"
|
| 451 |
+
prev_str = f"{currency}{md['prev_close']:,.2f}" if md.get("prev_close") else "β"
|
| 452 |
+
day_range_str = md.get("day_range") or "β"
|
| 453 |
+
week_range_str = md.get("week_range_52") or "β"
|
| 454 |
+
settlement = md.get("settlement_type") or "Physical"
|
| 455 |
+
contract = md.get("contract_size") or "25 MT"
|
| 456 |
+
point_val = md.get("point_value") or ""
|
| 457 |
+
|
| 458 |
+
st.markdown(f'''<div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:12px;margin-top:4px;">Market Data β Last Session</div>''', unsafe_allow_html=True)
|
| 459 |
+
|
| 460 |
+
mc1, mc2, mc3, mc4, mc5 = st.columns(5)
|
| 461 |
+
with mc1:
|
| 462 |
+
st.markdown(metric_card("Volume", vol_display, vol_delta, "#0A84FF"), unsafe_allow_html=True)
|
| 463 |
+
with mc2:
|
| 464 |
+
st.markdown(metric_card("Open", open_str, None), unsafe_allow_html=True)
|
| 465 |
+
with mc3:
|
| 466 |
+
st.markdown(metric_card("High", high_str, None, "#30D158"), unsafe_allow_html=True)
|
| 467 |
+
with mc4:
|
| 468 |
+
st.markdown(metric_card("Low", low_str, None, "#FF453A"), unsafe_allow_html=True)
|
| 469 |
+
with mc5:
|
| 470 |
+
st.markdown(metric_card("Prev Close", prev_str, None), unsafe_allow_html=True)
|
| 471 |
+
|
| 472 |
+
contract_info = f"Settlement: {settlement} | Contract: {contract}"
|
| 473 |
+
if point_val:
|
| 474 |
+
contract_info += f" | Point: {point_val}"
|
| 475 |
+
st.markdown(f'''<div style="display:flex;justify-content:space-between;color:#6E6E73;font-size:11px;font-family:{APPLE_FONT};margin-top:2px;margin-bottom:20px;flex-wrap:wrap;gap:8px;">
|
| 476 |
+
<span>Day Range: {day_range_str}</span>
|
| 477 |
+
<span>52W Range: {week_range_str}</span>
|
| 478 |
+
<span>{contract_info}</span>
|
| 479 |
+
</div>''', unsafe_allow_html=True)
|
| 480 |
+
|
| 481 |
st.markdown("<div style='border-top: 1px solid rgba(255,255,255,0.06); margin: 28px 0;'></div>", unsafe_allow_html=True)
|
| 482 |
|
| 483 |
col_gauge, col_bar, col_timeline = st.columns([1, 1, 1.5])
|
requirements.txt
CHANGED
|
@@ -8,4 +8,5 @@ streamlit>=1.35
|
|
| 8 |
streamlit-autorefresh>=1.0
|
| 9 |
python-telegram-bot>=21.0
|
| 10 |
apscheduler>=3.10
|
| 11 |
-
groq>=0.20
|
|
|
|
|
|
| 8 |
streamlit-autorefresh>=1.0
|
| 9 |
python-telegram-bot>=21.0
|
| 10 |
apscheduler>=3.10
|
| 11 |
+
groq>=0.20
|
| 12 |
+
cloudscraper>=1.2
|