-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifier.py
More file actions
482 lines (430 loc) · 22.5 KB
/
Copy pathnotifier.py
File metadata and controls
482 lines (430 loc) · 22.5 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
"""
notifier.py - Telegram notification untuk sinyal trading
"""
import requests
import logging
import time
from datetime import datetime
from typing import Optional
from collections import deque
from config import (
TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID,
NOTIFY_ON_SIGNAL, NOTIFY_ON_ERROR, MAX_SIGNALS_PER_HOUR
)
from monte_carlo import SimulationResult
logger = logging.getLogger(__name__)
class TelegramNotifier:
"""Kirim notifikasi trading signal ke Telegram."""
BASE_URL = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}"
def __init__(self):
self._signal_timestamps = deque() # Throttle tracker
def send_signal(self, result: SimulationResult, chart_path: str = None) -> bool:
"""
Kirim notifikasi sinyal trading ke Telegram.
Format mirip dashboard MiroFish dengan info lengkap.
"""
if not NOTIFY_ON_SIGNAL:
return False
if not self._check_rate_limit():
logger.warning("Rate limit reached, skipping notification")
return False
emoji_dir = "🟢 LONG" if result.direction == 'LONG' else "🔴 SHORT"
conf_bar = self._confidence_bar(result.confidence)
conf_pct = f"{result.confidence * 100:.1f}%"
win_pct = f"{result.win_probability * 100:.1f}%"
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
# Format harga dengan presisi yang tepat
price_fmt = self._format_price(result.entry_price)
tp_fmt = self._format_price(result.take_profit)
sl_fmt = self._format_price(result.stop_loss)
message = (
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"⚡ *NERA QUANT SIGNAL*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *{result.symbol}* | {emoji_dir}\n\n"
f"🎯 *Confidence:* {conf_pct}\n"
f"{conf_bar}\n\n"
f"📈 *Win Probability:* {win_pct}\n"
f"🔢 *Simulations:* {result.simulations_run:,} paths\n"
f"✅ *Profitable Paths:* {result.profitable_paths:,}\n\n"
f"💰 *Entry:* `{price_fmt}`\n"
f"🎯 *Take Profit:* `{tp_fmt}`\n"
f"🛑 *Stop Loss:* `{sl_fmt}`\n"
f"⚖️ *Risk/Reward:* 1:{result.risk_reward:.2f}\n\n"
f"📉 *Expected Return:* {result.expected_return:+.2f}%\n"
f"🔍 *Signal Score:* {result.signal_score * 100:.1f}/100\n\n"
f"🕐 `{timestamp}`\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"⚠️ _DYOR. Bukan financial advice._"
)
if chart_path:
return self._send_photo(chart_path, message)
return self._send_message(message)
def send_trade_executed(self, signal, trade, chart_path: str = None, debate: dict = None) -> bool:
"""
Kirim notifikasi setelah order berhasil dieksekusi.
Tampilkan detail order: leverage, quantity, margin, TP/SL order ID + AI reasoning.
"""
if not NOTIFY_ON_SIGNAL:
return False
if not self._check_rate_limit():
return False
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
if trade.success:
emoji_dir = "🟢 LONG" if trade.direction == 'LONG' else "🔴 SHORT"
conf_pct = f"{signal.confidence * 100:.1f}%"
conf_bar = self._confidence_bar(signal.confidence)
# ── AI Reasoning block ────────────────────────────────────
ai_block = ""
if debate and debate.get('verdict'):
verdict = debate['verdict']
bull_strength = debate.get('bull_strength', '')
bear_strength = debate.get('bear_strength', '')
verdict_emoji = "✅" if verdict == 'APPROVE' else "❌"
# Ambil kalimat pertama dari masing-masing reasoning (max 120 char)
bull_text = (debate.get('bull', '') or '').split('\n')[0].strip()
bear_text = (debate.get('bear', '') or '').split('\n')[0].strip()
ai_block = (
f"\n🤖 *AI CIO Reasoning:*\n"
f"{verdict_emoji} *Verdict:* `{verdict}` "
f"(Bull: `{bull_strength}` | Bear: `{bear_strength}`)\n"
f"🟢 _{bull_text}_\n"
f"🔴 _{bear_text}_\n"
)
message = (
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"✅ *ORDER EXECUTED*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *{trade.symbol}* | {emoji_dir}\n\n"
f"🎯 *Confidence:* {conf_pct}\n"
f"{conf_bar}\n\n"
f"⚙️ *Leverage:* {trade.leverage_used}x (Isolated)\n"
f"📦 *Quantity:* `{trade.quantity}`\n"
f"💵 *Margin Used:* `{trade.margin_used:.2f} USDT`\n\n"
f"💰 *Entry:* `{self._format_price(trade.entry_price)}`\n"
f"🎯 *Take Profit:* `{self._format_price(trade.take_profit)}`\n"
f"🛑 *Stop Loss:* `{self._format_price(trade.stop_loss)}`\n"
f"⚖️ *Risk/Reward:* 1:{signal.risk_reward:.2f}\n\n"
f"🔖 *Order ID:* `{trade.order_id}`\n"
f"🔖 *TP Order:* `{trade.tp_order_id}`\n"
f"🔖 *SL Order:* `{trade.sl_order_id}`\n"
f"{ai_block}\n"
f"🕐 `{timestamp}`\n"
f"━━━━━━━━━━━━━━━━━━━━━━"
)
if chart_path:
return self._send_photo(chart_path, message)
return self._send_message(message)
else:
# Order gagal — log saja, tidak perlu notif Telegram
logger.warning(f"Order failed [{trade.symbol}]: {trade.error_msg}")
return False
def send_scan_summary(self, total_pairs: int, signals_found: int, top_signals: list) -> bool:
"""Kirim ringkasan hasil scan ke Telegram."""
timestamp = datetime.utcnow().strftime('%H:%M UTC')
lines = [
f"🔍 *SCAN SELESAI* | {timestamp}",
f"━━━━━━━━━━━━━━━━━━━━━━",
f"📊 Pairs dianalisis: *{total_pairs}*",
f"⚡ Sinyal ditemukan: *{signals_found}*",
]
if top_signals:
lines.append("\n🏆 *Top Signals:*")
for i, sig in enumerate(top_signals[:5], 1):
dir_emoji = "🟢" if sig.direction == 'LONG' else "🔴"
lines.append(
f"{i}. {dir_emoji} *{sig.symbol}* — "
f"conf: {sig.confidence*100:.1f}% | "
f"win: {sig.win_probability*100:.1f}%"
)
if not top_signals:
lines.append("\n😴 Tidak ada sinyal kuat saat ini.")
return self._send_message('\n'.join(lines))
def send_error(self, error_msg: str) -> bool:
"""Kirim notifikasi error."""
if not NOTIFY_ON_ERROR:
return False
message = f"⚠️ *NERA QUANT ERROR*\n\n`{error_msg}`"
return self._send_message(message)
def send_startup(self) -> bool:
"""Kirim notifikasi bot startup."""
from config import AUTO_TRADE, LEVERAGE, MARGIN_TYPE, MAX_OPEN_POSITIONS
trade_mode = "🤖 AUTO TRADE ON" if AUTO_TRADE else "👁 Signal Only Mode"
message = (
f"🚀 *NERA QUANT STARTED*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"✅ Bot aktif dan scanning...\n"
f"📊 Monitoring top 50 Binance pairs\n"
f"🎲 Monte Carlo: 5,000 simulations/pair\n"
f"⏱ Scan interval: 60 detik\n"
f"⚙️ Mode: *{trade_mode}*\n"
f"📐 Leverage: up to *{LEVERAGE}x* (auto-cap per pair)\n"
f"🔒 Margin: *{MARGIN_TYPE}*\n"
f"📂 Max posisi: *{MAX_OPEN_POSITIONS}*\n"
f"━━━━━━━━━━━━━━━━━━━━━━"
)
return self._send_message(message)
def send_partial_tp_executed(
self, symbol: str, direction: str, qty: float, price: float, remaining_qty: float
) -> bool:
"""Kirim notifikasi Partial Take Profit & Breakeven ke Telegram."""
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
emoji_dir = "🟢 LONG" if direction == 'LONG' else "🔴 SHORT"
price_fmt = self._format_price(price)
message = (
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"💥 *PARTIAL TAKE PROFIT (TP1)*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *{symbol}* | {emoji_dir}\n\n"
f"✅ *Status:* TP1 Hit! 50% Posisi Ditutup.\n"
f"💵 *Harga Exit TP1:* `{price_fmt}`\n"
f"📦 *Qty Terjual:* `{qty}`\n"
f"📦 *Sisa Qty:* `{remaining_qty}`\n\n"
f"🔒 *Stop Loss baru:* Disesuaikan ke *ENTRY (Breakeven)*! (Free Trade)\n\n"
f"🕐 `{timestamp}`\n"
f"━━━━━━━━━━━━━━━━━━━━━━"
)
return self._send_message(message)
def send_early_close_executed(
self, symbol: str, direction: str, price: float, pnl: float, confidence: float, win_prob: float
) -> bool:
"""Kirim notifikasi Early Close karena penurunan probabilitas."""
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
emoji_dir = "🟢 LONG" if direction == 'LONG' else "🔴 SHORT"
price_fmt = self._format_price(price)
pnl_emoji = "🟢" if pnl >= 0 else "🔴"
conf_bar = self._confidence_bar(confidence)
message = (
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"⚠️ *DYNAMIC EARLY EXIT*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *{symbol}* | {emoji_dir}\n\n"
f"🛑 *Status:* Ditutup Lebih Awal (Early Close)\n"
f"🎯 *Confidence Terkini:* `{confidence*100:.1f}%`\n"
f"{conf_bar}\n"
f"📈 *Win Probability:* `{win_prob*100:.1f}%`\n\n"
f"💵 *Harga Exit:* `{price_fmt}`\n"
f"{pnl_emoji} *Estimasi PnL:* `{pnl:+.2f}%`\n\n"
f"🔍 *Alasan:* Monte Carlo mendeteksi setup trade melemah di bawah batas aman. Posisi dilikuidasi demi keamanan modal.\n\n"
f"🕐 `{timestamp}`\n"
f"━━━━━━━━━━━━━━━━━━━━━━"
)
return self._send_message(message)
def send_pending_setup_created(self, signal, trigger_price: float, invalidation_price: float, chart_path: str = None) -> bool:
"""Kirim notifikasi bahwa Setup Pending SMC berhasil dipasang."""
if not NOTIFY_ON_SIGNAL:
return False
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
emoji_dir = "🟢 PENDING LONG" if signal.direction == 'LONG' else "🔴 PENDING SHORT"
conf_pct = f"{signal.confidence * 100:.1f}%"
conf_bar = self._confidence_bar(signal.confidence)
message = (
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"⏳ *SMC PENDING SETUP PLACED*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *{signal.symbol}* | {emoji_dir}\n\n"
f"🎯 *Confidence:* {conf_pct}\n"
f"{conf_bar}\n\n"
f"📥 *Entry Trigger:* `{self._format_price(trigger_price)}` (Pullback OB)\n"
f"🛑 *Batas Invalidation:* `{self._format_price(invalidation_price)}` (OB Break)\n"
f"🎯 *Target Profit (TP):* `{self._format_price(signal.take_profit)}`\n"
f"⚖️ *Risk/Reward:* 1:{signal.risk_reward:.2f}\n\n"
f"🔍 *Alasan:* Sinyal SMC sangat kuat, bot menunggu harga retrace/diskon ke zona Order Block untuk efisiensi R/R.\n\n"
f"🕐 `{timestamp}`\n"
f"━━━━━━━━━━━━━━━━━━━━━━"
)
if chart_path:
return self._send_photo(chart_path, message)
return self._send_message(message)
def send_pending_setup_triggered(self, signal, trade, chart_path: str = None, debate: dict = None) -> bool:
"""Kirim notifikasi bahwa Setup Pending berhasil terpicu & terisi."""
if not NOTIFY_ON_SIGNAL:
return False
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
if trade.success:
emoji_dir = "🟢 LONG (OB Retest)" if trade.direction == 'LONG' else "🔴 SHORT (OB Retest)"
conf_pct = f"{signal.confidence * 100:.1f}%"
conf_bar = self._confidence_bar(signal.confidence)
# ── AI Reasoning block ────────────────────────────────────
ai_block = ""
if debate and debate.get('verdict'):
verdict = debate['verdict']
bull_strength = debate.get('bull_strength', '')
bear_strength = debate.get('bear_strength', '')
verdict_emoji = "✅" if verdict == 'APPROVE' else "❌"
bull_text = (debate.get('bull', '') or '').split('\n')[0].strip()
bear_text = (debate.get('bear', '') or '').split('\n')[0].strip()
ai_block = (
f"\n🤖 *AI CIO Reasoning:*\n"
f"{verdict_emoji} *Verdict:* `{verdict}` "
f"(Bull: `{bull_strength}` | Bear: `{bear_strength}`)\n"
f"🟢 _{bull_text}_\n"
f"🔴 _{bear_text}_\n"
)
message = (
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"🔥 *SMC PENDING TRIGGERED & FILLED*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *{trade.symbol}* | {emoji_dir}\n\n"
f"🎯 *Confidence:* {conf_pct}\n"
f"{conf_bar}\n\n"
f"⚙️ *Leverage:* {trade.leverage_used}x (Isolated)\n"
f"📦 *Quantity:* `{trade.quantity}`\n"
f"💵 *Margin Used:* `{trade.margin_used:.2f} USDT`\n\n"
f"💰 *Trigger Entry Price:* `{self._format_price(trade.entry_price)}`\n"
f"🎯 *Take Profit:* `{self._format_price(trade.take_profit)}`\n"
f"🛑 *Stop Loss:* `{self._format_price(trade.stop_loss)}`\n"
f"⚖️ *Risk/Reward:* 1:{signal.risk_reward:.2f}\n\n"
f"🔖 *Order ID:* `{trade.order_id}`\n"
f"🔖 *TP Order:* `{trade.tp_order_id}`\n"
f"🔖 *SL Order:* `{trade.sl_order_id}`\n"
f"{ai_block}\n"
f"🕐 `{timestamp}`\n"
f"━━━━━━━━━━━━━━━━━━━━━━"
)
if chart_path:
return self._send_photo(chart_path, message)
return self._send_message(message)
else:
logger.warning(f"Pending trigger trade failed [{trade.symbol}]: {trade.error_msg}")
return False
def send_pending_setup_invalidated(self, symbol: str, direction: str, price: float, reason: str) -> bool:
"""Kirim notifikasi bahwa Setup Pending dibatalkan (Invalidated)."""
if not NOTIFY_ON_SIGNAL:
return False
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
emoji_dir = "🟢 LONG" if direction == 'LONG' else "🔴 SHORT"
price_fmt = self._format_price(price)
message = (
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"❌ *SMC SETUP INVALIDATED*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *{symbol}* | {emoji_dir}\n\n"
f"⚠️ *Status:* DIBATALKAN (Setup Invalidated)\n"
f"💵 *Harga Saat Ini:* `{price_fmt}`\n\n"
f"🔍 *Alasan:* {reason}\n\n"
f"🕐 `{timestamp}`\n"
f"━━━━━━━━━━━━━━━━━━━━━━"
)
return self._send_message(message)
def send_circuit_breaker_alert(self, reason: str, resume_at: str) -> bool:
"""Kirim alert circuit breaker ke Telegram."""
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
message = (
f"🚨 *PSYCHOLOGICAL CIRCUIT BREAKER*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"⚠️ *Trading Paused!*\n\n"
f"🔍 *Alasan:* {reason}\n"
f"🕐 *Estimasi Resume:* `{resume_at}`\n\n"
f"Sistem menghentikan pembukaan posisi baru demi melindungi modal psikologis & finansial Anda. Posisi yang ada tetap akan dipantau & dikelola."
)
return self._send_message(message)
def send_weekly_performance_report(self, stats: dict) -> bool:
"""Kirim laporan mingguan trading intelligence."""
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
win_rate = stats.get('win_rate', 0.0)
total_pnl = stats.get('total_pnl', 0.0)
total_trades = stats.get('total_trades', 0)
best_pair = stats.get('best_pair', 'N/A')
best_session = stats.get('best_session', 'N/A')
pnl_emoji = "🟢" if total_pnl >= 0 else "🔴"
message = (
f"📊 *NERA QUANT WEEKLY REPORT*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📅 *Timestamp:* `{timestamp}`\n\n"
f"💼 *Total Trades:* `{total_trades}`\n"
f"📈 *Win Rate:* `{win_rate:.2f}%`\n"
f"{pnl_emoji} *Total PnL:* `{total_pnl:+.4f} USDT`\n\n"
f"🏆 *Best Pair:* `{best_pair}`\n"
f"🕒 *Best Session:* `{best_session}`\n\n"
f"Sistem otomatis memperbarui model personality untuk mengoptimalkan dynamic risk. Terus pantau dashboard untuk wawasan mendalam!"
)
return self._send_message(message)
def send_pair_insight(self, symbol: str, personality: dict) -> bool:
"""Kirim alert jika pair personality berubah signifikan."""
timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M UTC')
win_rate = personality.get('win_rate', 0.0)
best_session = personality.get('best_session', 'N/A')
avoid_session = personality.get('avoid_session', 'N/A')
rec_risk = personality.get('recommended_risk_pct', 0.02) * 100
message = (
f"💡 *PAIR INTELLIGENCE INSIGHT*\n"
f"━━━━━━━━━━━━━━━━━━━━━━\n"
f"📊 *Pair:* *{symbol}*\n\n"
f"📈 *Win Rate:* `{win_rate*100:.1f}%` ({personality.get('total_trades')} trades)\n"
f"🕒 *Best Session:* `{best_session}`\n"
f"❌ *Avoid Session:* `{avoid_session}`\n"
f"🛡️ *Recommended Risk:* `{rec_risk:.2f}%` per trade\n\n"
f"Sistem Decision Intelligence telah mendeteksi pergeseran karakteristik pair. Parameter risk engine otomatis disesuaikan."
)
return self._send_message(message)
# ── Private methods ───────────────────────────────────────────────
def _send_photo(self, photo_path: str, caption: str) -> bool:
"""Kirim foto beserta caption ke Telegram."""
import os
if not os.path.exists(photo_path):
return self._send_message(caption)
url = f"{self.BASE_URL}/sendPhoto"
data = {
'chat_id': TELEGRAM_CHAT_ID,
'caption': caption,
'parse_mode': 'Markdown',
}
for attempt in range(3):
try:
with open(photo_path, 'rb') as photo:
files = {'photo': photo}
resp = requests.post(url, data=data, files=files, timeout=15)
if resp.status_code == 200:
self._signal_timestamps.append(time.time())
return True
else:
logger.warning(f"Telegram sendPhoto API error {resp.status_code}: {resp.text}")
except requests.RequestException as e:
logger.error(f"Telegram sendPhoto attempt {attempt+1} failed: {e}")
if attempt < 2:
time.sleep(2)
return False
def _send_message(self, text: str) -> bool:
"""Kirim pesan ke Telegram dengan retry."""
url = f"{self.BASE_URL}/sendMessage"
payload = {
'chat_id': TELEGRAM_CHAT_ID,
'text': text,
'parse_mode': 'Markdown',
}
for attempt in range(3):
try:
resp = requests.post(url, json=payload, timeout=10)
if resp.status_code == 200:
self._signal_timestamps.append(time.time())
return True
else:
logger.warning(f"Telegram API error {resp.status_code}: {resp.text}")
except requests.RequestException as e:
logger.error(f"Telegram send attempt {attempt+1} failed: {e}")
if attempt < 2:
time.sleep(2)
return False
def _check_rate_limit(self) -> bool:
"""Cek apakah masih dalam batas MAX_SIGNALS_PER_HOUR."""
now = time.time()
one_hour_ago = now - 3600
# Hapus timestamps yang sudah lebih dari 1 jam
while self._signal_timestamps and self._signal_timestamps[0] < one_hour_ago:
self._signal_timestamps.popleft()
return len(self._signal_timestamps) < MAX_SIGNALS_PER_HOUR
def _confidence_bar(self, confidence: float) -> str:
"""Buat visual bar untuk confidence level."""
filled = int(confidence * 10)
empty = 10 - filled
bar = '█' * filled + '░' * empty
return f"`[{bar}]`"
def _format_price(self, price: float) -> str:
"""Format harga dengan presisi yang sesuai."""
if price >= 1000:
return f"{price:,.2f}"
elif price >= 1:
return f"{price:.4f}"
else:
return f"{price:.6f}"