@muhammedaksam/borsats 0.10.1 β 0.11.0
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.
- package/README.md +386 -149
- package/dist/cli.cjs +26 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +26 -0
- package/dist/index.cjs +20 -4
- package/dist/index.d.cts +365 -86
- package/dist/index.d.ts +365 -86
- package/dist/index.js +20 -4
- package/package.json +17 -14
package/README.md
CHANGED
|
@@ -11,21 +11,26 @@
|
|
|
11
11
|
>
|
|
12
12
|
> This library is for personal and educational use only. It cannot be used for developing commercial software products, commercial services, or any commercial purposes. For commercial use, you must contact Borsa Istanbul to purchase an appropriate license.
|
|
13
13
|
|
|
14
|
-
Turkish financial markets data library for TypeScript/JavaScript. A yfinance-like API for BIST stocks, forex, crypto, investment funds, and
|
|
14
|
+
Turkish financial markets data library and CLI for TypeScript/JavaScript. A yfinance-like API for BIST stocks, forex, crypto, investment & pension funds, bonds, Eurobonds, TCMB rates, EVDS macro data, technical analysis, scanning, backtesting, and real-time streaming.
|
|
15
15
|
|
|
16
|
-
**
|
|
16
|
+
**Aligned with [borsapy](https://github.com/saidsurucu/borsapy/) v0.11.0** β bringing full feature parity to the TypeScript ecosystem.
|
|
17
17
|
|
|
18
18
|
## Features
|
|
19
19
|
|
|
20
|
-
- π **BIST Stocks** -
|
|
21
|
-
- π± **65+ Currencies**
|
|
22
|
-
- πͺ **Cryptocurrencies**
|
|
23
|
-
- π¦ **Investment Funds**
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
20
|
+
- π **BIST Stocks (`Ticker`, `Tickers`, `download`)** β Quotes, OHLCV history (split-adjusted, unadjusted, and dividend-adjusted `adjClose`), parametric financial statements (`lastN`), TTM statements, dividends, splits, analyst recommendations & price targets, KAP disclosures, ETF holders, ISIN
|
|
21
|
+
- π± **65+ Currencies & Commodities (`FX`)** β Live rates, bank rates, precious metal dealer rates, institution history, intraday TradingView data
|
|
22
|
+
- πͺ **Cryptocurrencies (`Crypto`)** β BtcTurk TRY/USDT pairs, quotes, OHLCV history, TradingView TA signals
|
|
23
|
+
- π¦ **Investment, Pension & ETF Funds (`Fund`)** β TEFAS v2 JSON API (`YAT`, `EMK`, `BYF`), profile info, NAV history, portfolio asset allocation & allocation history, screening, comparison, management fees, risk metrics, withholding tax (stopaj) schedule, and KAP PDF holdings parsing via OpenRouter LLM
|
|
24
|
+
- ποΈ **EVDS (`EVDS`, `EVDSSeries`)** β TCMB Electronic Data Delivery System (145 categories, series search, multi-series download, dashboards, formulas, automatic pagination)
|
|
25
|
+
- π **79 BIST Indices (`Index`)** β Quotes, OHLCV history, constituent stocks, participation indices, index scanning
|
|
26
|
+
- π **Technical Analysis (`TechnicalAnalyzer`, `TechnicalMixin`)** β SMA, EMA, WMA, DEMA, TEMA, Tilson T3, RSI, MACD, Bollinger Bands, ATR, Stochastic, OBV, VWAP, ADX, Supertrend, HHV, LLV, MOM, ROC, CCI, Williams %R, Pivot Points, Ichimoku, Heikin Ashi, and TradingView TA signals across all 6 asset classes
|
|
27
|
+
- π **Stock Screener & Technical Scanner (`Screener`, `TechnicalScanner`)** β Fundamental screening (Δ°Ε YatΔ±rΔ±m templates & criteria) and fast native TradingView technical scanning with parallel local calculation for Supertrend & Tilson T3
|
|
28
|
+
- π§ͺ **Backtesting & Historical Replay (`BacktestEngine`, `ReplaySession`)** β Strategy backtesting with commissions, slippage, Sharpe/Sortino/Calmar ratios, drawdown curves, and candle-by-candle replay
|
|
29
|
+
- πΌ **Portfolio Management (`Portfolio`)** β Multi-asset holdings (`stock`, `fx`, `crypto`, `fund`), `purchaseDate` tracking, multi-asset history & correlation matrix, risk metrics (Sharpe, Sortino, Beta, Alpha), drift analysis, and automated rebalancing
|
|
30
|
+
- β‘ **Real-Time Streaming (`TradingViewStream`, `StudySession`)** β Persistent WebSocket quotes, live OHLCV candles, Pine Script studies, and auto-reconnection
|
|
31
|
+
- π§Ύ **Fixed Income, Macro & Derivatives** β Turkish Government Bonds (`Bond`, `riskFreeRate`), Sovereign Eurobonds (`Eurobond` + daily history), TCMB Policy/Overnight/GLP rates (`TCMB`), Inflation TΓFE/ΓFE (`Inflation`), VIOP Futures & Options (`VIOP`), Economic Calendar (`EconomicCalendar`)
|
|
32
|
+
- π¦ **Twitter/X Tweet Search (`searchTweets`, `.tweets()`)** β Cookie-authenticated search with built-in Turkish asset query builders on `Ticker`, `Fund`, `FX`, and `Crypto`
|
|
33
|
+
- π» **CLI (`borsats`)** β 27 terminal commands with `table`, `json`, and `csv` output formats
|
|
29
34
|
|
|
30
35
|
## Installation
|
|
31
36
|
|
|
@@ -44,31 +49,87 @@ pnpm add @muhammedaksam/borsats
|
|
|
44
49
|
## Quick Start
|
|
45
50
|
|
|
46
51
|
```typescript
|
|
47
|
-
import {
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
import {
|
|
53
|
+
Crypto,
|
|
54
|
+
download,
|
|
55
|
+
EVDS,
|
|
56
|
+
evdsSeries,
|
|
57
|
+
Fund,
|
|
58
|
+
FX,
|
|
59
|
+
Inflation,
|
|
60
|
+
setEVDSKey,
|
|
61
|
+
Ticker,
|
|
62
|
+
} from "@muhammedaksam/borsats";
|
|
63
|
+
|
|
64
|
+
// BIST Stock
|
|
50
65
|
const stock = new Ticker("THYAO");
|
|
51
|
-
console.log(await stock.info); //
|
|
66
|
+
console.log(await stock.info()); // Enriched quote & company info
|
|
52
67
|
console.log(await stock.history({ period: "1mo" })); // OHLCV data
|
|
53
|
-
console.log(await stock.balanceSheet); //
|
|
68
|
+
console.log(await stock.balanceSheet); // Annual balance sheet
|
|
69
|
+
|
|
70
|
+
// Batch download
|
|
71
|
+
const multi = await download(["THYAO", "GARAN", "AKBNK"], { period: "1mo" });
|
|
54
72
|
|
|
55
|
-
// Forex
|
|
73
|
+
// Forex & Precious Metals
|
|
56
74
|
const usd = new FX("USD");
|
|
57
|
-
console.log(await usd.current);
|
|
58
|
-
console.log(await usd.
|
|
59
|
-
console.log(await usd.bankRates); // All bank rates
|
|
75
|
+
console.log(await usd.current);
|
|
76
|
+
console.log(await usd.bankRates);
|
|
60
77
|
|
|
61
78
|
// Cryptocurrency
|
|
62
79
|
const btc = new Crypto("BTCTRY");
|
|
63
|
-
console.log(await btc.current);
|
|
64
|
-
console.log(await btc.history({ period: "1mo" }));
|
|
80
|
+
console.log(await btc.current);
|
|
81
|
+
console.log(await btc.history({ period: "1mo" }));
|
|
65
82
|
|
|
66
|
-
//
|
|
83
|
+
// TEFAS Fund
|
|
67
84
|
const fund = new Fund("AAK");
|
|
68
|
-
console.log(await fund.info);
|
|
69
|
-
console.log(await fund.
|
|
85
|
+
console.log(await fund.info);
|
|
86
|
+
console.log(await fund.allocation);
|
|
87
|
+
|
|
88
|
+
// Inflation
|
|
89
|
+
const inflation = new Inflation();
|
|
90
|
+
console.log(await inflation.latest("tufe"));
|
|
91
|
+
|
|
92
|
+
// EVDS (TCMB macro time-series)
|
|
93
|
+
setEVDSKey("YOUR_EVDS_KEY"); // Free key: https://evds3.tcmb.gov.tr
|
|
94
|
+
console.log(await evdsSeries("TP.DK.USD.A.YTL", { period: "1y" }));
|
|
95
|
+
console.log(await new EVDS().categories); // No key required
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Command-Line Interface (CLI)
|
|
99
|
+
|
|
100
|
+
`borsats` ships with a 27-command CLI (`table`, `json`, or `csv` output):
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Quick prices for stocks, FX, crypto, funds, and indices
|
|
104
|
+
npx borsats price THYAO GARAN USD BTCTRY AAK XU100
|
|
105
|
+
|
|
106
|
+
# Export 1-year OHLCV history to CSV
|
|
107
|
+
npx borsats history THYAO --period 1y --output csv > thyao.csv
|
|
108
|
+
|
|
109
|
+
# TradingView TA signals
|
|
110
|
+
npx borsats signals THYAO --interval 1h
|
|
111
|
+
|
|
112
|
+
# Technical scan & fundamental screen
|
|
113
|
+
npx borsats scan "rsi < 30 and volume > 1000000" --index XU100
|
|
114
|
+
npx borsats screen --template high_dividend --index XU030
|
|
115
|
+
|
|
116
|
+
# Bonds, TCMB rates, Eurobonds, TEFAS funds, VIOP, and economic calendar
|
|
117
|
+
npx borsats bonds
|
|
118
|
+
npx borsats tcmb --history --period 1y
|
|
119
|
+
npx borsats fund AAK --allocation
|
|
120
|
+
npx borsats economic --country TR
|
|
121
|
+
|
|
122
|
+
# Live quote watch
|
|
123
|
+
npx borsats watch THYAO GARAN --duration 10
|
|
124
|
+
|
|
125
|
+
# See all 27 commands
|
|
126
|
+
npx borsats --help
|
|
70
127
|
```
|
|
71
128
|
|
|
129
|
+
Supported commands: `auth`, `price`, `quote`, `search`, `history`, `scan`, `screen`, `technical`, `compare`, `watch`, `economic`, `news`, `dividends`, `splits`, `companies`, `bonds`, `tcmb`, `inflation`, `fund`, `eurobond`, `index`, `financials`, `signals`, `holders`, `targets`, `fx-rates`, `viop`.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
72
133
|
## Documentation
|
|
73
134
|
|
|
74
135
|
### Ticker (BIST Stocks)
|
|
@@ -78,71 +139,94 @@ import { Ticker } from "@muhammedaksam/borsats";
|
|
|
78
139
|
|
|
79
140
|
const stock = new Ticker("THYAO");
|
|
80
141
|
|
|
81
|
-
// Fast info (
|
|
82
|
-
const
|
|
83
|
-
console.log(
|
|
84
|
-
console.log(
|
|
85
|
-
console.log(
|
|
142
|
+
// Fast info (parallel quote + metrics + 52w/MA calculations)
|
|
143
|
+
const fi = stock.fastInfo;
|
|
144
|
+
console.log(await fi.lastPrice);
|
|
145
|
+
console.log(await fi.marketCap);
|
|
146
|
+
console.log(await fi.peRatio);
|
|
147
|
+
console.log(await fi.freeFloat);
|
|
148
|
+
console.log(await fi.foreignRatio);
|
|
86
149
|
|
|
87
150
|
// Detailed info
|
|
88
|
-
const info = await stock.info;
|
|
89
|
-
console.log(info.last);
|
|
90
|
-
console.log(info.trailingPE);
|
|
91
|
-
console.log(info.dividendYield);
|
|
151
|
+
const info = await stock.info();
|
|
152
|
+
console.log(info.last, info.peRatio, info.dividendYield, info.sector);
|
|
92
153
|
|
|
93
|
-
// Historical
|
|
154
|
+
// Historical OHLCV
|
|
94
155
|
const history = await stock.history({
|
|
95
156
|
period: "1y",
|
|
96
157
|
interval: "1d",
|
|
97
|
-
actions: true, // Include dividends
|
|
158
|
+
actions: true, // Include dividends & splits
|
|
159
|
+
adjust: true, // Set false for raw split-unadjusted prices
|
|
160
|
+
autoAdjust: true, // Adds yfinance-style dividend-adjusted `adjClose`
|
|
98
161
|
});
|
|
99
162
|
|
|
100
|
-
// Financial statements
|
|
163
|
+
// Financial statements (annual, quarterly, TTM, and parametric lastN)
|
|
101
164
|
const balanceSheet = await stock.balanceSheet;
|
|
102
165
|
const incomeStmt = await stock.incomeStmt;
|
|
103
166
|
const cashflow = await stock.cashflow;
|
|
104
|
-
|
|
105
|
-
// Quarterly statements
|
|
106
167
|
const qBalanceSheet = await stock.quarterlyBalanceSheet;
|
|
107
|
-
const
|
|
168
|
+
const ttmIncome = await stock.ttmIncomeStmt;
|
|
169
|
+
const tenYears = await stock.getIncomeStmt({ lastN: 10 });
|
|
170
|
+
const allQuarters = await stock.getBalanceSheet({
|
|
171
|
+
quarterly: true,
|
|
172
|
+
lastN: "all",
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Banks use financialGroup: "UFRS"
|
|
176
|
+
const bank = new Ticker("AKBNK");
|
|
177
|
+
const bankBS = await bank.getBalanceSheet({ financialGroup: "UFRS" });
|
|
108
178
|
|
|
109
|
-
// Corporate actions
|
|
179
|
+
// Corporate actions, holders, analyst data, and KAP disclosures
|
|
110
180
|
const dividends = await stock.dividends;
|
|
111
181
|
const splits = await stock.splits;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
182
|
+
const actions = await stock.actions;
|
|
183
|
+
const majorHolders = await stock.majorHolders;
|
|
184
|
+
const etfHolders = await stock.etfHolders;
|
|
185
|
+
const recommendations = await stock.recommendations; // { recommendation, target_price, upside_potential }
|
|
186
|
+
const recSummary = await stock.recommendationsSummary; // { strongBuy, buy, hold, sell, strongSell }
|
|
187
|
+
const targets = await stock.analystPriceTargets; // Alias of stock.priceTarget
|
|
115
188
|
const news = await stock.news;
|
|
189
|
+
const calendar = await stock.calendar;
|
|
190
|
+
const earningsDates = await stock.earningsDates;
|
|
191
|
+
const isin = await stock.isin;
|
|
116
192
|
```
|
|
117
193
|
|
|
118
|
-
###
|
|
194
|
+
### Multi-Ticker Batch Download
|
|
119
195
|
|
|
120
196
|
```typescript
|
|
121
|
-
import {
|
|
197
|
+
import { download, Tickers } from "@muhammedaksam/borsats";
|
|
122
198
|
|
|
123
|
-
const
|
|
199
|
+
const tickers = new Tickers(["THYAO", "GARAN", "AKBNK"]);
|
|
200
|
+
const multiHist = await tickers.history({ period: "1mo", groupBy: "ticker" });
|
|
124
201
|
|
|
125
|
-
|
|
126
|
-
|
|
202
|
+
const data = await download(["THYAO", "ASELS"], {
|
|
203
|
+
period: "3mo",
|
|
204
|
+
interval: "1d",
|
|
205
|
+
});
|
|
206
|
+
```
|
|
127
207
|
|
|
128
|
-
|
|
129
|
-
console.log(await usd.history({ period: "1mo" }));
|
|
208
|
+
### FX (Forex, Precious Metals & Commodities)
|
|
130
209
|
|
|
131
|
-
|
|
132
|
-
|
|
210
|
+
```typescript
|
|
211
|
+
import { banks, FX, metalInstitutions } from "@muhammedaksam/borsats";
|
|
133
212
|
|
|
134
|
-
|
|
135
|
-
console.log(await usd.
|
|
136
|
-
console.log(await usd.
|
|
213
|
+
const usd = new FX("USD");
|
|
214
|
+
console.log(await usd.current);
|
|
215
|
+
console.log(await usd.history({ period: "1mo" }));
|
|
216
|
+
console.log(await usd.history({ period: "1d", interval: "5m" })); // Intraday via TradingView
|
|
137
217
|
|
|
138
|
-
//
|
|
139
|
-
console.log(
|
|
218
|
+
// Bank rates
|
|
219
|
+
console.log(await usd.bankRates);
|
|
220
|
+
console.log(await usd.bankRate("akbank"));
|
|
221
|
+
console.log(banks()); // or FX.banks()
|
|
140
222
|
|
|
141
|
-
// Precious metals
|
|
223
|
+
// Precious metals & dealer/institution rates
|
|
142
224
|
const gold = new FX("gram-altin");
|
|
143
225
|
console.log(await gold.current);
|
|
144
|
-
console.log(await gold.institutionRates);
|
|
145
|
-
console.log(await gold.institutionRate("kapalicarsi"));
|
|
226
|
+
console.log(await gold.institutionRates());
|
|
227
|
+
console.log(await gold.institutionRate("kapalicarsi"));
|
|
228
|
+
console.log(await gold.institutionHistory("akbank", { period: "1mo" }));
|
|
229
|
+
console.log(metalInstitutions()); // or FX.metalInstitutions()
|
|
146
230
|
|
|
147
231
|
// Commodities
|
|
148
232
|
const brent = new FX("BRENT");
|
|
@@ -154,18 +238,16 @@ const silver = new FX("XAG-USD");
|
|
|
154
238
|
```typescript
|
|
155
239
|
import { allIndices, Index, indices } from "@muhammedaksam/borsats";
|
|
156
240
|
|
|
157
|
-
//
|
|
158
|
-
console.log(indices()); //
|
|
159
|
-
console.log(allIndices()); // All 79 indices
|
|
241
|
+
console.log(await indices()); // Popular indices
|
|
242
|
+
console.log(await indices(true)); // Detailed with component counts
|
|
243
|
+
console.log(await allIndices()); // All 79 BIST indices
|
|
160
244
|
|
|
161
|
-
// Index data
|
|
162
245
|
const xu100 = new Index("XU100");
|
|
163
|
-
console.log(await xu100.info);
|
|
164
|
-
console.log(await xu100.history({ period: "1y" }));
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
console.log(await xu100.
|
|
168
|
-
console.log(await xu100.componentSymbols); // Just symbols
|
|
246
|
+
console.log(await xu100.info);
|
|
247
|
+
console.log(await xu100.history({ period: "1y" }));
|
|
248
|
+
console.log(await xu100.components);
|
|
249
|
+
console.log(await xu100.componentSymbols());
|
|
250
|
+
console.log(await xu100.scan("rsi < 30", { interval: "1d" }));
|
|
169
251
|
```
|
|
170
252
|
|
|
171
253
|
### Crypto (Cryptocurrency)
|
|
@@ -173,119 +255,274 @@ console.log(await xu100.componentSymbols); // Just symbols
|
|
|
173
255
|
```typescript
|
|
174
256
|
import { Crypto, cryptoPairs } from "@muhammedaksam/borsats";
|
|
175
257
|
|
|
176
|
-
|
|
177
|
-
console.log(await cryptoPairs());
|
|
258
|
+
console.log(await cryptoPairs("TRY"));
|
|
178
259
|
|
|
179
|
-
// Crypto data
|
|
180
260
|
const btc = new Crypto("BTCTRY");
|
|
181
|
-
console.log(await btc.current);
|
|
182
|
-
console.log(await btc.history({ period: "1mo" }));
|
|
261
|
+
console.log(await btc.current);
|
|
262
|
+
console.log(await btc.history({ period: "1mo", interval: "1d" }));
|
|
263
|
+
console.log(await btc.taSignals("1h"));
|
|
183
264
|
```
|
|
184
265
|
|
|
185
|
-
### Fund (Investment Funds)
|
|
266
|
+
### Fund (TEFAS Investment, Pension & ETF Funds)
|
|
186
267
|
|
|
187
268
|
```typescript
|
|
188
|
-
import {
|
|
269
|
+
import {
|
|
270
|
+
compareFunds,
|
|
271
|
+
Fund,
|
|
272
|
+
managementFees,
|
|
273
|
+
screenFunds,
|
|
274
|
+
searchFunds,
|
|
275
|
+
withholdingTaxRate,
|
|
276
|
+
withholdingTaxTable,
|
|
277
|
+
} from "@muhammedaksam/borsats";
|
|
278
|
+
|
|
279
|
+
// Search, screen, compare & fees
|
|
280
|
+
console.log(await searchFunds("banka", 10));
|
|
281
|
+
console.log(await screenFunds({ fundType: "YAT", minReturn1y: 50 }));
|
|
282
|
+
console.log(await compareFunds(["AAK", "TTE", "AFO"]));
|
|
283
|
+
console.log(await managementFees("YAT"));
|
|
284
|
+
|
|
285
|
+
// Fund details, history, allocation & risk (supports YAT, EMK, BYF with auto-detection)
|
|
286
|
+
const fund = new Fund("AAK");
|
|
287
|
+
console.log(await fund.fundType); // "YAT" | "EMK" | "BYF"
|
|
288
|
+
console.log(await fund.info); // Includes ISIN, KAP link, valor, fees, category rank
|
|
289
|
+
console.log(await fund.history({ period: "1y" })); // Up to 5y via TEFAS v2 JSON API
|
|
290
|
+
console.log(await fund.allocation); // Latest portfolio asset breakdown
|
|
291
|
+
console.log(await fund.allocationHistory({ period: "2mo" })); // Up to 3mo
|
|
292
|
+
console.log(await fund.managementFee);
|
|
293
|
+
console.log(await fund.riskMetrics("1y")); // Sharpe, Sortino, volatility, max drawdown
|
|
294
|
+
|
|
295
|
+
// Withholding tax (Turkish Stopaj schedule)
|
|
296
|
+
console.log(await fund.taxCategory); // e.g., "degisken_karma_doviz"
|
|
297
|
+
console.log(await fund.withholdingTaxRate("2025-08-01")); // 0.175 (17.5%)
|
|
298
|
+
console.log(await withholdingTaxRate("TTE", "2025-08-01")); // 0.0 (equity-heavy)
|
|
299
|
+
console.log(withholdingTaxTable());
|
|
300
|
+
|
|
301
|
+
// Individual stock holdings from KAP "PortfΓΆy DaΔΔ±lΔ±m Raporu" PDF via OpenRouter LLM
|
|
302
|
+
const holdings = await fund.getHoldings(process.env.OPENROUTER_API_KEY!);
|
|
303
|
+
```
|
|
189
304
|
|
|
190
|
-
|
|
191
|
-
console.log(await searchFunds("banka"));
|
|
305
|
+
### EVDS (TCMB Electronic Data Delivery System)
|
|
192
306
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
307
|
+
```typescript
|
|
308
|
+
import {
|
|
309
|
+
EVDS,
|
|
310
|
+
evdsCategories,
|
|
311
|
+
evdsDownload,
|
|
312
|
+
evdsSearch,
|
|
313
|
+
evdsSeries,
|
|
314
|
+
setEVDSKey,
|
|
315
|
+
} from "@muhammedaksam/borsats";
|
|
316
|
+
|
|
317
|
+
// Catalogue & search (no API key needed)
|
|
318
|
+
console.log(await evdsCategories());
|
|
319
|
+
console.log(await evdsSearch("dolar"));
|
|
320
|
+
|
|
321
|
+
// Time-series data (free key from https://evds3.tcmb.gov.tr or EVDS_API_KEY env var)
|
|
322
|
+
setEVDSKey("YOUR_EVDS_KEY");
|
|
323
|
+
const usdTry = await evdsSeries("TP.DK.USD.A.YTL", { period: "1y" });
|
|
324
|
+
const cpiYoY = await evdsSeries("TP.FG.J0", {
|
|
325
|
+
period: "2y",
|
|
326
|
+
formula: "yoy_pct",
|
|
327
|
+
});
|
|
328
|
+
const multi = await evdsDownload(["TP.DK.USD.A.YTL", "TP.DK.EUR.A.YTL"], {
|
|
329
|
+
period: "6mo",
|
|
330
|
+
});
|
|
200
331
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
console.log(await
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
332
|
+
const evds = new EVDS();
|
|
333
|
+
console.log(await evds.datagroups(2));
|
|
334
|
+
console.log(await evds.dashboard("enflasyon"));
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Technical Analysis, Scanner & Screener
|
|
338
|
+
|
|
339
|
+
All 6 asset classes (`Ticker`, `FX`, `Crypto`, `Index`, `Fund`, `Portfolio`) extend `TechnicalMixin`:
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
import { scan, screenStocks, Screener, TechnicalScanner, Ticker } from "@muhammedaksam/borsats";
|
|
343
|
+
|
|
344
|
+
const stock = new Ticker("THYAO");
|
|
345
|
+
console.log(await stock.rsi("3mo", 14));
|
|
346
|
+
console.log(await stock.sma("3mo", 50));
|
|
347
|
+
console.log(await stock.supertrend("3mo"));
|
|
348
|
+
console.log(await stock.tilsonT3("3mo"));
|
|
349
|
+
console.log(await stock.taSignals("1d"));
|
|
350
|
+
|
|
351
|
+
const ta = await stock.technicals("1y");
|
|
352
|
+
console.log(ta.latest);
|
|
353
|
+
console.log(ta.all({ indicators: ["sma", "rsi", "macd", "supertrend"] }));
|
|
354
|
+
|
|
355
|
+
// Technical scanner (TradingView native API + parallel local Supertrend/T3)
|
|
356
|
+
const oversold = await scan("XU030", "rsi < 30 and volume > 1000000", "1d");
|
|
357
|
+
const scanner = new TechnicalScanner();
|
|
358
|
+
await scanner.setUniverse("XU100");
|
|
359
|
+
scanner.addCondition("close crosses_above sma_50");
|
|
360
|
+
console.log(await scanner.run(25));
|
|
361
|
+
|
|
362
|
+
// Fundamental screener (Δ°Ε YatΔ±rΔ±m)
|
|
363
|
+
const highDiv = await screenStocks({
|
|
364
|
+
template: "high_dividend",
|
|
365
|
+
index: "XU030",
|
|
366
|
+
pe_max: 10,
|
|
367
|
+
});
|
|
368
|
+
const screener = new Screener().setIndex("XU100").addFilter("roe", 20);
|
|
369
|
+
console.log(await screener.run());
|
|
208
370
|
```
|
|
209
371
|
|
|
210
|
-
### Portfolio Management
|
|
372
|
+
### Portfolio Management & Rebalancing
|
|
211
373
|
|
|
212
374
|
```typescript
|
|
213
375
|
import { Portfolio } from "@muhammedaksam/borsats";
|
|
214
376
|
|
|
215
|
-
const portfolio = new Portfolio();
|
|
377
|
+
const portfolio = new Portfolio("XU100");
|
|
216
378
|
|
|
217
|
-
// Add holdings
|
|
218
379
|
portfolio
|
|
219
|
-
.add("THYAO", { shares: 100, cost: 280 })
|
|
380
|
+
.add("THYAO", { shares: 100, cost: 280, purchaseDate: "2024-01-15" })
|
|
220
381
|
.add("GARAN", { shares: 200, cost: 50 })
|
|
221
382
|
.add("USD", { shares: 1000, assetType: "fx" })
|
|
222
|
-
.add("gram-altin", { shares: 10, assetType: "fx" })
|
|
223
383
|
.add("BTCTRY", { shares: 0.5 })
|
|
224
384
|
.add("AAK", { shares: 1000, assetType: "fund" });
|
|
225
385
|
|
|
226
|
-
|
|
227
|
-
portfolio.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
console.log(portfolio.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
console.log(portfolio.
|
|
234
|
-
console.log(portfolio.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
console.log(await portfolio.
|
|
240
|
-
console.log(await portfolio.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
386
|
+
console.log(await portfolio.value);
|
|
387
|
+
console.log(portfolio.cost);
|
|
388
|
+
console.log(await portfolio.pnl, await portfolio.pnlPct);
|
|
389
|
+
console.log(await portfolio.weights);
|
|
390
|
+
console.log(await portfolio.holdings);
|
|
391
|
+
|
|
392
|
+
// Multi-asset history, correlation matrix & risk metrics (incl. beta & alpha)
|
|
393
|
+
console.log(await portfolio.history("1y"));
|
|
394
|
+
console.log(await portfolio.correlationMatrix("1y"));
|
|
395
|
+
console.log(await portfolio.riskMetrics("1y"));
|
|
396
|
+
|
|
397
|
+
// Target weights, drift & rebalancing
|
|
398
|
+
portfolio.setTargetWeights({ THYAO: 0.4, GARAN: 0.3, USD: 0.3 });
|
|
399
|
+
console.log(await portfolio.drift());
|
|
400
|
+
console.log(await portfolio.rebalancePlan(5));
|
|
401
|
+
console.log(await portfolio.rebalance(5, false)); // Execute share adjustments
|
|
402
|
+
|
|
403
|
+
// Serialization
|
|
404
|
+
const snapshot = portfolio.toDict();
|
|
405
|
+
const restored = Portfolio.fromDict(snapshot);
|
|
245
406
|
```
|
|
246
407
|
|
|
247
|
-
###
|
|
408
|
+
### Backtesting & Replay
|
|
248
409
|
|
|
249
410
|
```typescript
|
|
250
|
-
import {
|
|
411
|
+
import { backtest, createReplay } from "@muhammedaksam/borsats";
|
|
412
|
+
|
|
413
|
+
const result = await backtest(
|
|
414
|
+
"THYAO",
|
|
415
|
+
(candle, position, indicators) => {
|
|
416
|
+
if (position === null && indicators.rsi < 30) return "BUY";
|
|
417
|
+
if (position === "long" && indicators.rsi > 70) return "SELL";
|
|
418
|
+
return "HOLD";
|
|
419
|
+
},
|
|
420
|
+
{ period: "1y", capital: 100000, commission: 0.001, slippage: 0.0005 },
|
|
421
|
+
);
|
|
422
|
+
console.log(result.summary());
|
|
423
|
+
console.log(result.toDict());
|
|
251
424
|
|
|
252
|
-
const
|
|
425
|
+
const replay = await createReplay("THYAO", { period: "1mo", speed: 0 });
|
|
426
|
+
for await (const candle of replay.replay()) {
|
|
427
|
+
console.log(candle.date, candle.close);
|
|
428
|
+
}
|
|
429
|
+
```
|
|
253
430
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
console.log(ta.latest); // All indicators at once
|
|
264
|
-
console.log(ta.rsi()); // Full RSI series
|
|
265
|
-
console.log(ta.macd()); // Full MACD series
|
|
266
|
-
|
|
267
|
-
// History with indicators
|
|
268
|
-
const df = await stock.historyWithIndicators({
|
|
269
|
-
period: "3mo",
|
|
270
|
-
indicators: ["sma", "rsi", "macd"],
|
|
431
|
+
### Real-Time Streaming & TradingView Auth
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
import { createStream, setTradingViewAuth } from "@muhammedaksam/borsats";
|
|
435
|
+
|
|
436
|
+
// Optional: authenticate for real-time BIST prices (removes ~15 min delay)
|
|
437
|
+
await setTradingViewAuth({
|
|
438
|
+
session: "YOUR_SESSIONID_COOKIE",
|
|
439
|
+
sessionSign: "YOUR_SESSIONID_SIGN_COOKIE",
|
|
271
440
|
});
|
|
441
|
+
|
|
442
|
+
const stream = createStream();
|
|
443
|
+
await stream.connect();
|
|
444
|
+
stream.subscribeMultiple(["THYAO", "GARAN"]);
|
|
445
|
+
stream.onQuote("THYAO", (quote) => console.log("THYAO:", quote.lp));
|
|
446
|
+
|
|
447
|
+
// Live chart candles & Pine Script studies
|
|
448
|
+
stream.subscribeChart("THYAO", "1m");
|
|
449
|
+
await stream.addStudy("THYAO", "1m", "RSI");
|
|
450
|
+
stream.onStudy("THYAO", "1m", "RSI", (vals) => console.log("RSI:", vals));
|
|
272
451
|
```
|
|
273
452
|
|
|
274
|
-
|
|
453
|
+
### Fixed Income, Macro, VIOP, Calendar & Search
|
|
275
454
|
|
|
276
|
-
|
|
455
|
+
```typescript
|
|
456
|
+
import {
|
|
457
|
+
Bond,
|
|
458
|
+
bonds,
|
|
459
|
+
companies,
|
|
460
|
+
EconomicCalendar,
|
|
461
|
+
Eurobond,
|
|
462
|
+
eurobonds,
|
|
463
|
+
Inflation,
|
|
464
|
+
policyRate,
|
|
465
|
+
riskFreeRate,
|
|
466
|
+
search,
|
|
467
|
+
TCMB,
|
|
468
|
+
VIOP,
|
|
469
|
+
viopContracts,
|
|
470
|
+
} from "@muhammedaksam/borsats";
|
|
471
|
+
|
|
472
|
+
// Government Bonds & Risk-Free Rate
|
|
473
|
+
console.log(await bonds());
|
|
474
|
+
console.log(await new Bond("10Y").yieldRate);
|
|
475
|
+
console.log(await riskFreeRate());
|
|
476
|
+
|
|
477
|
+
// Sovereign Eurobonds & Daily History
|
|
478
|
+
console.log(await eurobonds("USD"));
|
|
479
|
+
const eb = new Eurobond("US900123AL40");
|
|
480
|
+
console.log(await eb.info());
|
|
481
|
+
console.log(await eb.history({ period: "1mo" }));
|
|
482
|
+
|
|
483
|
+
// TCMB Rates & Inflation
|
|
484
|
+
console.log(await policyRate());
|
|
485
|
+
console.log(await new TCMB().history("policy", "1y"));
|
|
486
|
+
console.log(await new Inflation().calculate(100000, "2020-01", "2025-01"));
|
|
487
|
+
|
|
488
|
+
// VIOP, Economic Calendar, Companies & Unified Search
|
|
489
|
+
console.log(await new VIOP().futures);
|
|
490
|
+
console.log(await viopContracts("XU030", true));
|
|
491
|
+
console.log(await new EconomicCalendar().thisWeek({ country: "TR" }));
|
|
492
|
+
console.log(await companies());
|
|
493
|
+
console.log(await search("banka", { exchange: "BIST", limit: 10 }));
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### Twitter/X Tweet Search
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
import {
|
|
500
|
+
FX,
|
|
501
|
+
searchTweets,
|
|
502
|
+
setTwitterAuth,
|
|
503
|
+
Ticker,
|
|
504
|
+
} from "@muhammedaksam/borsats";
|
|
505
|
+
|
|
506
|
+
// Authenticate with x.com browser cookies (auth_token & ct0)
|
|
507
|
+
setTwitterAuth({ authToken: "YOUR_AUTH_TOKEN", ct0: "YOUR_CT0" });
|
|
508
|
+
|
|
509
|
+
const tweets = await searchTweets("$THYAO", { period: "7d", lang: "tr", limit: 50 });
|
|
510
|
+
const stockTweets = await new Ticker("THYAO").tweets({ period: "3d" });
|
|
511
|
+
const usdTweets = await new FX("USD").tweets({ period: "1d", lang: "tr" });
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
## Environment Support
|
|
277
515
|
|
|
278
|
-
- **Node.js**: Full support
|
|
279
|
-
- **Browser**: Compatible when bundled (
|
|
516
|
+
- **Node.js (20+)**: Full support for all library modules, WebSocket streaming, and the `borsats` CLI.
|
|
517
|
+
- **Browser**: Compatible when bundled for CORS-accessible endpoints (server-side / Node.js recommended for direct scraping & WebSocket feeds).
|
|
280
518
|
|
|
281
|
-
## API Rate Limiting
|
|
519
|
+
## API Rate Limiting & Caching
|
|
282
520
|
|
|
283
|
-
|
|
521
|
+
Built-in per-provider rate limiting, retries, and TTL caching:
|
|
284
522
|
|
|
285
|
-
- Automatic retries
|
|
286
|
-
- Default: 60 requests
|
|
287
|
-
- Configurable per
|
|
288
|
-
- Response caching to reduce API calls
|
|
523
|
+
- Automatic exponential backoff retries on transient failures and HTTP 429 rate limits
|
|
524
|
+
- Default: 60 requests/minute per provider
|
|
525
|
+
- Configurable TTL caching per data domain (`REALTIME_PRICE`, `OHLCV_HISTORY`, `FINANCIAL_STATEMENTS`, `EVDS_CATALOG`, `EVDS_DATA`, `SOCIAL_DATA`, etc.)
|
|
289
526
|
|
|
290
527
|
## License
|
|
291
528
|
|
|
@@ -293,7 +530,7 @@ MIT Β© [Muhammed Mustafa AKΕAM](https://github.com/muhammedaksam)
|
|
|
293
530
|
|
|
294
531
|
## Credits
|
|
295
532
|
|
|
296
|
-
Inspired by and
|
|
533
|
+
Inspired by and aligned with [borsapy](https://github.com/saidsurucu/borsapy/) by Said SΓΌrΓΌcΓΌ.
|
|
297
534
|
|
|
298
535
|
## Contributing
|
|
299
536
|
|