laplace-api 1.0.13 → 1.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laplace-api",
3
- "version": "1.0.13",
3
+ "version": "1.1.1",
4
4
  "description": "Client library for Laplace API for the US stock market and BIST (Istanbul stock market) fundamental financial data.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,80 @@
1
+ import { Client } from './client';
2
+ import { Region, Locale } from './collections';
3
+
4
+ // type PaginatedResponse[T any] struct {
5
+ // RecordCount int `json:"recordCount"`
6
+ // Items []T `json:"items"`
7
+ // }
8
+
9
+ export interface PaginatedResponse<T> {
10
+ recordCount: number;
11
+ items: T[];
12
+ }
13
+
14
+ export interface CapitalIncrease {
15
+ id: number;
16
+ boardDecisionDate: string;
17
+ registeredCapitalCeiling: string;
18
+ currentCapital: string;
19
+ targetCapital: string;
20
+ types: string[];
21
+ spkApplicationResult: string;
22
+ spkApplicationDate: string;
23
+ spkApprovalDate: string;
24
+ paymentDate: string;
25
+ registrationDate: string;
26
+ specifiedCurrency: string;
27
+ symbol: string;
28
+ relatedDisclosureIDs: number[];
29
+ rightsRate: string;
30
+ rightsPrice: string;
31
+ rightsTotalAmount: string;
32
+ rightsStartDate: string;
33
+ rightsEndDate: string;
34
+ bonusRate: string;
35
+ bonusTotalAmount: string;
36
+ bonusStartDate: string;
37
+ bonusDividendRate: string;
38
+ bonusDividendTotalAmount: string;
39
+ externalCapitalIncreaseAmount: string;
40
+ externalCapitalIncreaseRate: string;
41
+ }
42
+
43
+ export class CapitalIncreaseClient extends Client {
44
+ async getAllCapitalIncreases(
45
+ page: number,
46
+ size: number,
47
+ region: Region
48
+ ): Promise<PaginatedResponse<CapitalIncrease>> {
49
+ return this.sendRequest<PaginatedResponse<CapitalIncrease>>({
50
+ method: 'GET',
51
+ url: '/api/v1/capital-increase/all',
52
+ params: { region, page, size },
53
+ });
54
+ }
55
+
56
+ async getCapitalIncreasesForInstrument(
57
+ symbol: string,
58
+ page: number,
59
+ size: number,
60
+ region: Region,
61
+ ): Promise<PaginatedResponse<CapitalIncrease>> {
62
+ return this.sendRequest<PaginatedResponse<CapitalIncrease>>({
63
+ method: 'GET',
64
+ url: '/api/v1/capital-increase/' + symbol,
65
+ params: { region, page, size },
66
+ });
67
+ }
68
+
69
+ async getActiveRightsForInstrument(
70
+ symbol: string,
71
+ date: string,
72
+ region: Region
73
+ ): Promise<CapitalIncrease[]> {
74
+ return this.sendRequest<CapitalIncrease[]>({
75
+ method: 'GET',
76
+ url: '/api/v1/rights/active/' + symbol,
77
+ params: { date, region },
78
+ });
79
+ }
80
+ }
@@ -25,6 +25,20 @@ export enum HistoricalPricePeriod {
25
25
  FiveYear = '5Y',
26
26
  }
27
27
 
28
+ export enum HistoricalPriceInterval {
29
+ OneMinute = "1m",
30
+ ThreeMinute = "3m",
31
+ FiveMinute = "5m",
32
+ FifteenMinute = "15m",
33
+ ThirtyMinute = "30m",
34
+ OneHour = "1h",
35
+ TwoHour = "2h",
36
+ OneDay = "1d",
37
+ FiveDay = "5d",
38
+ SevenDay = "7d",
39
+ ThirtyDay = "30d",
40
+ }
41
+
28
42
  export interface Stock {
29
43
  id: string;
30
44
  assetType: AssetType;
@@ -34,7 +48,7 @@ export interface Stock {
34
48
  industryId: string;
35
49
  updatedDate: string;
36
50
  dailyChange?: number;
37
- active?: boolean;
51
+ active: boolean;
38
52
  }
39
53
 
40
54
  export interface LocaleString {
@@ -55,6 +69,19 @@ export interface StockDetail {
55
69
  sectorId: string;
56
70
  industryId: string;
57
71
  updatedDate: string;
72
+ active: boolean;
73
+ markets: Market[];
74
+ }
75
+
76
+ export enum Market {
77
+ Yildiz = "YILDIZ",
78
+ Ana = "ANA",
79
+ Alt = "ALT",
80
+ YakinIzleme = "YAKIN_IZLEME",
81
+ POIP = "POIP",
82
+ Fon = "FON",
83
+ Girisim = "GIRISIM",
84
+ Emtia = "EMTIA",
58
85
  }
59
86
 
60
87
  export interface PriceDataPoint {
@@ -77,6 +104,28 @@ export interface StockPriceGraph {
77
104
  '5Y': PriceDataPoint[];
78
105
  }
79
106
 
107
+ export interface StockRestriction {
108
+ id: number;
109
+ title: string;
110
+ description: string;
111
+ startDate: string;
112
+ endDate: string;
113
+ }
114
+
115
+ export interface TickRule {
116
+ basePrice: number;
117
+ additionalPrice: number;
118
+ lowerPriceLimit: number;
119
+ upperPriceLimit: number;
120
+ rules: TickSizeRule[];
121
+ }
122
+
123
+ export interface TickSizeRule {
124
+ priceFrom: number;
125
+ priceTo: number;
126
+ tickSize: number;
127
+ }
128
+
80
129
  export class StockClient extends Client {
81
130
  async getAllStocks(region: Region): Promise<Stock[]> {
82
131
  return this.sendRequest<Stock[]>({
@@ -113,4 +162,39 @@ export class StockClient extends Client {
113
162
  },
114
163
  });
115
164
  }
116
- }
165
+
166
+ async getCustomHistoricalPrices(stock: string, region: Region, fromDate: string, toDate: string, interval: HistoricalPriceInterval, detail: boolean): Promise<PriceDataPoint[]> {
167
+ this.validateCustomHistoricalPriceDate(fromDate);
168
+ this.validateCustomHistoricalPriceDate(toDate);
169
+
170
+ return this.sendRequest<PriceDataPoint[]>({
171
+ method: 'GET',
172
+ url: '/api/v1/stock/price/interval',
173
+ params: { stock, region, fromDate, toDate, interval, detail },
174
+ });
175
+ }
176
+
177
+ async validateCustomHistoricalPriceDate(date: string) {
178
+ const pattern = /^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$/;
179
+ const matched = date.match(pattern);
180
+ if (!matched) {
181
+ throw new Error("Invalid date format, allowed formats: YYYY-MM-DD, YYYY-MM-DD HH:MM:SS");
182
+ }
183
+ }
184
+
185
+ async getStockRestrictions(symbol: string, region: Region): Promise<StockRestriction[]> {
186
+ return this.sendRequest<StockRestriction[]>({
187
+ method: 'GET',
188
+ url: '/api/v1/stock/restrictions',
189
+ params: { symbol, region },
190
+ });
191
+ }
192
+
193
+ async getTickRules(symbol: string, region: Region): Promise<TickRule> {
194
+ return this.sendRequest<TickRule>({
195
+ method: 'GET',
196
+ url: '/api/v1/stock/rules',
197
+ params: { symbol, region },
198
+ });
199
+ }
200
+ }
@@ -0,0 +1,36 @@
1
+ import { Logger } from 'winston';
2
+ import { LaplaceConfiguration } from '../utilities/configuration';
3
+ import { CapitalIncreaseClient } from '../client/capital_increase';
4
+ import { Region } from '../client/collections';
5
+ import './client_test_suite';
6
+
7
+
8
+ describe('Capital Increase', () => {
9
+ let client: CapitalIncreaseClient;
10
+
11
+ beforeAll(() => {
12
+ // Assuming global.testSuite is set up as in the previous example
13
+ const config = (global as any).testSuite.config as LaplaceConfiguration;
14
+ const logger: Logger = {
15
+ info: jest.fn(),
16
+ error: jest.fn(),
17
+ warn: jest.fn(),
18
+ debug: jest.fn(),
19
+ } as unknown as Logger;
20
+
21
+ client = new CapitalIncreaseClient(config, logger);
22
+ });
23
+
24
+ test('GetAllCapitalIncreases', async () => {
25
+ await client.getAllCapitalIncreases(1, 10, Region.Tr, );
26
+ });
27
+
28
+ test('GetCapitalIncreasesForInstrument', async () => {
29
+ await client.getCapitalIncreasesForInstrument("TUPRS", 1, 10, Region.Tr);
30
+ });
31
+
32
+ test('GetActiveRightsForInstrument', async () => {
33
+ await client.getActiveRightsForInstrument("TUPRS", "2024-01-01", Region.Tr);
34
+ });
35
+
36
+ });
@@ -1,6 +1,6 @@
1
1
  import { Logger } from 'winston';
2
2
  import { LaplaceConfiguration } from '../utilities/configuration';
3
- import { StockClient, AssetClass, HistoricalPricePeriod } from '../client/stocks';
3
+ import { StockClient, AssetClass, HistoricalPricePeriod, HistoricalPriceInterval } from '../client/stocks';
4
4
  import { Region, Locale } from '../client/collections';
5
5
  import './client_test_suite';
6
6
 
@@ -48,4 +48,43 @@ describe('Stocks', () => {
48
48
  expect(price).not.toBeEmpty();
49
49
  }
50
50
  });
51
- });
51
+
52
+ test('GetCustomHistoricalPrices', async () => {
53
+ let resp = await client.getCustomHistoricalPrices(
54
+ "TUPRS",
55
+ Region.Tr,
56
+ "2024-01-01",
57
+ "2024-03-01",
58
+ HistoricalPriceInterval.OneDay,
59
+ false
60
+ );
61
+ expect(resp).not.toBeEmpty();
62
+
63
+ for (const price of resp) {
64
+ expect(price).not.toBeEmpty();
65
+ }
66
+
67
+ resp = await client.getCustomHistoricalPrices(
68
+ "SASA",
69
+ Region.Tr,
70
+ "2024-01-01 10:00:00",
71
+ "2024-01-05 10:00:00",
72
+ HistoricalPriceInterval.OneHour,
73
+ true
74
+ );
75
+ expect(resp).not.toBeEmpty();
76
+
77
+ for (const price of resp) {
78
+ expect(price).not.toBeEmpty();
79
+ }
80
+ });
81
+
82
+ test('GetStockRestrictions', async () => {
83
+ await client.getStockRestrictions("TUPRS", Region.Tr);
84
+ });
85
+
86
+ test('GetTickRules', async () => {
87
+ const resp = await client.getTickRules("TUPRS", Region.Tr);
88
+ expect(resp).not.toBeEmpty();
89
+ });
90
+ });