laplace-api 3.1.0 → 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.
@@ -1,11 +1,10 @@
1
- import { Logger } from 'winston';
2
- import { LaplaceConfiguration } from '../utilities/configuration';
3
- import { SearchClient, SearchType } from '../client/search';
4
- import { Region, Locale } from '../client/collections';
5
- import './client_test_suite';
1
+ import { Logger } from "winston";
2
+ import { LaplaceConfiguration } from "../utilities/configuration";
3
+ import { SearchClient, SearchType } from "../client/search";
4
+ import "./client_test_suite";
5
+ import { Region, Locale } from "../client/collections";
6
6
 
7
-
8
- describe('Search', () => {
7
+ describe("Search", () => {
9
8
  let client: SearchClient;
10
9
 
11
10
  beforeAll(() => {
@@ -21,23 +20,73 @@ describe('Search', () => {
21
20
  client = new SearchClient(config, logger);
22
21
  });
23
22
 
24
- test('SearchStock', async () => {
25
- const resp = await client.search("TUPRS", [SearchType.Stock], Region.Tr, Locale.Tr);
26
- expect(resp).not.toBeEmpty();
23
+ test("SearchStock", async () => {
24
+ const resp = await client.search(
25
+ "TUPRS",
26
+ [SearchType.Stock],
27
+ Region.Tr,
28
+ Locale.Tr
29
+ );
30
+ expect(resp.stocks).not.toBeEmpty();
31
+
32
+ const firstResult = resp.stocks[0];
33
+ expect(typeof firstResult.id).toBe("string");
34
+ expect(typeof firstResult.name).toBe("string");
35
+ expect(typeof firstResult.title).toBe("string");
36
+ expect(typeof firstResult.region).toBe("string");
37
+ expect(typeof firstResult.assetType).toBe("string");
38
+ expect(typeof firstResult.type).toBe("string");
27
39
  });
28
40
 
29
- test('SearchIndustry', async () => {
30
- const resp = await client.search("Hava Taşımacılığı", [SearchType.Industry], Region.Tr, Locale.Tr);
31
- expect(resp).not.toBeEmpty();
41
+ test("SearchIndustry", async () => {
42
+ const resp = await client.search(
43
+ "Hava",
44
+ [SearchType.Industry],
45
+ Region.Tr,
46
+ Locale.Tr
47
+ );
48
+ expect(resp.industries).not.toBeEmpty();
49
+
50
+ const firstResult = resp.industries[0];
51
+ expect(typeof firstResult.id).toBe("string");
52
+ expect(typeof firstResult.title).toBe("string");
53
+ expect(Array.isArray(firstResult.region)).toBe(true);
54
+ expect(firstResult.region.length).toBeGreaterThan(0);
55
+ firstResult.region.forEach((region) => {
56
+ expect(typeof region).toBe("string");
57
+ });
58
+
59
+ expect(typeof firstResult.assetClass).toBe("string");
60
+ expect(typeof firstResult.imageUrl).toBe("string");
61
+ expect(typeof firstResult.avatarUrl).toBe("string");
32
62
  });
63
+ test("SearchAllTypes", async () => {
64
+ const resp = await client.search(
65
+ "Ab",
66
+ [
67
+ SearchType.Stock,
68
+ SearchType.Industry,
69
+ SearchType.Sector,
70
+ SearchType.Collection,
71
+ ],
72
+ Region.Us,
73
+ Locale.Tr
74
+ );
75
+
76
+ expect(typeof resp).toBe("object");
77
+ expect(resp).not.toBeNull();
78
+
79
+ const hasResults =
80
+ (resp.stocks && resp.stocks.length > 0) ||
81
+ (resp.industries && resp.industries.length > 0) ||
82
+ (resp.sectors && resp.sectors.length > 0) ||
83
+ (resp.collections && resp.collections.length > 0);
84
+
85
+ expect(hasResults).toBe(true);
33
86
 
34
- test('SearchAllTypes', async () => {
35
- const resp = await client.search("Ab", [
36
- SearchType.Stock,
37
- SearchType.Industry,
38
- SearchType.Sector,
39
- SearchType.Collection
40
- ], Region.Us, Locale.Tr);
41
- expect(resp).not.toBeEmpty();
87
+ if (resp.stocks) expect(Array.isArray(resp.stocks)).toBe(true);
88
+ if (resp.industries) expect(Array.isArray(resp.industries)).toBe(true);
89
+ if (resp.sectors) expect(Array.isArray(resp.sectors)).toBe(true);
90
+ if (resp.collections) expect(Array.isArray(resp.collections)).toBe(true);
42
91
  });
43
- });
92
+ });
@@ -1,15 +1,18 @@
1
- import { Logger } from 'winston';
2
- import { LaplaceConfiguration } from '../utilities/configuration';
3
- import { StockClient, AssetClass, HistoricalPricePeriod, HistoricalPriceInterval } from '../client/stocks';
4
- import { Region, Locale } from '../client/collections';
5
- import './client_test_suite';
6
-
7
-
8
- describe('Stocks', () => {
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
- test('GetAllStocks', async () => {
25
- const resp = await client.getAllStocks(Region.Tr);
26
- expect(resp).not.toBeEmpty();
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
- test('GetAllStocksWithPagination', async () => {
31
- const resp = await client.getAllStocks(Region.Tr, 10, 10);
32
- expect(resp).not.toBeEmpty();
33
- expect(resp.length).toBe(10);
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
- test('GetStockDetailByID', async () => {
37
- const resp = await client.getStockDetailById("61dd0d6f0ec2114146342fd0", Locale.Tr);
38
- expect(resp).not.toBeEmpty();
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
- test('GetStockDetailBySymbol', async () => {
42
- const resp = await client.getStockDetailBySymbol("TUPRS", AssetClass.Equity, Region.Tr, Locale.Tr);
43
- expect(resp).not.toBeEmpty();
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
- test('GetHistoricalPrices', async () => {
47
- const resp = await client.getHistoricalPrices(
48
- ["TUPRS", "SASA"],
49
- Region.Tr,
50
- [HistoricalPricePeriod.OneDay, HistoricalPricePeriod.OneWeek, HistoricalPricePeriod.OneMonth]
51
- );
52
- expect(resp).not.toBeEmpty();
53
-
54
- for (const price of resp) {
55
- expect(price).not.toBeEmpty();
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
- test('GetCustomHistoricalPrices', async () => {
60
- let resp = await client.getCustomHistoricalPrices(
61
- "TUPRS",
62
- Region.Tr,
63
- "2024-01-01",
64
- "2024-03-01",
65
- HistoricalPriceInterval.OneDay,
66
- false
67
- );
68
- expect(resp).not.toBeEmpty();
69
-
70
- for (const price of resp) {
71
- expect(price).not.toBeEmpty();
72
- }
73
-
74
- resp = await client.getCustomHistoricalPrices(
75
- "SASA",
76
- Region.Tr,
77
- "2024-01-01 10:00:00",
78
- "2024-01-05 10:00:00",
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
- test('GetStockRestrictions', async () => {
90
- await client.getStockRestrictions("TUPRS", Region.Tr);
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
- test('GetTickRules', async () => {
94
- const resp = await client.getTickRules("TUPRS", Region.Tr);
95
- expect(resp).not.toBeEmpty();
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
  });