laplace-api 3.0.1 → 4.0.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/package.json +1 -1
- package/src/client/broker.ts +175 -0
- package/src/client/capital_increase.ts +11 -11
- package/src/client/collections.ts +5 -13
- package/src/client/financial_fundamentals.ts +41 -33
- package/src/client/financial_ratios.ts +56 -35
- package/src/client/funds.ts +139 -0
- package/src/client/key-insights.ts +17 -0
- package/src/client/live-price.ts +25 -0
- package/src/client/stocks.ts +12 -2
- package/src/test/broker.test.ts +238 -0
- package/src/test/capital_increase.test.ts +119 -15
- package/src/test/collections.test.ts +69 -11
- package/src/test/custom_theme.test.ts +18 -9
- package/src/test/financial_fundamentals.test.ts +23 -8
- package/src/test/financial_ratios.test.ts +67 -37
- package/src/test/funds.test.ts +110 -0
- package/src/test/helpers.ts +58 -0
- package/src/test/key-insight.test.ts +48 -0
- package/src/test/live-price.test.ts +4 -5
- package/src/test/search.test.ts +71 -22
- package/src/test/stocks.test.ts +185 -67
package/src/test/stocks.test.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { Logger } from
|
|
2
|
-
import { LaplaceConfiguration } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Logger } from "winston";
|
|
2
|
+
import { LaplaceConfiguration } from "../utilities/configuration";
|
|
3
|
+
import {
|
|
4
|
+
StockClient,
|
|
5
|
+
HistoricalPricePeriod,
|
|
6
|
+
HistoricalPriceInterval,
|
|
7
|
+
AssetClass,
|
|
8
|
+
} from "../client/stocks";
|
|
9
|
+
import "./client_test_suite";
|
|
10
|
+
import { Region, Locale } from "../client/collections";
|
|
11
|
+
|
|
12
|
+
describe("Stocks Client", () => {
|
|
9
13
|
let client: StockClient;
|
|
10
14
|
|
|
11
15
|
beforeAll(() => {
|
|
12
|
-
// Assuming global.testSuite is set up as in the previous example
|
|
13
16
|
const config = (global as any).testSuite.config as LaplaceConfiguration;
|
|
14
17
|
const logger: Logger = {
|
|
15
18
|
info: jest.fn(),
|
|
@@ -21,77 +24,192 @@ describe('Stocks', () => {
|
|
|
21
24
|
client = new StockClient(config, logger);
|
|
22
25
|
});
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
describe("getAllStocks", () => {
|
|
28
|
+
test("should return stocks list for TR region", async () => {
|
|
29
|
+
const resp = await client.getAllStocks(Region.Tr);
|
|
30
|
+
|
|
31
|
+
expect(resp).not.toBeEmpty();
|
|
32
|
+
|
|
33
|
+
const firstStock = resp[0];
|
|
34
|
+
expect(typeof firstStock.id).toBe("string");
|
|
35
|
+
expect(typeof firstStock.assetType).toBe("string");
|
|
36
|
+
expect(typeof firstStock.name).toBe("string");
|
|
37
|
+
expect(typeof firstStock.symbol).toBe("string");
|
|
38
|
+
expect(typeof firstStock.sectorId).toBe("string");
|
|
39
|
+
expect(typeof firstStock.industryId).toBe("string");
|
|
40
|
+
expect(typeof firstStock.updatedDate).toBe("string");
|
|
41
|
+
expect(typeof firstStock.active).toBe("boolean");
|
|
42
|
+
|
|
43
|
+
if (firstStock.dailyChange !== undefined) {
|
|
44
|
+
expect(typeof firstStock.dailyChange).toBe("number");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("should handle pagination correctly", async () => {
|
|
49
|
+
const resp = await client.getAllStocks(Region.Tr, 10, 10);
|
|
50
|
+
|
|
51
|
+
expect(resp).not.toBeEmpty();
|
|
52
|
+
expect(resp.length).toBeLessThanOrEqual(10);
|
|
53
|
+
});
|
|
27
54
|
});
|
|
28
55
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
describe("getStockDetailById", () => {
|
|
57
|
+
test("should return stock detail by ID", async () => {
|
|
58
|
+
const resp = await client.getStockDetailById(
|
|
59
|
+
"61dd0d6f0ec2114146342fd0",
|
|
60
|
+
Locale.Tr
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(resp).toBeDefined();
|
|
64
|
+
expect(typeof resp.id).toBe("string");
|
|
65
|
+
expect(typeof resp.assetClass).toBe("string");
|
|
66
|
+
expect(typeof resp.description).toBe("string");
|
|
67
|
+
expect(typeof resp.shortDescription).toBe("string");
|
|
68
|
+
expect(typeof resp.region).toBe("string");
|
|
69
|
+
expect(typeof resp.localized_description).toBe("object");
|
|
70
|
+
expect(typeof resp.localizedShortDescription).toBe("object");
|
|
71
|
+
|
|
72
|
+
if (resp.markets) {
|
|
73
|
+
expect(Array.isArray(resp.markets)).toBe(true);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
34
76
|
});
|
|
35
77
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
78
|
+
describe("getStockDetailBySymbol", () => {
|
|
79
|
+
test("should return stock detail by symbol", async () => {
|
|
80
|
+
const resp = await client.getStockDetailBySymbol(
|
|
81
|
+
"TUPRS",
|
|
82
|
+
AssetClass.Equity,
|
|
83
|
+
Region.Tr,
|
|
84
|
+
Locale.Tr
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(resp).toBeDefined();
|
|
88
|
+
expect(resp.symbol).toBe("TUPRS");
|
|
89
|
+
expect(typeof resp.assetClass).toBe("string");
|
|
90
|
+
expect(typeof resp.description).toBe("string");
|
|
91
|
+
expect(typeof resp.region).toBe("string");
|
|
92
|
+
});
|
|
39
93
|
});
|
|
40
94
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
95
|
+
describe("getHistoricalPrices", () => {
|
|
96
|
+
test("should return historical prices for multiple symbols", async () => {
|
|
97
|
+
const resp = await client.getHistoricalPrices(
|
|
98
|
+
["TUPRS", "SASA"],
|
|
99
|
+
Region.Tr,
|
|
100
|
+
[
|
|
101
|
+
HistoricalPricePeriod.OneDay,
|
|
102
|
+
HistoricalPricePeriod.OneWeek,
|
|
103
|
+
HistoricalPricePeriod.OneMonth,
|
|
104
|
+
]
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(resp).not.toBeEmpty();
|
|
108
|
+
|
|
109
|
+
const firstPriceGraph = resp[0];
|
|
110
|
+
expect(typeof firstPriceGraph.symbol).toBe("string");
|
|
111
|
+
expect(Array.isArray(firstPriceGraph["1D"])).toBe(true);
|
|
112
|
+
expect(Array.isArray(firstPriceGraph["1W"])).toBe(true);
|
|
113
|
+
expect(Array.isArray(firstPriceGraph["1M"])).toBe(true);
|
|
114
|
+
|
|
115
|
+
if (firstPriceGraph["1D"].length > 0) {
|
|
116
|
+
const firstDataPoint = firstPriceGraph["1D"][0];
|
|
117
|
+
expect(typeof firstDataPoint.d).toBe("number");
|
|
118
|
+
expect(typeof firstDataPoint.c).toBe("number");
|
|
119
|
+
expect(typeof firstDataPoint.h).toBe("number");
|
|
120
|
+
expect(typeof firstDataPoint.l).toBe("number");
|
|
121
|
+
expect(typeof firstDataPoint.o).toBe("number");
|
|
122
|
+
}
|
|
123
|
+
});
|
|
44
124
|
});
|
|
45
125
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
126
|
+
describe("getCustomHistoricalPrices", () => {
|
|
127
|
+
test("should return custom historical prices", async () => {
|
|
128
|
+
const resp = await client.getCustomHistoricalPrices(
|
|
129
|
+
"TUPRS",
|
|
130
|
+
Region.Tr,
|
|
131
|
+
"2024-01-01",
|
|
132
|
+
"2024-03-01",
|
|
133
|
+
HistoricalPriceInterval.OneDay,
|
|
134
|
+
false
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
expect(resp).not.toBeEmpty();
|
|
138
|
+
|
|
139
|
+
const firstDataPoint = resp[0];
|
|
140
|
+
expect(typeof firstDataPoint.d).toBe("number");
|
|
141
|
+
expect(typeof firstDataPoint.c).toBe("number");
|
|
142
|
+
expect(typeof firstDataPoint.h).toBe("number");
|
|
143
|
+
expect(typeof firstDataPoint.l).toBe("number");
|
|
144
|
+
expect(typeof firstDataPoint.o).toBe("number");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("should handle detailed historical prices", async () => {
|
|
148
|
+
const resp = await client.getCustomHistoricalPrices(
|
|
149
|
+
"SASA",
|
|
150
|
+
Region.Tr,
|
|
151
|
+
"2024-01-01 10:00:00",
|
|
152
|
+
"2024-01-05 10:00:00",
|
|
153
|
+
HistoricalPriceInterval.OneHour,
|
|
154
|
+
true
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(resp).not.toBeEmpty();
|
|
158
|
+
});
|
|
57
159
|
});
|
|
58
160
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"TUPRS",
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
HistoricalPriceInterval.OneHour,
|
|
80
|
-
true
|
|
81
|
-
);
|
|
82
|
-
expect(resp).not.toBeEmpty();
|
|
83
|
-
|
|
84
|
-
for (const price of resp) {
|
|
85
|
-
expect(price).not.toBeEmpty();
|
|
86
|
-
}
|
|
161
|
+
describe("getStockRestrictions", () => {
|
|
162
|
+
test("should return stock restrictions for specific symbol", async () => {
|
|
163
|
+
const resp = await client.getStockRestrictions("TUPRS", Region.Tr);
|
|
164
|
+
|
|
165
|
+
if (resp && resp.length > 0) {
|
|
166
|
+
const firstRestriction = resp[0];
|
|
167
|
+
expect(typeof firstRestriction.id).toBe("number");
|
|
168
|
+
expect(typeof firstRestriction.title).toBe("string");
|
|
169
|
+
expect(typeof firstRestriction.description).toBe("string");
|
|
170
|
+
expect(typeof firstRestriction.startDate).toBe("string");
|
|
171
|
+
expect(typeof firstRestriction.endDate).toBe("string");
|
|
172
|
+
|
|
173
|
+
if (firstRestriction.symbol) {
|
|
174
|
+
expect(typeof firstRestriction.symbol).toBe("string");
|
|
175
|
+
}
|
|
176
|
+
if (firstRestriction.market) {
|
|
177
|
+
expect(typeof firstRestriction.market).toBe("string");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
87
181
|
});
|
|
88
182
|
|
|
89
|
-
|
|
90
|
-
|
|
183
|
+
describe("getAllStockRestrictions", () => {
|
|
184
|
+
test("should return all stock restrictions for region", async () => {
|
|
185
|
+
const resp = await client.getAllStockRestrictions(Region.Tr);
|
|
186
|
+
|
|
187
|
+
expect(Array.isArray(resp)).toBe(true);
|
|
188
|
+
|
|
189
|
+
if (resp.length > 0) {
|
|
190
|
+
const firstRestriction = resp[0];
|
|
191
|
+
expect(typeof firstRestriction.id).toBe("number");
|
|
192
|
+
expect(typeof firstRestriction.title).toBe("string");
|
|
193
|
+
expect(typeof firstRestriction.description).toBe("string");
|
|
194
|
+
expect(typeof firstRestriction.startDate).toBe("string");
|
|
195
|
+
expect(typeof firstRestriction.endDate).toBe("string");
|
|
196
|
+
}
|
|
197
|
+
});
|
|
91
198
|
});
|
|
92
199
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
200
|
+
describe("getTickRules", () => {
|
|
201
|
+
test("should return tick rules for symbol", async () => {
|
|
202
|
+
const resp = await client.getTickRules("TUPRS", Region.Tr);
|
|
203
|
+
|
|
204
|
+
expect(resp).toBeDefined();
|
|
205
|
+
expect(typeof resp.basePrice).toBe("number");
|
|
206
|
+
expect(typeof resp.additionalPrice).toBe("number");
|
|
207
|
+
expect(typeof resp.lowerPriceLimit).toBe("number");
|
|
208
|
+
expect(typeof resp.upperPriceLimit).toBe("number");
|
|
209
|
+
|
|
210
|
+
if (resp.rules !== null) {
|
|
211
|
+
expect(Array.isArray(resp.rules)).toBe(true);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
96
214
|
});
|
|
97
215
|
});
|