Skip to content

Commit b7f1dbe

Browse files
Adds EA for LibreCapital
1 parent 4cdf40b commit b7f1dbe

File tree

12 files changed

+361
-46
lines changed

12 files changed

+361
-46
lines changed

.pnp.cjs

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sources/nav-libre/src/endpoint/nav.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import dayjs from 'dayjs'
44
import { config } from '../config'
55
import { httpTransport } from '../transport/nav'
66

7-
// Input parameters define the structure of the request expected by the endpoint. The second parameter defines example input data that will be used in EA readme
87
export const inputParameters = new InputParameters(
98
{
109
globalFundID: {
@@ -33,18 +32,16 @@ export const inputParameters = new InputParameters(
3332
},
3433
],
3534
)
36-
export type NavResultResponse = {
37-
Result: number
38-
Data: {
39-
navPerShare: number
40-
navDate: string
41-
globalFundID: number
42-
}
43-
}
44-
4535
export type BaseEndpointTypes = {
4636
Parameters: typeof inputParameters.definition
47-
Response: NavResultResponse
37+
Response: {
38+
Result: number
39+
Data: {
40+
navPerShare: number
41+
navDate: string
42+
globalFundID: number
43+
}
44+
}
4845
Settings: typeof config.settings
4946
}
5047

packages/sources/nav-libre/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import { config } from './config'
44
import { nav } from './endpoint'
55

66
export const adapter = new Adapter({
7-
//Requests will direct to this endpoint if the `endpoint` input parameter is not specified.
87
defaultEndpoint: nav.name,
9-
// Adapter name
108
name: 'NAV_LIBRE',
11-
// Adapter configuration (environment variables)
129
config,
13-
// List of supported endpoints
1410
endpoints: [nav],
11+
rateLimiting: {
12+
tiers: {
13+
default: {
14+
rateLimit1m: 1,
15+
},
16+
},
17+
},
1518
})
1619

1720
export const server = (): Promise<ServerInstance | undefined> => expose(adapter)

packages/sources/nav-libre/src/transport/authentication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getNavRequestHeaders = (
1616
const contentHash = CryptoJS.SHA256(body).toString(CryptoJS.enc.Base64)
1717
const stringToSign = [apiKey, path, method, utcNow, nonce, contentHash].join(';')
1818

19-
// 5. Compute the HMAC-SHA256 signature, Base64-encoded
19+
// Compute the HMAC-SHA256 signature, Base64-encoded
2020
const signature = CryptoJS.HmacSHA256(stringToSign, secret).toString(CryptoJS.enc.Base64)
2121

2222
return {

packages/sources/nav-libre/src/transport/nav.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ export interface ResponseSchema {
2626
}[]
2727
}
2828

29-
// HttpTransport extends base types from endpoint and adds additional, Provider-specific types like 'RequestBody', which is the type of
30-
// request body (not the request to adapter, but the request that adapter sends to Data Provider), and 'ResponseBody' which is
31-
// the type of raw response from Data Provider
3229
export type HttpTransportTypes = BaseEndpointTypes & {
3330
Provider: {
3431
RequestBody: never
3532
ResponseBody: ResponseSchema
3633
}
3734
}
38-
// HttpTransport is used to fetch and process data from a Provider using HTTP(S) protocol. It usually needs two methods
39-
// `prepareRequests` and `parseResponse`
35+
4036
export const httpTransport = new HttpTransport<HttpTransportTypes>({
4137
prepareRequests: (params, config) => {
4238
return params.map((param) => {
@@ -58,6 +54,7 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
5854
const path =
5955
'/navapigateway/api/v1/FundAccountingData/GetOfficialNAVAndPerformanceReturnsForFund'
6056
const query = `globalFundID=${param.globalFundID}&fromDate=${fromDate}&toDate=${toDate}`
57+
// Body is empy for GET
6158
const body = ''
6259

6360
const headers = getNavRequestHeaders(
@@ -75,8 +72,8 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
7572
headers,
7673
params: {
7774
globalFundID: param.globalFundID,
78-
fromDate: param.fromDate,
79-
toDate: param.toDate,
75+
fromDate,
76+
toDate,
8077
},
8178
},
8279
}
@@ -98,6 +95,10 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
9895
return new Date(a['Accounting Date']) > new Date(b['Accounting Date']) ? a : b
9996
})
10097

98+
const timestamps = {
99+
providerIndicatedTimeUnixMs: new Date(latest['Accounting Date']).getTime(),
100+
}
101+
101102
return params.map((param) => ({
102103
params: param,
103104
response: {
@@ -107,6 +108,8 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
107108
navDate: latest['Accounting Date'],
108109
globalFundID: param.globalFundID,
109110
},
111+
timestamps,
112+
statusCode: 200,
110113
},
111114
}))
112115
},
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"requests": [{
3-
"from": "BTC",
4-
"to": "USD"
3+
"globalFundID": 1234,
4+
"fromDate": "01-01-2024",
5+
"toDate": "01-30-2024"
56
}]
67
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`execute nav endpoint should return success 1`] = `
4+
{
5+
"data": {
6+
"globalFundID": 1234,
7+
"navDate": "01-01-2024",
8+
"navPerShare": 123.45,
9+
},
10+
"result": 123.45,
11+
"statusCode": 200,
12+
"timestamps": {
13+
"providerDataReceivedUnixMs": 978347471111,
14+
"providerDataRequestedUnixMs": 978347471111,
15+
},
16+
}
17+
`;

0 commit comments

Comments
 (0)