borsajs 0.1.1 β†’ 0.1.4

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/test/demo.ts CHANGED
@@ -4,95 +4,168 @@
4
4
  */
5
5
  import { Crypto, cryptoPairs } from '../src/crypto.js';
6
6
  import { FX } from '../src/fx.js';
7
- import { Ticker } from '../src/ticker.js';
8
- import { Index, indices } from '../src/index-class.js';
9
7
  import { Fund, searchFunds } from '../src/fund.js';
8
+ import { Index, indices } from '../src/index-class.js';
10
9
  import { Inflation } from '../src/inflation.js';
10
+ import { Ticker } from '../src/ticker.js';
11
+ import { symbols, searchSymbols, cryptoSymbols, fxSymbols, indexSymbols } from '../src/market.js';
12
+ import { getKapProvider } from '../src/providers/kap.js';
11
13
 
12
14
  async function testCrypto() {
13
- console.log('\nπŸͺ™ Testing Crypto (BtcTurk)...');
14
- console.log('─'.repeat(50));
15
+ console.log('\nπŸͺ™ CRYPTO (BtcTurk)');
16
+ console.log('─'.repeat(60));
15
17
  try {
16
18
  const btc = new Crypto('BTCTRY');
17
19
  const current = await btc.getCurrent();
18
- console.log('BTC/TRY Current:', JSON.stringify(current, null, 2));
20
+ console.log('BTC/TRY:', JSON.stringify(current, null, 2));
21
+
19
22
  const pairs = await cryptoPairs('TRY');
20
- console.log(`\nAvailable TRY pairs: ${pairs.slice(0, 10).join(', ')}...`);
21
- } catch (error) { console.error('Crypto Error:', error); }
23
+ console.log(`\nAvailable pairs: ${pairs.slice(0, 10).join(', ')}... (${pairs.length} total)`);
24
+ } catch (error) { console.error('Error:', error); }
22
25
  }
23
26
 
24
27
  async function testFX() {
25
- console.log('\nπŸ’± Testing FX (doviz.com)...');
26
- console.log('─'.repeat(50));
28
+ console.log('\nπŸ’± FX (doviz.com)');
29
+ console.log('─'.repeat(60));
27
30
  try {
28
31
  const usd = new FX('USD');
29
32
  const current = await usd.getCurrent();
30
- console.log('USD/TRY Current:', JSON.stringify(current, null, 2));
33
+ console.log('USD/TRY:', JSON.stringify(current, null, 2));
34
+
31
35
  const gold = new FX('gram-altin');
32
36
  const goldCurrent = await gold.getCurrent();
33
- console.log('\nGold (gram) Current:', JSON.stringify(goldCurrent, null, 2));
34
- } catch (error) { console.error('FX Error:', error); }
37
+ console.log('\nGold (gram):', JSON.stringify(goldCurrent, null, 2));
38
+
39
+ console.log(`\nFX Symbols: ${fxSymbols.slice(0, 10).join(', ')}...`);
40
+ } catch (error) { console.error('Error:', error); }
35
41
  }
36
42
 
37
43
  async function testTicker() {
38
- console.log('\nπŸ“ˆ Testing Ticker (Paratic)...');
39
- console.log('─'.repeat(50));
44
+ console.log('\nπŸ“ˆ TICKER (Paratic)');
45
+ console.log('─'.repeat(60));
40
46
  try {
41
47
  const stock = new Ticker('THYAO');
42
48
  const info = await stock.getInfo();
43
- console.log('THYAO Info:', JSON.stringify(info, null, 2));
44
- } catch (error) { console.error('Ticker Error:', error); }
49
+ console.log('THYAO:', JSON.stringify(info, null, 2));
50
+
51
+ const history = await stock.getHistory({ period: '5d', interval: '1d' });
52
+ console.log(`\nHistory (5d): ${history.length} records`);
53
+ if (history.length > 0) console.log('Last:', JSON.stringify(history[history.length - 1], null, 2));
54
+ } catch (error) { console.error('Error:', error); }
45
55
  }
46
56
 
47
57
  async function testIndex() {
48
- console.log('\nπŸ“Š Testing Index (Paratic)...');
49
- console.log('─'.repeat(50));
58
+ console.log('\nπŸ“Š INDEX (Paratic)');
59
+ console.log('─'.repeat(60));
50
60
  try {
51
- console.log('Available indices:', indices().slice(0, 10).join(', '));
61
+ console.log('Index Symbols:', indexSymbols.slice(0, 10).join(', '));
62
+
52
63
  const xu100 = new Index('XU100');
53
64
  const info = await xu100.getInfo();
54
- console.log('\nXU100 Info:', JSON.stringify(info, null, 2));
55
- } catch (error) { console.error('Index Error:', error); }
65
+ console.log('\nXU100:', JSON.stringify(info, null, 2));
66
+ } catch (error) { console.error('Error:', error); }
56
67
  }
57
68
 
58
69
  async function testFund() {
59
- console.log('\n🏦 Testing Fund (TEFAS)...');
60
- console.log('─'.repeat(50));
70
+ console.log('\n🏦 FUND (TEFAS)');
71
+ console.log('─'.repeat(60));
61
72
  try {
62
- const results = await searchFunds('ak', 5);
73
+ const results = await searchFunds('ak', 3);
63
74
  console.log('Search "ak":', JSON.stringify(results, null, 2));
75
+
64
76
  if (results.length > 0) {
65
77
  const fund = new Fund(results[0].fundCode);
66
78
  const info = await fund.getInfo();
67
- console.log(`\n${results[0].fundCode} Info:`, JSON.stringify(info, null, 2));
79
+ console.log(`\n${results[0].fundCode}:`, JSON.stringify(info, null, 2));
68
80
  }
69
- } catch (error) { console.error('Fund Error:', error); }
81
+ } catch (error) { console.error('Error:', error); }
70
82
  }
71
83
 
72
84
  async function testInflation() {
73
- console.log('\nπŸ“‰ Testing Inflation (TCMB)...');
74
- console.log('─'.repeat(50));
85
+ console.log('\nπŸ“‰ INFLATION (TCMB)');
86
+ console.log('─'.repeat(60));
75
87
  try {
76
88
  const inflation = new Inflation();
77
89
  const latest = await inflation.getLatest();
78
90
  console.log('Latest CPI:', JSON.stringify(latest, null, 2));
79
- const cpi = await inflation.getTufe({ limit: 3 });
80
- console.log('\nCPI last 3 months:', JSON.stringify(cpi, null, 2));
81
- const calculation = await inflation.calculate(100000, '2020-01', '2024-01');
82
- console.log('\n100,000 TL (2020-01 β†’ 2024-01):', JSON.stringify(calculation, null, 2));
83
- } catch (error) { console.error('Inflation Error:', error); }
91
+
92
+ const calc = await inflation.calculate(100000, '2020-01', '2024-01');
93
+ console.log('\nCalculation (100K TL, 2020-01 β†’ 2024-01):', JSON.stringify(calc, null, 2));
94
+ } catch (error) { console.error('Error:', error); }
95
+ }
96
+
97
+ async function testSymbols() {
98
+ console.log('\n🏒 SYMBOLS');
99
+ console.log('─'.repeat(60));
100
+ try {
101
+ // Stock symbols
102
+ const stockSymbols = symbols();
103
+ console.log(`Stock Symbols: ${stockSymbols.slice(0, 15).join(', ')}... (${stockSymbols.length} total)`);
104
+
105
+ // Search stocks
106
+ const banks = searchSymbols('BNK');
107
+ console.log(`\nSearch "BNK": ${banks.join(', ')}`);
108
+
109
+ // Crypto symbols
110
+ const cryptoList = await cryptoSymbols('TRY');
111
+ console.log(`\nCrypto Symbols: ${cryptoList.slice(0, 10).join(', ')}... (${cryptoList.length} total)`);
112
+
113
+ // FX symbols
114
+ console.log(`\nFX Symbols: ${fxSymbols.join(', ')}`);
115
+
116
+ // Index symbols
117
+ console.log(`\nIndex Symbols: ${indexSymbols.join(', ')}`);
118
+ } catch (error) { console.error('Error:', error); }
119
+ }
120
+
121
+ async function testKap() {
122
+ console.log('\nπŸ›οΈ KAP (Public Disclosure Platform)');
123
+ console.log('─'.repeat(60));
124
+ try {
125
+ const kap = getKapProvider();
126
+ const companies = await kap.getCompanies();
127
+ console.log(`Total Companies: ${companies.length}`);
128
+ console.log('Sample:', JSON.stringify(companies.slice(0, 3), null, 2));
129
+
130
+ const search = await kap.search('tΓΌrk hava');
131
+ console.log('\nSearch "tΓΌrk hava":', JSON.stringify(search, null, 2));
132
+
133
+ // Test disclosures
134
+ const disclosures = await kap.getDisclosures('THYAO', 5);
135
+ console.log(`\nRecent THYAO Disclosures (${disclosures.length}):`);
136
+ disclosures.forEach((d, i) => {
137
+ console.log(` ${i + 1}. [${d.date}] ${d.title}`);
138
+ console.log(` ${d.url}`);
139
+ });
140
+
141
+ // Test calendar
142
+ const calendar = await kap.getCalendar('THYAO');
143
+ console.log(`\nTHYAO Expected Disclosures (${calendar.length}):`);
144
+ calendar.slice(0, 3).forEach((c, i) => {
145
+ console.log(` ${i + 1}. ${c.subject} (${c.period} ${c.year})`);
146
+ console.log(` ${c.startDate} - ${c.endDate}`);
147
+ });
148
+
149
+ // Test company details
150
+ const details = await kap.getCompanyDetails('THYAO');
151
+ console.log('\nTHYAO Company Details:', JSON.stringify(details, null, 2));
152
+ } catch (error) { console.error('Error:', error); }
84
153
  }
85
154
 
86
155
  async function main() {
87
156
  console.log('πŸš€ borsajs API Test');
88
- console.log('═'.repeat(50));
157
+ console.log('═'.repeat(60));
158
+
89
159
  await testCrypto();
90
160
  await testFX();
91
161
  await testTicker();
92
162
  await testIndex();
93
163
  await testFund();
94
164
  await testInflation();
95
- console.log('\n' + '═'.repeat(50));
165
+ await testSymbols();
166
+ await testKap();
167
+
168
+ console.log('\n' + '═'.repeat(60));
96
169
  console.log('βœ… All tests completed!');
97
170
  }
98
171