@drico2008/fincli 0.1.3 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +909 -684
  3. package/fincli/__init__.py +3 -3
  4. package/fincli/app/agents/__init__.py +5 -0
  5. package/fincli/app/agents/registry.py +76 -0
  6. package/fincli/app/analysis/ai_prompts.py +23 -16
  7. package/fincli/app/analysis/analyzer.py +107 -100
  8. package/fincli/app/analysis/assistant_context.py +187 -160
  9. package/fincli/app/analysis/backtest.py +179 -0
  10. package/fincli/app/analysis/gameplay_plan.py +79 -0
  11. package/fincli/app/analysis/indicators.py +1 -1
  12. package/fincli/app/analysis/market_structure.py +1 -1
  13. package/fincli/app/analysis/multi_timeframe.py +180 -0
  14. package/fincli/app/analysis/trading_methods.py +144 -0
  15. package/fincli/app/cli/commands.py +105 -77
  16. package/fincli/app/cli/router.py +2143 -1121
  17. package/fincli/app/connectors/__init__.py +5 -0
  18. package/fincli/app/connectors/catalog.py +148 -0
  19. package/fincli/app/connectors/news_connectors.py +412 -0
  20. package/fincli/app/modules/alerts.py +80 -0
  21. package/fincli/app/modules/economic_calendar.py +374 -1
  22. package/fincli/app/modules/reports.py +151 -0
  23. package/fincli/app/modules/scanner.py +111 -93
  24. package/fincli/app/modules/session_history.py +113 -0
  25. package/fincli/app/modules/transactions.py +84 -84
  26. package/fincli/app/modules/user_profile.py +84 -0
  27. package/fincli/app/plugins/loader.py +72 -0
  28. package/fincli/app/providers/ai/anthropic_provider.py +8 -7
  29. package/fincli/app/providers/ai/gemini_provider.py +8 -7
  30. package/fincli/app/providers/ai/groq_provider.py +8 -7
  31. package/fincli/app/providers/ai/huggingface_provider.py +8 -7
  32. package/fincli/app/providers/ai/manager.py +60 -60
  33. package/fincli/app/providers/ai/openai_provider.py +8 -7
  34. package/fincli/app/providers/ai/openrouter_provider.py +8 -7
  35. package/fincli/app/providers/ai/together_provider.py +8 -7
  36. package/fincli/app/providers/market/alphavantage_provider.py +194 -0
  37. package/fincli/app/providers/market/base.py +98 -77
  38. package/fincli/app/providers/market/custom_provider.py +186 -169
  39. package/fincli/app/providers/market/manager.py +85 -2
  40. package/fincli/app/providers/market/news_provider.py +4 -4
  41. package/fincli/app/providers/market/symbols.py +143 -0
  42. package/fincli/app/providers/market/twelvedata_provider.py +167 -167
  43. package/fincli/app/providers/market/yfinance_provider.py +1 -1
  44. package/fincli/app/research/__init__.py +7 -0
  45. package/fincli/app/research/engine.py +75 -0
  46. package/fincli/app/research/formatter.py +22 -0
  47. package/fincli/app/research/models.py +18 -0
  48. package/fincli/app/research/prompt_builder.py +47 -0
  49. package/fincli/app/services/macro_data.py +50 -0
  50. package/fincli/app/services/market_data.py +203 -203
  51. package/fincli/app/services/news_aggregator.py +90 -0
  52. package/fincli/app/services/web_research.py +267 -0
  53. package/fincli/app/storage/cache.py +2 -2
  54. package/fincli/app/storage/config.py +122 -88
  55. package/fincli/app/storage/database.py +201 -85
  56. package/fincli/app/storage/secrets.py +12 -3
  57. package/fincli/app/tui/components.py +68 -50
  58. package/fincli/app/tui/layout.py +270 -258
  59. package/fincli/app/tui/market_provider_selector.py +6 -1
  60. package/fincli/app/tui/model_selector.py +11 -3
  61. package/fincli/app/tui/theme.py +134 -74
  62. package/fincli/app/utils/formatting.py +125 -12
  63. package/npm/bin/fincli.js +9 -2
  64. package/package.json +23 -23
  65. package/pyproject.toml +35 -35
package/README.md CHANGED
@@ -1,684 +1,909 @@
1
- # FinCLI v0.1
2
-
3
- FinCLI adalah financial CLI/TUI terminal modern untuk memantau market, mengelola watchlist, portfolio, journal, konfigurasi provider, dan menyiapkan integrasi AI market analysis secara modular.
4
-
5
- Status saat ini: Phase 23 MVP sudah aktif di atas fondasi Phase 1 sampai Phase 22.
6
-
7
- - Textual TUI satu kolom dengan command palette inline yang bisa discroll; sidebar lama sudah dihapus agar output market lebih lega.
8
- - Slash command router dengan command wajib FinCLI v0.1.
9
- - Config system berbasis `.env` untuk secret dan `~/.fincli/config.json` untuk preference non-secret.
10
- - SQLite local storage untuk watchlist, portfolio, dan journal.
11
- - yfinance fallback untuk quote, OHLCV history, news, dan fundamental snapshot.
12
- - Finnhub provider untuk quote, stock candles, company news, dan company profile via `FINNHUB_API_KEY`.
13
- - Twelve Data provider untuk multi-asset market data via `TWELVE_DATA_API_KEY`.
14
- - Economic calendar lewat Finnhub jika API key tersedia, dengan fallback lokal jika provider belum dikonfigurasi.
15
- - Technical analysis dasar: SMA, EMA, RSI, MACD, Bollinger Bands, ATR, support/resistance, volume, trend bias.
16
- - Market structure dasar: HH/HL, LH/LL, break of structure, change of character, liquidity area, risk zone.
17
- - Watchlist scanner: `/scan watchlist` dengan filter `rsi<30`, `rsi>70`, atau `trend=bullish`.
18
- - Persistent SQLite market cache untuk quote, OHLCV history, news, dan fundamental agar provider API tidak dipanggil berulang secara boros.
19
- - `/ai` dan `/analyze` sudah lewat AI provider interface. `/ai` memakai persona FinCLI, guardrail anti-coding, dan market context otomatis jika prompt menyebut symbol eksplisit.
20
- - AI HTTP clients untuk OpenAI-compatible APIs, Gemini, dan Anthropic. OpenRouter, OpenAI, Together, Groq, dan HuggingFace memakai jalur OpenAI-compatible.
21
- - Portfolio view menghitung current price, PnL, dan PnL percent dari quote provider aktif.
22
- - Export portfolio/journal ke CSV atau JSON.
23
- - Basic tests untuk command registry, router, config, storage, market command, technical analysis, dan AI command injection.
24
-
25
- ## Stack
26
-
27
- - Python 3.11+
28
- - Textual + Rich untuk TUI
29
- - SQLite untuk local database
30
- - python-dotenv untuk `.env`
31
- - yfinance untuk fallback market/news/fundamental data
32
- - httpx disiapkan untuk provider API lanjutan
33
- - pytest untuk test
34
-
35
- Textual dipilih karena lebih cocok untuk dashboard terminal interaktif dibanding CLI statis. Rich tetap dipakai untuk table/panel renderable.
36
-
37
- ## Install
38
-
39
- ```bash
40
- python -m venv .venv
41
- .venv\Scripts\activate
42
- pip install -e ".[dev]"
43
- ```
44
-
45
- Alternatif:
46
-
47
- ```bash
48
- pip install -r requirements.txt
49
- ```
50
-
51
- ## Global Install
52
-
53
- Rekomendasi untuk Python CLI adalah `pipx`, karena dependency FinCLI dipasang di environment terisolasi tetapi command `fincli` tersedia global:
54
-
55
- ```bash
56
- pip install pipx
57
- pipx ensurepath
58
- pipx install .
59
- fincli
60
- ```
61
-
62
- Jika sudah dipublish ke PyPI:
63
-
64
- ```bash
65
- pipx install fincli
66
- fincli
67
- ```
68
-
69
- FinCLI juga punya npm wrapper agar bisa mengikuti pola “install once, run anywhere” seperti CLI Node:
70
-
71
- ```bash
72
- npm install -g .
73
- fincli
74
- ```
75
-
76
- Setelah package npm dipublish:
77
-
78
- ```bash
79
- npm install -g @drico2008/fincli
80
- fincli
81
- ```
82
-
83
- Catatan: npm wrapper tetap membutuhkan Python 3.11+ saat install. Script npm akan membuat virtualenv `.npm-python`, menginstall package Python FinCLI ke sana, lalu command global `fincli` menjalankan `python -m fincli.app.main`.
84
-
85
- ## Setup `.env`
86
-
87
- ```bash
88
- copy .env.example .env
89
- ```
90
-
91
- Isi API key hanya untuk provider yang ingin digunakan. yfinance fallback tidak butuh API key. Config membaca status key tanpa menampilkan secret.
92
-
93
- Untuk install global lewat npm, user tidak perlu membuka folder package atau mengedit `.env`. Simpan API key lewat command FinCLI:
94
-
95
- ```text
96
- /ai_model key groq <api_key>
97
- /ai_model key openrouter <api_key>
98
- /news_model key finnhub <api_key>
99
- /news_model key twelvedata <api_key>
100
- /news_model key custom <api_key> https://your-market-api.example.com
101
- ```
102
-
103
- Key disimpan lokal di:
104
-
105
- ```text
106
- ~/.fincli/secrets.env
107
- ```
108
-
109
- File ini tidak dicetak penuh di output terminal. `/config` dan `/provider key status` hanya menampilkan status/masked key.
110
-
111
- ## Run
112
-
113
- ```bash
114
- fincli
115
- ```
116
-
117
- Atau:
118
-
119
- ```bash
120
- python -m fincli.app.main
121
- ```
122
-
123
- ## Command Utama
124
-
125
- ```text
126
- /help
127
- /dashboard
128
- /config
129
- /ai_model
130
- /ai_model openrouter openai/gpt-4o-mini
131
- /news_model
132
- /market AAPL 1d
133
- /provider status
134
- /provider list
135
- /provider test AAPL
136
- /provider key status
137
- /watchlist
138
- /watchlist add AAPL
139
- /watchlist remove AAPL
140
- /portfolio
141
- /portfolio add BTC-USD 0.05 65000
142
- /portfolio remove BTC-USD
143
- /portfolio performance
144
- /tx add buy AAPL 10 185
145
- /tx add sell AAPL 5 195
146
- /tx list
147
- /journal
148
- /journal add BTC-USD bullish "Breakout gagal, tunggu konfirmasi"
149
- /journal stats
150
- /journal review
151
- /price AAPL
152
- /technical BTC-USD 1d
153
- /technical XAUUSD 1d
154
- /technical EURUSD 1d
155
- /structure BTC-USD 1d
156
- /news AAPL
157
- /funda MSFT
158
- /yahoo BBRI history 6mo 1d
159
- /yahoo BBRI statistics
160
- /yahoo BBRI profile
161
- /yahoo BBRI financials
162
- /yahoo BBRI analysis
163
- /yahoo BBRI holders
164
- /ai jelaskan risiko market hari ini
165
- /analyze ETH-USD 4h
166
- /scan watchlist rsi<30
167
- /scan watchlist trend=bullish
168
- /scan watchlist rsi>60 trend=bullish
169
- /calendar
170
- /calendar today
171
- /calendar 2026-06-05 2026-06-12 country=US impact=high
172
- /export portfolio json C:\Users\MSI\Desktop\portfolio.json
173
- /export journal csv C:\Users\MSI\Desktop\journal.csv
174
- /cache stats
175
- /cache clear
176
- /clear
177
- /exit
178
- ```
179
-
180
- Command `/market`, `/price`, `/quote`, `/technical`, `/structure`, `/news`, dan `/funda` sudah memakai provider chain aktif. Command `/ai` dan `/analyze` sudah memakai AI provider aktif dari `/ai_model` dan `.env`. `/analyze` membawa konteks indikator, struktur pasar, news, dan fundamental ringkas ke prompt AI. `/ai` juga mengambil quote, OHLCV/technical, structure, news, dan fundamental saat user menyebut symbol seperti `AAPL`, `EURUSD`, atau `XAUUSD`.
181
-
182
- ## AI Chat UX
183
-
184
- Di TUI, input biasa tanpa slash sekarang diperlakukan sebagai chat ke AI assistant aktif:
185
-
186
- ```text
187
- hello
188
- ```
189
-
190
- Output ditampilkan dengan format terminal chat:
191
-
192
- ```text
193
- > hello
194
- Thinking: routing prompt to active AI provider...
195
- * Provider: ...
196
- ```
197
-
198
- Command eksplisit tetap bisa dipakai:
199
-
200
- ```text
201
- /ai jelaskan risiko market hari ini
202
- ```
203
-
204
- AI assistant di dalam FinCLI dipersonalisasi untuk market workflow:
205
-
206
- - Mengenali FinCLI sebagai terminal financial dashboard.
207
- - Boleh free chat untuk pertanyaan umum, market, portfolio, journal, provider, dan risk workflow.
208
- - Menolak coding/debugging/refactor/pembuatan software di dalam assistant FinCLI agar fokus app tetap jelas.
209
- - Jika prompt berisi symbol eksplisit, FinCLI menyisipkan market context dari provider chain aktif sebelum memanggil AI provider.
210
- - Tidak membocorkan API key dan tidak mengklaim realtime jika provider aktif hanya delayed/fallback.
211
-
212
- ## Interactive AI Model Selector
213
-
214
- ```text
215
- /ai_model
216
- ```
217
-
218
- Di TUI, command ini membuka selector seperti modern CLI:
219
-
220
- - Select Provider
221
- - Status provider current/configured
222
- - Use existing configuration / configure again
223
- - Configure API key jika provider belum punya key
224
- - Select Model
225
- - Search model/provider
226
- - Navigasi `up/down`, `Enter`, `Tab`, dan `Esc`
227
-
228
- Untuk set langsung tanpa selector:
229
-
230
- ```text
231
- /ai_model openrouter openai/gpt-4o-mini
232
- ```
233
-
234
- ## Interactive Market/News Provider Selector
235
-
236
- ```text
237
- /news_model
238
- ```
239
-
240
- Di TUI, command ini membuka selector untuk provider market/news dan fallback priority:
241
-
242
- - Select Market/News Provider
243
- - Pilih `Twelve Data`, `Finnhub`, `Custom API`, atau `Yahoo Finance`
244
- - Masukkan API key langsung dari popup jika provider belum dikonfigurasi
245
- - Pilih preset fallback: recommended, primary + yfinance, data API priority, atau yfinance only
246
- - Search provider/preset
247
- - Navigasi `up/down`, `Enter`, `Tab`, dan `Esc`
248
-
249
- Rekomendasi praktis:
250
-
251
- ```text
252
- Primary: twelvedata
253
- Fallback: twelvedata -> finnhub -> custom -> yfinance
254
- ```
255
-
256
- `yfinance` tetap fallback gratis/delayed. Provider API seperti Twelve Data dan Finnhub tetap bergantung pada API key, plan, entitlement exchange, dan batas rate-limit.
257
-
258
- ## Economic Calendar
259
-
260
- ```text
261
- /calendar
262
- /calendar today
263
- /calendar week US high
264
- /calendar 2026-06-05 2026-06-12 country=US impact=high
265
- ```
266
-
267
- Jika `FINNHUB_API_KEY` tersedia, FinCLI mengambil economic calendar aktual dari Finnhub. Jika API key kosong atau provider gagal, FinCLI tetap menampilkan fallback kategori event penting seperti central bank decision, inflation release, labor data, GDP/PMI, dan retail sales. Fallback ini tidak mengklaim tanggal aktual.
268
-
269
- ## Market Cache
270
-
271
- FinCLI memakai dua lapis cache:
272
-
273
- - Runtime cache di memori untuk command yang dipanggil berulang dalam sesi TUI.
274
- - Persistent SQLite cache di `~/.fincli/fincli.db` untuk quote, OHLCV history, news, dan fundamentals.
275
-
276
- Cache mengikuti `cache_ttl_seconds` dari config. Ini penting untuk mengurangi rate-limit, mempercepat scanner/watchlist, dan membuat provider chain lebih efisien.
277
-
278
- Command:
279
-
280
- ```text
281
- /cache stats
282
- /cache clear
283
- ```
284
-
285
- `/cache clear` menghapus runtime cache dan persistent market cache. API key tetap aman karena cache hanya menyimpan respons market data, bukan secret.
286
-
287
- ## Dashboard Compact
288
-
289
- ```text
290
- /dashboard
291
- ```
292
-
293
- Dashboard dibuat sebagai layar awal TUI yang tidak stacked dan tidak ramai. Ringkasannya mencakup:
294
-
295
- - Provider chain
296
- - Watchlist price snapshot
297
- - Portfolio market value dan PnL
298
- - Journal win rate
299
- - Command hint untuk langkah berikutnya
300
-
301
- ## Market Overview
302
-
303
- Command utama untuk melihat instrumen secara profesional:
304
-
305
- ```text
306
- /market AAPL 1d
307
- ```
308
-
309
- Output berisi:
310
-
311
- - Data Quality score
312
- - Quote dan provider status
313
- - RSI, trend, MACD, ATR
314
- - Support/resistance
315
- - Market structure
316
- - Fundamental snapshot
317
- - Latest news
318
- - Disclaimer
319
-
320
- Gunakan `/market` sebagai entry point sebelum masuk ke `/technical`, `/structure`, atau `/analyze`.
321
-
322
- ## Coverage Instrumen
323
-
324
- Coverage tergantung provider dan format symbol:
325
-
326
- - `yfinance`: stocks, ETFs, indices, forex, crypto, commodities, dan mutual funds selama symbol Yahoo valid.
327
- - `custom`: instrumen apa pun selama API kamu menyediakan endpoint FinCLI.
328
- - `finnhub`: quote/candle saham, forex candle, crypto candle, company news, company profile, dan economic calendar sesuai plan API.
329
- - `twelvedata`: multi-asset stocks, forex, ETFs, indices, commodities, dan crypto dengan format symbol yang lebih konsisten untuk market global.
330
-
331
- Rekomendasi provider priority untuk multi-asset:
332
-
333
- ```text
334
- /provider priority twelvedata,finnhub,yfinance
335
- ```
336
-
337
- Dengan konfigurasi ini:
338
-
339
- - `twelvedata` dicoba dulu untuk forex/indices/commodities/global stocks.
340
- - `finnhub` menjadi fallback untuk saham dan news/fundamental tertentu.
341
- - `yfinance` tetap fallback gratis/delayed jika provider API gagal.
342
-
343
- Contoh symbol yfinance:
344
-
345
- ```text
346
- AAPL
347
- MSFT
348
- SPY
349
- ^GSPC
350
- BTC-USD
351
- ETH-USD
352
- EURUSD=X
353
- GC=F
354
- CL=F
355
- ```
356
-
357
- FinCLI juga menerima alias umum dan mengubahnya ke format provider:
358
-
359
- ```text
360
- EURUSD -> EURUSD=X untuk yfinance, EUR/USD untuk Twelve Data, OANDA:EUR_USD untuk Finnhub forex candle
361
- XAUUSD -> XAUUSD=X untuk yfinance, XAU/USD untuk Twelve Data
362
- SPX -> ^GSPC untuk yfinance
363
- NASDAQ -> ^IXIC untuk yfinance
364
- DAX -> ^GDAXI untuk yfinance
365
- NIKKEI -> ^N225 untuk yfinance
366
- WTI -> CL=F untuk yfinance
367
- BRENT -> BZ=F untuk yfinance
368
- ```
369
-
370
- ## Technical AI Summary
371
-
372
- `/technical` sekarang menyertakan ringkasan khusus untuk AI assistance:
373
-
374
- ```text
375
- /technical EURUSD 1d
376
- /technical XAUUSD 1d
377
- /technical SPX 1d
378
- ```
379
-
380
- Output mencakup trend bias, RSI, MACD, support/resistance, ATR, market structure ringkas, signal, dan risk notes. Signal bersifat rule-based dan transparan:
381
-
382
- ```text
383
- Signal: BEST TO BUY | BEST TO SELL | CAUTION
384
- Signal Score
385
- Confidence
386
- Signal Reasoning
387
- Signal Risk Notes
388
- Invalidation / Caution Level
389
- ```
390
-
391
- Signal tidak dianggap instruksi entry pasti. FinCLI tetap memakai bahasa skenario, confirmation, invalidation, dan risk notes agar cocok untuk AI assistance serta tidak memberi klaim profit. Ringkasan ini bisa langsung dipakai sebagai konteks sebelum menjalankan:
392
-
393
- Selain signal langsung, `/technical` sekarang memakai `Technical Debate`:
394
-
395
- - `Bull Chooser`: mencari argumen buy candidate.
396
- - `Bear Chooser`: mencari argumen sell candidate.
397
- - `Caution Chooser`: mencari konflik, overextension, volatilitas, dan kualitas konfirmasi.
398
- - `Judge`: menentukan final `BEST TO BUY`, `BEST TO SELL`, atau `CAUTION`.
399
-
400
- Debate ini juga dimasukkan ke prompt AI agar AI assistance tidak hanya membaca satu sisi argumen.
401
-
402
- ```text
403
- /analyze EURUSD 1d
404
- ```
405
-
406
- ## Scanner
407
-
408
- Contoh:
409
-
410
- ```text
411
- /scan watchlist
412
- /scan watchlist rsi<30
413
- /scan watchlist rsi>70
414
- /scan watchlist trend=bullish
415
- /scan watchlist trend=bearish 1d
416
- /scan watchlist rsi>60 trend=bullish
417
- ```
418
-
419
- Scanner mengambil data history secara async dalam batch terbatas, menghitung indikator, lalu hanya menampilkan symbol yang match filter.
420
-
421
- ## Portfolio Transaction Ledger
422
-
423
- Gunakan transaction ledger untuk portfolio yang lebih serius:
424
-
425
- ```text
426
- /tx add buy AAPL 10 185
427
- /tx add sell AAPL 5 195
428
- /tx list
429
- /portfolio performance
430
- ```
431
-
432
- Buy transaction akan memperbarui quantity dan average price. Sell transaction akan mengurangi posisi dan mencatat realized PnL. `/portfolio performance` menampilkan cost basis, market value, unrealized PnL, realized PnL, dan total PnL.
433
-
434
- ## Journal Analytics
435
-
436
- ```text
437
- /journal stats
438
- /journal review
439
- ```
440
-
441
- `/journal stats` menghitung total entry, win/loss, win rate, instrumen dominan, emosi dominan, dan tag teratas. `/journal review` mengirim statistik dan entry journal ke AI provider aktif untuk review proses, pola kesalahan, risk notes, dan perbaikan kebiasaan. Output tetap memakai disclaimer dan bukan nasihat keuangan.
442
-
443
- ## AI Provider
444
-
445
- Provider yang disiapkan:
446
-
447
- - `openrouter`: `OPENROUTER_API_KEY`
448
- - `openai`: `OPENAI_API_KEY`
449
- - `groq`: `GROQ_API_KEY`
450
- - `together`: `TOGETHER_API_KEY`
451
- - `huggingface`: `HUGGINGFACE_API_KEY`
452
- - `gemini`: `GEMINI_API_KEY`
453
- - `anthropic`: `ANTHROPIC_API_KEY`
454
-
455
- Contoh:
456
-
457
- ```bash
458
- /ai_model openrouter openai/gpt-4o-mini
459
- /ai_model key openrouter <api_key>
460
- /ai jelaskan risiko market NVDA secara singkat
461
- /analyze AAPL 1d
462
- ```
463
-
464
- API key tidak pernah dicetak penuh di output terminal.
465
-
466
- ## Data Realtime / Delayed
467
-
468
- FinCLI saat ini memakai yfinance sebagai fallback. Data yfinance umumnya delayed dan tidak boleh diklaim realtime. Provider API key dapat ditambahkan untuk realtime jika provider tersebut mendukungnya.
469
-
470
- ## Yahoo Finance Tables
471
-
472
- FinCLI memakai yfinance untuk akses saham global yang tersedia di Yahoo Finance. Untuk saham di luar US, gunakan suffix Yahoo bila tahu exchange-nya, misalnya `BBRI.JK`, `HSBA.L`, `SHOP.TO`, atau `0700.HK`. Untuk ticker IDX umum seperti `BBRI`, `BBCA`, `BMRI`, `TLKM`, `ASII`, FinCLI otomatis mengarahkannya ke suffix `.JK`.
473
-
474
- Command:
475
-
476
- ```text
477
- /price BBRI
478
- /technical BBRI 1d
479
- /analyze BBRI 1d
480
- /yahoo BBRI history 6mo 1d
481
- /yahoo BBRI news
482
- /yahoo BBRI statistics
483
- /yahoo BBRI profile
484
- /yahoo BBRI financials
485
- /yahoo BBRI balance
486
- /yahoo BBRI cashflow
487
- /yahoo BBRI analysis
488
- /yahoo BBRI holders
489
- ```
490
-
491
- Source URL yang dipakai mengikuti format Yahoo Finance, misalnya:
492
-
493
- ```text
494
- https://finance.yahoo.com/quote/BBRI.JK/
495
- https://finance.yahoo.com/quote/BBRI.JK/news/
496
- https://finance.yahoo.com/quote/BBRI.JK/key-statistics/
497
- https://finance.yahoo.com/quote/BBRI.JK/history/
498
- https://finance.yahoo.com/quote/BBRI.JK/profile/
499
- https://finance.yahoo.com/quote/BBRI.JK/financials/
500
- https://finance.yahoo.com/quote/BBRI.JK/analysis/
501
- https://finance.yahoo.com/quote/BBRI.JK/holders/
502
- ```
503
-
504
- Catatan: availability news, analysis, holders, dan beberapa financial table bergantung coverage Yahoo untuk exchange/ticker tersebut.
505
-
506
- ## Finnhub Provider
507
-
508
- Aktifkan lewat selector TUI:
509
-
510
- ```text
511
- /news_model
512
- ```
513
-
514
- Environment variable:
515
-
516
- ```env
517
- FINNHUB_API_KEY=your-finnhub-key
518
- ```
519
-
520
- Atau simpan dari FinCLI:
521
-
522
- ```text
523
- /news_model key finnhub <api_key>
524
- ```
525
-
526
- Endpoint Finnhub yang dipakai:
527
-
528
- ```text
529
- GET /quote
530
- GET /stock/candle
531
- GET /forex/candle
532
- GET /crypto/candle
533
- GET /company-news
534
- GET /stock/profile2
535
- GET /calendar/economic
536
- ```
537
-
538
- Catatan: Finnhub menyediakan REST/WebSocket untuk stocks, currencies/forex, dan crypto, plus fundamental/news sesuai plan. Di FinCLI, news/fundamental tetap paling kuat untuk saham; forex/crypto dipakai untuk candle/technical.
539
-
540
- ## Twelve Data Provider
541
-
542
- Aktifkan lewat selector TUI:
543
-
544
- ```text
545
- /news_model
546
- ```
547
-
548
- Environment variable:
549
-
550
- ```env
551
- TWELVE_DATA_API_KEY=your-twelve-data-key
552
- ```
553
-
554
- Atau simpan dari FinCLI:
555
-
556
- ```text
557
- /news_model key twelvedata <api_key>
558
- ```
559
-
560
- Endpoint Twelve Data yang dipakai:
561
-
562
- ```text
563
- GET /quote
564
- GET /time_series
565
- ```
566
-
567
- Twelve Data paling cocok untuk symbol multi-asset seperti forex (`EURUSD`), metals (`XAUUSD`), indices global, ETF, crypto, dan saham populer US/Eropa/Asia. Tetap cek plan dan exchange entitlement provider untuk realtime vs delayed.
568
-
569
- ## Provider Commands
570
-
571
- ```text
572
- /news_model
573
- /provider list
574
- /provider status
575
- /provider test AAPL
576
- /provider test finnhub AAPL
577
- /provider key status
578
- ```
579
-
580
- `/news_model` adalah flow resmi untuk memilih provider market/news dan fallback chain di TUI. `/provider status` menampilkan provider aktif, fallback chain, dan health message dari provider utama. `/provider test <symbol>` melakukan quote test lewat provider aktif. `/provider test <provider> <symbol>` mengetes provider tertentu tanpa mengganti provider aktif.
581
-
582
- Command manual `/provider use ...` dan `/provider priority ...` masih tersedia sebagai advanced CLI fallback, tetapi tidak lagi ditampilkan sebagai flow utama di command palette.
583
-
584
- Contoh fallback chain yang disimpan selector:
585
-
586
- ```text
587
- twelvedata -> finnhub -> custom -> yfinance
588
- ```
589
-
590
- Dengan contoh di atas, FinCLI mencoba Twelve Data lebih dulu. Jika gagal, FinCLI mencoba provider berikutnya dan memakai yfinance delayed sebagai fallback terakhir.
591
-
592
- ## Custom Market Provider
593
-
594
- Aktifkan lewat selector TUI:
595
-
596
- ```text
597
- /news_model
598
- ```
599
-
600
- Environment variable:
601
-
602
- ```env
603
- MARKET_DATA_API_KEY=your-key
604
- MARKET_DATA_BASE_URL=https://your-market-api.example.com
605
- ```
606
-
607
- Atau simpan dari FinCLI:
608
-
609
- ```text
610
- /news_model key custom <api_key> https://your-market-api.example.com
611
- ```
612
-
613
- FinCLI akan memanggil endpoint:
614
-
615
- ```text
616
- GET /quote/{symbol}
617
- GET /history/{symbol}?period=6mo&interval=1d
618
- GET /news/{symbol}?limit=5
619
- GET /fundamentals/{symbol}
620
- ```
621
-
622
- Header dikirim sebagai `X-API-Key` dan `Authorization: Bearer <key>`. API key tidak ditampilkan di terminal.
623
-
624
- Contoh payload quote:
625
-
626
- ```json
627
- {
628
- "symbol": "AAPL",
629
- "price": 123.45,
630
- "currency": "USD",
631
- "timestamp": "2026-06-04T12:00:00",
632
- "status": "realtime"
633
- }
634
- ```
635
-
636
- ## Local Storage
637
-
638
- FinCLI menyimpan data lokal di:
639
-
640
- ```text
641
- ~/.fincli/config.json
642
- ~/.fincli/fincli.db
643
- ~/.fincli/fincli.log
644
- ```
645
-
646
- API key tidak disimpan di output terminal dan sebaiknya tetap berada di `.env` atau environment variable.
647
- Untuk install global via npm, API key paling praktis disimpan lewat command FinCLI di `~/.fincli/secrets.env`.
648
-
649
- ## Test
650
-
651
- ```bash
652
- pytest
653
- ```
654
-
655
- Hasil terakhir di environment ini:
656
-
657
- ```text
658
- 97 passed
659
- ```
660
-
661
- ## Troubleshooting
662
-
663
- - `fincli` tidak dikenali: jalankan `pip install -e .` dari root project.
664
- - TUI tidak tampil rapi: perbesar terminal desktop.
665
- - API key tidak terbaca: gunakan `/ai_model key <provider> <api_key>` atau `/news_model key <provider> <api_key>`, lalu cek `/config` atau `/provider key status`.
666
- - `/price` gagal karena yfinance belum ada: jalankan `pip install -e ".[dev]"` atau `pip install -r requirements.txt`.
667
- - Config rusak: hapus `~/.fincli/config.json` untuk kembali ke default.
668
-
669
- ## Roadmap Lanjutan
670
-
671
- - Scanner export dan filter expression parser yang lebih lengkap.
672
- - Market structure lebih lanjut: pivot strength, multi-timeframe structure, liquidity sweep detection.
673
- - AI market analysis dengan ranking data quality dan confidence scoring.
674
- - Custom provider schema validation yang lebih ketat dan adapter untuk provider populer.
675
- - Provider adapter lanjutan untuk entitlement exchange, symbol search, dan realtime streaming.
676
- - Economic calendar lanjutan, screener, alert dasar, dan multi-timeframe analysis.
677
-
678
- ## Roadmap v0.3
679
-
680
- - Plugin system.
681
- - Strategy builder.
682
- - Advanced portfolio analytics.
683
- - Notification integration.
684
- - Optional cloud sync.
1
+ <<<<<<< HEAD
2
+ # FinCLI v0.2.2
3
+ =======
4
+ # FinCLI v0.1.9
5
+ >>>>>>> a26bfe0e03787066d4676c17641647723991f356
6
+
7
+ FinCLI is a modern financial CLI/TUI terminal for market monitoring, technical analysis, AI-assisted research, portfolio tracking, watchlists, trading journals, and configurable market/news provider workflows.
8
+
9
+ Current status: FinCLI is an active MVP moving into v0.2 with a Textual TUI, provider chain, symbol normalization, AI assistance, web research, portfolio, journal, watchlist, exports, and local session history.
10
+
11
+ - Single-column Textual TUI with an inline command palette and scrollable command suggestions. The old sidebar has been removed so market output has more room.
12
+ - Slash command router for the core FinCLI v0.1 command system.
13
+ - Config system using optional `.env` values for local development, `~/.fincli/config.json` for non-secret preferences, and `~/.fincli/secrets.env` for API keys saved from commands.
14
+ - SQLite local storage for watchlist, portfolio, journal, transactions, session history, and persistent market cache.
15
+ - yfinance fallback for quote, OHLCV history, news, Yahoo tables, and fundamental snapshots.
16
+ - Finnhub provider for quotes, stock candles, company news, company profile, and economic calendar via `FINNHUB_API_KEY`.
17
+ - Twelve Data provider for multi-asset market data via `TWELVE_DATA_API_KEY`.
18
+ - Alpha Vantage provider for stock/FX quote, daily history, news sentiment, and company overview via `ALPHA_VANTAGE_API_KEY`.
19
+ - 100+ news connector catalog for `/news`, including public RSS fallbacks and API-key-ready providers such as Marketaux, NewsAPI, GNews, Alpha Vantage News, Finnhub News, StockNewsAPI, APITube, Benzinga, Polygon, Tiingo, FMP, and EODHD.
20
+ - Symbol search and provider-specific normalization with `/symbol`.
21
+ - Provider entitlement and realtime/delayed labeling with `/provider entitlement`.
22
+ - Economic calendar through Finnhub when an API key is configured, with a local fallback when the provider is unavailable.
23
+ - Technical analysis: SMA, EMA, RSI, MACD, Bollinger Bands, ATR, support/resistance, volume, trend bias, and technical signal scoring.
24
+ - Market structure analysis: HH/HL, LH/LL, break of structure, change of character, liquidity areas, and risk zones.
25
+ - Technical Debate engine for `/technical`: Bull Chooser, Bear Chooser, Caution Chooser, and Judge.
26
+ - Watchlist scanner: `/scan watchlist` with filters such as `rsi<30`, `rsi>70`, and `trend=bullish`.
27
+ - Persistent market cache for quote, OHLCV history, news, and fundamentals to reduce unnecessary API calls.
28
+ - `/ai` and `/analyze` use the active AI provider. `/ai` has a FinCLI-specific persona, anti-coding guardrails, optional market context, and optional web research context.
29
+ - AI HTTP clients for OpenAI-compatible APIs, Gemini, and Anthropic. OpenRouter, OpenAI, Together, Groq, and HuggingFace use OpenAI-compatible request flows.
30
+ - Portfolio view calculates current price, PnL, PnL percent, allocation, and transaction-ledger performance.
31
+ - Portfolio and journal export to CSV or JSON.
32
+ - Basic tests for command registry, router, config, storage, market providers, technical analysis, AI commands, TUI selectors, web research, and session history.
33
+
34
+ ## Stack
35
+
36
+ - Python 3.11+
37
+ - Textual + Rich for the terminal UI
38
+ - SQLite for local storage
39
+ - python-dotenv for optional local `.env` support
40
+ - yfinance for fallback market/news/fundamental data
41
+ - httpx for provider APIs and lightweight web research
42
+ - pandas + numpy for analysis workflows
43
+ - pytest for tests
44
+ - npm wrapper for global installation through `npm install -g`
45
+
46
+ Textual was chosen because FinCLI needs an interactive terminal dashboard instead of a static CLI. Rich is still used for tables, panels, Markdown rendering, and structured output.
47
+
48
+ ## Install
49
+
50
+ For local development:
51
+
52
+ ```bash
53
+ python -m venv .venv
54
+ .venv\Scripts\activate
55
+ pip install -e ".[dev]"
56
+ ```
57
+
58
+ Alternative:
59
+
60
+ ```bash
61
+ pip install -r requirements.txt
62
+ ```
63
+
64
+ ## Global Install
65
+
66
+ The recommended Python CLI approach is `pipx`, because FinCLI dependencies are installed in an isolated environment while the `fincli` command remains globally available:
67
+
68
+ ```bash
69
+ pip install pipx
70
+ pipx ensurepath
71
+ pipx install .
72
+ fincli
73
+ ```
74
+
75
+ If the Python package is published to PyPI:
76
+
77
+ ```bash
78
+ pipx install fincli
79
+ fincli
80
+ ```
81
+
82
+ FinCLI also ships with an npm wrapper so users can follow a common "install once, run anywhere" CLI pattern:
83
+
84
+ ```bash
85
+ npm install -g @drico2008/fincli
86
+ fincli
87
+ ```
88
+
89
+ For local npm testing before publishing:
90
+
91
+ ```bash
92
+ npm install -g .
93
+ fincli
94
+ ```
95
+
96
+ Note: the npm wrapper still requires Python 3.11+ during installation. The postinstall script creates a local `.npm-python` virtual environment inside the installed package, installs the Python FinCLI package there, and the global `fincli` command runs `python -m fincli.app.main`.
97
+
98
+ ## Setup
99
+
100
+ For local development, you may copy `.env.example`:
101
+
102
+ ```bash
103
+ copy .env.example .env
104
+ ```
105
+
106
+ Only fill API keys for providers you want to use. The yfinance fallback does not require an API key. FinCLI never prints full API keys in the terminal.
107
+
108
+ For global npm installs, users do not need to open the installed package folder or edit `.env`. Save API keys directly from FinCLI:
109
+
110
+ ```text
111
+ /ai_model key groq <api_key>
112
+ /ai_model key openrouter <api_key>
113
+ /news_model key finnhub <api_key>
114
+ /news_model key twelvedata <api_key>
115
+ /news_model key custom <api_key> https://your-market-api.example.com
116
+ ```
117
+
118
+ Keys are saved locally at:
119
+
120
+ ```text
121
+ ~/.fincli/secrets.env
122
+ ```
123
+
124
+ The file is not printed in full by FinCLI. `/config` and `/provider key status` only show masked key status and safe source labels.
125
+
126
+ ## Run
127
+
128
+ ```bash
129
+ fincli
130
+ ```
131
+
132
+ Or:
133
+
134
+ ```bash
135
+ python -m fincli.app.main
136
+ ```
137
+
138
+ ## Main Commands
139
+
140
+ ```text
141
+ /help
142
+ /dashboard
143
+ /config
144
+ /ai_model
145
+ /ai_model openrouter openai/gpt-4o-mini
146
+ /ai_model key groq <api_key>
147
+ /news_model
148
+ /news_model list
149
+ /news_model search rss
150
+ /news_model use google_news_rss
151
+ /news_model priority google_news_rss,yfinance,marketaux,newsapi,gnews
152
+ /news_model key finnhub <api_key>
153
+ /news_model key marketaux <api_key>
154
+ /news_model key alphavantage <api_key>
155
+ /symbol XAUUSD
156
+ /symbol normalize BBRI
157
+ /market AAPL 1d
158
+ /provider status
159
+ /provider list
160
+ /provider entitlement
161
+ /provider test AAPL
162
+ /provider key status
163
+ /watchlist
164
+ /watchlist add AAPL
165
+ /watchlist remove AAPL
166
+ /portfolio
167
+ /portfolio add BTC-USD 0.05 65000
168
+ /portfolio remove BTC-USD
169
+ /portfolio performance
170
+ /tx add buy AAPL 10 185
171
+ /tx add sell AAPL 5 195
172
+ /tx list
173
+ /journal
174
+ /journal add BTC-USD bullish "Failed breakout, wait for confirmation"
175
+ /journal stats
176
+ /journal review
177
+ /alert
178
+ /alert add AAPL above 200
179
+ /alert check
180
+ /history
181
+ /history sessions
182
+ /history show <session_id>
183
+ /history save "Morning market research"
184
+ /history delete <session_id>
185
+ /quote AAPL
186
+ /technical BTC-USD 1d
187
+ /technical XAUUSD 1d
188
+ /technical EURUSD 1d
189
+ /mtf AAPL 1d,1h,15m
190
+ /backtest AAPL sma_cross 1d
191
+ /backtest EURUSD rsi_reversion 1h
192
+ /structure BTC-USD 1d
193
+ /news AAPL
194
+ /web why is the rupiah weakening today
195
+ /web sources why is the rupiah weakening today
196
+ /funda MSFT
197
+ /yahoo BBRI history 6mo 1d
198
+ /yahoo BBRI statistics
199
+ /yahoo BBRI profile
200
+ /yahoo BBRI financials
201
+ /yahoo BBRI analysis
202
+ /yahoo BBRI holders
203
+ /ai explain today's market risk
204
+ /analyze ETH-USD 4h
205
+ /scan watchlist rsi<30
206
+ /scan watchlist trend=bullish
207
+ /scan watchlist rsi>60 trend=bullish
208
+ /scan export csv scan.csv rsi<30 1d
209
+ /report market AAPL md report.md
210
+ /report market AAPL json report.json
211
+ /calendar
212
+ /calendar today
213
+ /calendar 2026-06-05 2026-06-12 country=US impact=high
214
+ /calendar export csv calendar.csv week US high
215
+ /export portfolio json C:\Users\MSI\Desktop\portfolio.json
216
+ /export journal csv C:\Users\MSI\Desktop\journal.csv
217
+ /cache stats
218
+ /cache clear
219
+ /clear
220
+ /exit
221
+ ```
222
+
223
+ `/market`, `/quote`, `/technical`, `/structure`, and `/funda` use the active market provider chain. `/news` uses the active news fallback chain from `/news_model priority`. `/ai` and `/analyze` use the active AI provider from `/ai_model`. `/analyze` sends indicator, market structure, news, and fundamental context to the AI prompt. `/ai` can also attach quote, OHLCV/technical, structure, news, fundamental, and web context when the prompt asks for current information or mentions a clear symbol such as `AAPL`, `EURUSD`, or `XAUUSD`.
224
+
225
+ ## AI Chat UX
226
+
227
+ Inside the TUI, regular input without a slash is treated as chat to the active AI assistant:
228
+
229
+ ```text
230
+ hello
231
+ ```
232
+
233
+ Output is rendered as a terminal chat:
234
+
235
+ ```text
236
+ > hello
237
+ > Thinking: routing prompt to active AI provider...
238
+ * Provider: ...
239
+ ```
240
+
241
+ Explicit command mode is still supported:
242
+
243
+ ```text
244
+ /ai explain today's market risk
245
+ ```
246
+
247
+ The FinCLI assistant is customized for market workflows:
248
+
249
+ - It understands FinCLI as a financial terminal dashboard.
250
+ - It supports free chat for general questions, market research, portfolio workflows, journal review, provider setup, and risk analysis.
251
+ - It refuses coding, debugging, refactoring, and software-building requests inside the FinCLI assistant so the in-app assistant remains focused.
252
+ - If a prompt includes a clear market symbol, FinCLI attaches market context from the active provider chain before calling the AI provider.
253
+ - If a prompt needs recent public information, FinCLI can collect lightweight web context and pass it to the AI prompt.
254
+ - It never exposes API keys and never claims realtime data when the active provider is delayed or fallback-only.
255
+
256
+ Examples:
257
+
258
+ ```text
259
+ what caused the rupiah to weaken today
260
+ latest BI rate news and possible impact on IHSG
261
+ ```
262
+
263
+ Web research summarized by AI:
264
+
265
+ ```text
266
+ /web why is the rupiah weakening today
267
+ /web gold price and dollar index update
268
+ ```
269
+
270
+ Raw web sources without AI synthesis:
271
+
272
+ ```text
273
+ /web sources why is the rupiah weakening today
274
+ ```
275
+
276
+ FinCLI uses lightweight HTTP web research, not Chrome automation. This is more stable for global npm installs and does not open a browser in the background. Web-based output should still be verified because source quality can vary.
277
+
278
+ ## Interactive AI Model Selector
279
+
280
+ ```text
281
+ /ai_model
282
+ ```
283
+
284
+ In the TUI, this opens a modern CLI-style selector:
285
+
286
+ - Select Provider
287
+ - Show current/configured provider status
288
+ - Use existing configuration or configure again
289
+ - Enter API key from the popup when the provider has no key
290
+ - Select Model
291
+ - Search model/provider
292
+ - Navigate with `up/down`, `Enter`, `Tab`, and `Esc`
293
+
294
+ Set a provider/model directly:
295
+
296
+ ```text
297
+ /ai_model openrouter openai/gpt-4o-mini
298
+ ```
299
+
300
+ Save a key directly:
301
+
302
+ ```text
303
+ /ai_model key openrouter <api_key>
304
+ ```
305
+
306
+ ## News Connectors and Fallbacks
307
+
308
+ ```text
309
+ /news_model
310
+ ```
311
+
312
+ `/news_model` manages the `/news` provider chain. It supports public RSS fallbacks, yfinance news, custom news APIs, and API-key providers.
313
+
314
+ Useful commands:
315
+
316
+ ```text
317
+ /news_model list
318
+ /news_model search rss
319
+ /news_model use google_news_rss
320
+ /news_model priority google_news_rss,yfinance,yahoo_finance_rss,marketaux,newsapi,gnews
321
+ /news_model key marketaux <api_key>
322
+ /news_model key custom_news <api_key> https://your-news-api.example.com
323
+ ```
324
+
325
+ Practical free-first default:
326
+
327
+ ```text
328
+ /news_model priority google_news_rss,yfinance,yahoo_finance_rss
329
+ ```
330
+
331
+ API-key providers such as Marketaux, NewsAPI, GNews, Finnhub, and Alpha Vantage depend on their free-tier limits, plan, exchange entitlement, and rate limits. Public RSS sources may fail or change without notice, so FinCLI tries the next fallback automatically.
332
+
333
+ ## Economic Calendar
334
+
335
+ ```text
336
+ /calendar
337
+ /calendar today
338
+ /calendar week US high
339
+ /calendar 2026-06-05 2026-06-12 country=US impact=high
340
+ /calendar export csv calendar.csv week US high
341
+ ```
342
+
343
+ When `FINNHUB_API_KEY` is configured, FinCLI pulls actual economic calendar data from Finnhub. If the key is missing or the provider fails, FinCLI shows a local fallback list of important event categories such as central bank decisions, inflation releases, labor data, GDP/PMI, and retail sales. The fallback does not claim actual event dates.
344
+
345
+ Calendar output includes impact summary counts. `/calendar export` writes filtered events to CSV or JSON.
346
+
347
+ ## Market Cache
348
+
349
+ FinCLI uses two cache layers:
350
+
351
+ - Runtime memory cache for repeated commands in the same TUI session.
352
+ - Persistent SQLite cache in `~/.fincli/fincli.db` for quotes, OHLCV history, news, and fundamentals.
353
+
354
+ Cache TTL follows `cache_ttl_seconds` from config. This reduces rate-limit pressure, speeds up watchlist/scanner workflows, and makes provider fallback more efficient.
355
+
356
+ Commands:
357
+
358
+ ```text
359
+ /cache stats
360
+ /cache clear
361
+ ```
362
+
363
+ `/cache clear` removes runtime cache and persistent market cache. API keys stay safe because market cache stores provider responses, not secrets.
364
+
365
+ ## Dashboard
366
+
367
+ ```text
368
+ /dashboard
369
+ ```
370
+
371
+ The dashboard is designed as a compact first screen, not a stacked wall of panels. It includes:
372
+
373
+ - Provider chain
374
+ - Watchlist price snapshot
375
+ - Portfolio market value and PnL
376
+ - Journal win rate
377
+ - Command hints for next steps
378
+
379
+ ## Market Overview
380
+
381
+ Use `/market` as a professional entry point for a symbol:
382
+
383
+ ```text
384
+ /market AAPL 1d
385
+ ```
386
+
387
+ Output includes:
388
+
389
+ - Data Quality score
390
+ - Quote and provider status
391
+ - RSI, trend, MACD, ATR
392
+ - Support/resistance
393
+ - Market structure
394
+ - Fundamental snapshot
395
+ - Latest news
396
+ - Disclaimer
397
+
398
+ Use `/market` before moving into `/technical`, `/structure`, or `/analyze`.
399
+
400
+ ## Instrument Coverage
401
+
402
+ Coverage depends on provider and symbol format:
403
+
404
+ - `yfinance`: stocks, ETFs, indices, forex, crypto, commodities, and mutual funds as long as Yahoo supports the symbol.
405
+ - `custom`: any instrument your API exposes through the FinCLI custom provider schema.
406
+ - `finnhub`: stock quotes/candles, forex candles, crypto candles, company news, company profile, and economic calendar depending on API plan.
407
+ - `twelvedata`: multi-asset stocks, forex, ETFs, indices, commodities, and crypto with more consistent global market symbol formatting.
408
+ - `alphavantage`: stocks and FX quote/history plus news sentiment and company overview, with strict free-plan rate limits.
409
+
410
+ Recommended provider priority for multi-asset usage:
411
+
412
+ ```text
413
+ /provider priority twelvedata,finnhub,yfinance
414
+ ```
415
+
416
+ With that setup:
417
+
418
+ - `twelvedata` is tried first for forex, indices, commodities, and global stocks.
419
+ - `finnhub` is used as fallback for stocks and selected news/fundamental data.
420
+ - `yfinance` remains the free delayed fallback if API providers fail.
421
+
422
+ Example yfinance symbols:
423
+
424
+ ```text
425
+ AAPL
426
+ MSFT
427
+ SPY
428
+ ^GSPC
429
+ BTC-USD
430
+ ETH-USD
431
+ EURUSD=X
432
+ GC=F
433
+ CL=F
434
+ ```
435
+
436
+ FinCLI accepts common aliases and maps them into provider-specific formats:
437
+
438
+ ```text
439
+ EURUSD -> EURUSD=X for yfinance, EUR/USD for Twelve Data, OANDA:EUR_USD for Finnhub forex candles
440
+ XAUUSD -> XAUUSD=X for yfinance, XAU/USD for Twelve Data
441
+ SPX -> ^GSPC for yfinance
442
+ NASDAQ -> ^IXIC for yfinance
443
+ DAX -> ^GDAXI for yfinance
444
+ NIKKEI -> ^N225 for yfinance
445
+ WTI -> CL=F for yfinance
446
+ BRENT -> BZ=F for yfinance
447
+ ```
448
+
449
+ ## Technical AI Summary
450
+
451
+ `/technical` includes a structured summary designed for AI assistance:
452
+
453
+ ```text
454
+ /technical EURUSD 1d
455
+ /technical XAUUSD 1d
456
+ /technical SPX 1d
457
+ ```
458
+
459
+ Output includes trend bias, RSI, MACD, support/resistance, ATR, market structure summary, signal, and risk notes. The signal is rule-based and transparent:
460
+
461
+ ```text
462
+ Signal: BEST TO BUY | BEST TO SELL | CAUTION
463
+ Signal Score
464
+ Confidence
465
+ Signal Reasoning
466
+ Signal Risk Notes
467
+ Invalidation / Caution Level
468
+ ```
469
+
470
+ The signal is not a guaranteed entry instruction. FinCLI uses scenario language, confirmation, invalidation, and risk notes instead of profit claims.
471
+
472
+ `/technical` also uses `Technical Debate`:
473
+
474
+ - `Bull Chooser`: finds buy-candidate arguments.
475
+ - `Bear Chooser`: finds sell-candidate arguments.
476
+ - `Caution Chooser`: finds conflicts, overextension, volatility risk, and weak confirmation.
477
+ - `Judge`: decides the final `BEST TO BUY`, `BEST TO SELL`, or `CAUTION`.
478
+
479
+ The debate result is also included in AI prompts so the assistant does not reason from only one side.
480
+
481
+ ```text
482
+ /analyze EURUSD 1d
483
+ ```
484
+
485
+ ## Multi-Timeframe Analysis
486
+
487
+ ```text
488
+ /mtf AAPL
489
+ /mtf EURUSD 1d,1h,15m
490
+ /mtf XAUUSD 1d,4h,1h
491
+ ```
492
+
493
+ `/mtf` fetches multiple timeframes through the active provider chain, summarizes trend/structure/RSI/MACD/key levels for each timeframe, and returns an alignment label such as `aligned bullish`, `mostly bearish`, or `mixed`. The default timeframe set is `1d,1h,15m` for yfinance compatibility. Use `4h` when the active provider supports it.
494
+
495
+ ## Lightweight Backtesting
496
+
497
+ ```text
498
+ /backtest AAPL sma_cross 1d
499
+ /backtest EURUSD rsi_reversion 1h
500
+ ```
501
+
502
+ The v0.2 lightweight backtester supports educational long-only rule-based strategies:
503
+
504
+ - `sma_cross`: enters on fast/slow SMA bullish cross and exits on bearish cross.
505
+ - `rsi_reversion`: enters below RSI 30 and exits above RSI 55.
506
+
507
+ Output includes candles, trades, total return, win rate, max drawdown, exposure, latest trade, and risk notes. The backtest ignores fees, slippage, spreads, liquidity, and execution constraints.
508
+
509
+ ## Scanner
510
+
511
+ Examples:
512
+
513
+ ```text
514
+ /scan watchlist
515
+ /scan watchlist rsi<30
516
+ /scan watchlist rsi>70
517
+ /scan watchlist trend=bullish
518
+ /scan watchlist trend=bearish 1d
519
+ /scan watchlist rsi>60 trend=bullish
520
+ /scan export csv scan.csv rsi<30 1d
521
+ /scan export json scan.json trend=bullish 1d
522
+ ```
523
+
524
+ The scanner fetches history asynchronously in limited batches, calculates indicators, and only displays symbols that match the filter.
525
+
526
+ Scanner exports write matched scan rows from the current watchlist to CSV or JSON.
527
+
528
+ ## Exportable Market Reports
529
+
530
+ ```text
531
+ /report market AAPL md report.md
532
+ /report market AAPL json report.json
533
+ ```
534
+
535
+ Market reports reuse the `/market` overview pipeline and export quote, data quality, technicals, market structure, fundamentals, latest news, and disclaimer to Markdown or JSON.
536
+
537
+ ## Portfolio Transaction Ledger
538
+
539
+ Use the transaction ledger for more serious portfolio tracking:
540
+
541
+ ```text
542
+ /tx add buy AAPL 10 185
543
+ /tx add sell AAPL 5 195
544
+ /tx list
545
+ /portfolio performance
546
+ ```
547
+
548
+ Buy transactions update quantity and average price. Sell transactions reduce position size and record realized PnL. `/portfolio performance` shows cost basis, market value, unrealized PnL, realized PnL, and total PnL.
549
+
550
+ ## Journal Analytics
551
+
552
+ ```text
553
+ /journal stats
554
+ /journal review
555
+ ```
556
+
557
+ `/journal stats` calculates total entries, wins/losses, win rate, dominant instrument, dominant emotion, and top tags. `/journal review` sends journal statistics and recent entries to the active AI provider for process review, repeated mistake detection, risk notes, and habit improvement. Output includes a non-financial-advice disclaimer.
558
+
559
+ ## Session History
560
+
561
+ ```text
562
+ /history
563
+ /history sessions
564
+ /history show <session_id>
565
+ /history save "Morning market research"
566
+ /history delete <session_id>
567
+ /history clear current
568
+ ```
569
+
570
+ FinCLI stores local session events in SQLite so users can review previous terminal sessions. API key commands are redacted before being saved.
571
+
572
+ ## Price Alerts
573
+
574
+ ```text
575
+ /alert
576
+ /alert add AAPL above 200
577
+ /alert add EURUSD below 1.0800
578
+ /alert check
579
+ /alert remove <id>
580
+ ```
581
+
582
+ Alerts are stored locally in SQLite. v0.2.0 checks alerts manually with `/alert check` using the active quote provider. Triggered alerts are marked inactive. This is not a background notification daemon yet.
583
+
584
+ ## AI Providers
585
+
586
+ Supported provider keys:
587
+
588
+ - `openrouter`: `OPENROUTER_API_KEY`
589
+ - `openai`: `OPENAI_API_KEY`
590
+ - `groq`: `GROQ_API_KEY`
591
+ - `together`: `TOGETHER_API_KEY`
592
+ - `huggingface`: `HUGGINGFACE_API_KEY`
593
+ - `gemini`: `GEMINI_API_KEY`
594
+ - `anthropic`: `ANTHROPIC_API_KEY`
595
+
596
+ Examples:
597
+
598
+ ```text
599
+ /ai_model openrouter openai/gpt-4o-mini
600
+ /ai_model key openrouter <api_key>
601
+ /ai explain NVDA market risk briefly
602
+ /analyze AAPL 1d
603
+ ```
604
+
605
+ API keys are never printed in full.
606
+
607
+ ## Realtime vs Delayed Data
608
+
609
+ FinCLI uses yfinance as the default fallback. yfinance data is usually delayed and must not be described as realtime. API providers may provide realtime data only if the provider, subscription plan, and exchange entitlement support it.
610
+
611
+ FinCLI displays provider status as realtime, delayed, fallback, or unavailable whenever the provider exposes that status.
612
+
613
+ ## Yahoo Finance Tables
614
+
615
+ FinCLI uses yfinance for global equities available on Yahoo Finance. For non-US stocks, use the Yahoo exchange suffix when known, such as `BBRI.JK`, `HSBA.L`, `SHOP.TO`, or `0700.HK`. For common IDX tickers such as `BBRI`, `BBCA`, `BMRI`, `TLKM`, and `ASII`, FinCLI automatically maps them to `.JK`.
616
+
617
+ Commands:
618
+
619
+ ```text
620
+ /quote BBRI
621
+ /technical BBRI 1d
622
+ /analyze BBRI 1d
623
+ /yahoo BBRI history 6mo 1d
624
+ /yahoo BBRI news
625
+ /yahoo BBRI statistics
626
+ /yahoo BBRI profile
627
+ /yahoo BBRI financials
628
+ /yahoo BBRI balance
629
+ /yahoo BBRI cashflow
630
+ /yahoo BBRI analysis
631
+ /yahoo BBRI holders
632
+ ```
633
+
634
+ Yahoo Finance URL examples:
635
+
636
+ ```text
637
+ https://finance.yahoo.com/quote/BBRI.JK/
638
+ https://finance.yahoo.com/quote/BBRI.JK/news/
639
+ https://finance.yahoo.com/quote/BBRI.JK/key-statistics/
640
+ https://finance.yahoo.com/quote/BBRI.JK/history/
641
+ https://finance.yahoo.com/quote/BBRI.JK/profile/
642
+ https://finance.yahoo.com/quote/BBRI.JK/financials/
643
+ https://finance.yahoo.com/quote/BBRI.JK/analysis/
644
+ https://finance.yahoo.com/quote/BBRI.JK/holders/
645
+ ```
646
+
647
+ Availability of news, analysis, holders, and financial tables depends on Yahoo coverage for the exchange/ticker.
648
+
649
+ ## Finnhub Provider
650
+
651
+ Open the provider selector:
652
+
653
+ ```text
654
+ /news_model
655
+ ```
656
+
657
+ Environment variable:
658
+
659
+ ```env
660
+ FINNHUB_API_KEY=your-finnhub-key
661
+ ```
662
+
663
+ Or save it from FinCLI:
664
+
665
+ ```text
666
+ /news_model key finnhub <api_key>
667
+ ```
668
+
669
+ Finnhub endpoints used:
670
+
671
+ ```text
672
+ GET /quote
673
+ GET /stock/candle
674
+ GET /forex/candle
675
+ GET /crypto/candle
676
+ GET /company-news
677
+ GET /stock/profile2
678
+ GET /calendar/economic
679
+ ```
680
+
681
+ Finnhub provides REST/WebSocket data for stocks, currencies/forex, and crypto, plus fundamental/news data depending on plan. In FinCLI, news/fundamental support is strongest for equities; forex/crypto are mainly used for candles and technical analysis.
682
+
683
+ ## Twelve Data Provider
684
+
685
+ Open the provider selector:
686
+
687
+ ```text
688
+ /news_model
689
+ ```
690
+
691
+ Environment variable:
692
+
693
+ ```env
694
+ TWELVE_DATA_API_KEY=your-twelve-data-key
695
+ ```
696
+
697
+ Or save it from FinCLI:
698
+
699
+ ```text
700
+ /news_model key twelvedata <api_key>
701
+ ```
702
+
703
+ Twelve Data endpoints used:
704
+
705
+ ```text
706
+ GET /quote
707
+ GET /time_series
708
+ ```
709
+
710
+ Twelve Data is useful for multi-asset symbols such as forex (`EURUSD`), metals (`XAUUSD`), global indices, ETFs, crypto, and popular US/Europe/Asia stocks. Always check provider plan and exchange entitlement for realtime vs delayed access.
711
+
712
+ ## Alpha Vantage Provider
713
+
714
+ Open the provider selector:
715
+
716
+ ```text
717
+ /news_model
718
+ ```
719
+
720
+ Environment variable:
721
+
722
+ ```env
723
+ ALPHA_VANTAGE_API_KEY=your-alpha-vantage-key
724
+ ```
725
+
726
+ Or save it from FinCLI:
727
+
728
+ ```text
729
+ /news_model key alphavantage <api_key>
730
+ ```
731
+
732
+ Alpha Vantage functions used:
733
+
734
+ ```text
735
+ GLOBAL_QUOTE
736
+ TIME_SERIES_DAILY_ADJUSTED
737
+ CURRENCY_EXCHANGE_RATE
738
+ FX_DAILY
739
+ NEWS_SENTIMENT
740
+ OVERVIEW
741
+ ```
742
+
743
+ Alpha Vantage is useful as an additional stocks/FX adapter. Free plans are rate-limited, and realtime/delayed availability depends on provider plan and exchange coverage.
744
+
745
+ ## Provider Commands
746
+
747
+ ```text
748
+ /news_model
749
+ /provider list
750
+ /provider status
751
+ /provider test AAPL
752
+ /provider test finnhub AAPL
753
+ /provider key status
754
+ ```
755
+
756
+ `/news_model` is the main TUI flow for selecting market/news providers and fallback priority. `/provider status` shows the active provider, fallback chain, and health message. `/provider test <symbol>` tests the active provider. `/provider test <provider> <symbol>` tests a specific provider without changing the active provider.
757
+
758
+ Manual commands such as `/provider use ...` and `/provider priority ...` are still available as advanced CLI fallback commands, but they are not the primary command-palette flow.
759
+
760
+ Example fallback chain saved by the selector:
761
+
762
+ ```text
763
+ twelvedata -> finnhub -> custom -> yfinance
764
+ ```
765
+
766
+ With this chain, FinCLI tries Twelve Data first. If it fails, it tries the next provider and finally uses delayed yfinance fallback.
767
+
768
+ ## Symbol Search and Normalization
769
+
770
+ ```text
771
+ /symbol apple
772
+ /symbol XAUUSD
773
+ /symbol normalize EURUSD
774
+ /symbol normalize BBRI
775
+ ```
776
+
777
+ `/symbol` searches the local symbol catalog and displays provider-specific symbol mappings for yfinance, Twelve Data, Finnhub, and custom providers. `/symbol normalize <symbol>` works for any input and shows how FinCLI will normalize the symbol before sending it to each provider.
778
+
779
+ Examples:
780
+
781
+ ```text
782
+ EURUSD -> EURUSD=X for yfinance, EUR/USD for Twelve Data, OANDA:EUR_USD for Finnhub
783
+ XAUUSD -> XAUUSD=X for yfinance, XAU/USD for Twelve Data
784
+ BBRI -> BBRI.JK for yfinance
785
+ ```
786
+
787
+ Normalization does not guarantee provider entitlement. Check `/provider entitlement` and your provider plan for realtime/delayed access and supported exchanges.
788
+
789
+ ## Custom Market Provider
790
+
791
+ Open the provider selector:
792
+
793
+ ```text
794
+ /news_model
795
+ ```
796
+
797
+ Environment variables:
798
+
799
+ ```env
800
+ MARKET_DATA_API_KEY=your-key
801
+ MARKET_DATA_BASE_URL=https://your-market-api.example.com
802
+ ```
803
+
804
+ Or save from FinCLI:
805
+
806
+ ```text
807
+ /news_model key custom <api_key> https://your-market-api.example.com
808
+ ```
809
+
810
+ FinCLI calls:
811
+
812
+ ```text
813
+ GET /quote/{symbol}
814
+ GET /history/{symbol}?period=6mo&interval=1d
815
+ GET /news/{symbol}?limit=5
816
+ GET /fundamentals/{symbol}
817
+ ```
818
+
819
+ Headers are sent as `X-API-Key` and `Authorization: Bearer <key>`. API keys are not displayed in the terminal.
820
+
821
+ Quote payload example:
822
+
823
+ ```json
824
+ {
825
+ "symbol": "AAPL",
826
+ "price": 123.45,
827
+ "currency": "USD",
828
+ "timestamp": "2026-06-04T12:00:00",
829
+ "status": "realtime"
830
+ }
831
+ ```
832
+
833
+ ## Local Storage
834
+
835
+ FinCLI stores local data at:
836
+
837
+ ```text
838
+ ~/.fincli/config.json
839
+ ~/.fincli/fincli.db
840
+ ~/.fincli/fincli.log
841
+ ~/.fincli/secrets.env
842
+ ```
843
+
844
+ API keys are not stored in command output. For global npm installs, the main setup path is:
845
+
846
+ ```text
847
+ /ai_model key groq <api_key>
848
+ /news_model key twelvedata <api_key>
849
+ ```
850
+
851
+ Keys are stored in `~/.fincli/secrets.env`, automatically loaded for future FinCLI sessions, and do not need to be configured again. If a local `.env` contains an empty value, FinCLI still uses the saved local secret.
852
+
853
+ ## Security Notes
854
+
855
+ - Do not commit `.env`.
856
+ - Do not publish `~/.fincli/secrets.env`.
857
+ - FinCLI masks keys in `/config` and `/provider key status`.
858
+ - Session history redacts `/ai_model key ...` and `/news_model key ...` commands.
859
+ - If an API key was ever exposed in a screenshot, npm package, log, or public repository, revoke and rotate it from the provider dashboard.
860
+
861
+ ## Test
862
+
863
+ ```bash
864
+ pytest
865
+ ```
866
+
867
+ Latest local verification:
868
+
869
+ ```text
870
+ 113 passed
871
+ ```
872
+
873
+ NPM wrapper check:
874
+
875
+ ```bash
876
+ npm run check
877
+ npm pack --dry-run
878
+ ```
879
+
880
+ ## Troubleshooting
881
+
882
+ - `fincli` is not recognized: reinstall with `pip install -e .`, `pipx install .`, or `npm install -g .` from the project root.
883
+ - The TUI looks cramped: increase terminal size.
884
+ - API key is not detected: use `/ai_model key <provider> <api_key>` or `/news_model key <provider> <api_key>`, then check `/config` or `/provider key status`.
885
+ - `/quote` fails because yfinance is missing: run `pip install -e ".[dev]"` or `pip install -r requirements.txt`.
886
+ - Config is corrupted: delete `~/.fincli/config.json` to return to defaults.
887
+ - Market data fails for a symbol: check the symbol format for the active provider and try `/provider test <symbol>`.
888
+
889
+ ## Roadmap v0.2
890
+
891
+ - More provider adapters. Alpha Vantage started in v0.2.0.
892
+ - Symbol search and provider-specific symbol normalization UI. Started in v0.2.0 through `/symbol`.
893
+ - Economic calendar improvements. Summary counts and export started in v0.2.0.
894
+ - Screener and scanner export. Scanner export started in v0.2.0 through `/scan export`.
895
+ - Lightweight backtesting. Started in v0.2.0 through `/backtest`.
896
+ - Alert system. Started in v0.2.0 through local price alerts and `/alert check`.
897
+ - Exportable market reports. Started in v0.2.0 through `/report market`.
898
+ - Multi-timeframe analysis. Started in v0.2.0 through `/mtf`.
899
+ - Stronger custom provider schema validation. Started in v0.2.0.
900
+ - Provider entitlement handling and realtime/delayed labeling improvements. Started in v0.2.0 through `/provider entitlement`.
901
+
902
+ ## Roadmap v0.3
903
+
904
+ - Plugin system.
905
+ - Strategy builder.
906
+ - Advanced portfolio analytics.
907
+ - Notification integrations.
908
+ - Optional cloud sync.
909
+ - Realtime streaming where supported by provider plans.