Skip to content

Commit 76e8737

Browse files
authored
tradinghours: Add support for NYSE market (#3899)
1 parent 74360b8 commit 76e8737

File tree

6 files changed

+53
-21
lines changed

6 files changed

+53
-21
lines changed

.changeset/late-dingos-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/tradinghours-adapter': minor
3+
---
4+
5+
Add support for NYSE market

packages/sources/tradinghours/src/endpoint/market-status.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
2-
MarketStatusResultResponse,
32
MarketStatusEndpoint,
3+
MarketStatusResultResponse,
44
} from '@chainlink/external-adapter-framework/adapter'
5+
import { AdapterRequest } from '@chainlink/external-adapter-framework/util'
56
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
7+
import { TypeFromDefinition } from '@chainlink/external-adapter-framework/validation/input-params'
68

79
import { config } from '../config'
810
import { markets, transport } from '../transport/market-status'
@@ -12,7 +14,7 @@ const inputParameters = new InputParameters({
1214
aliases: [],
1315
type: 'string',
1416
description: 'The name of the market',
15-
options: markets,
17+
options: [...markets, ...markets.map((market) => market.toUpperCase())],
1618
required: true,
1719
},
1820
})
@@ -28,4 +30,11 @@ export const marketStatusEndpoint = new MarketStatusEndpoint({
2830
aliases: markets.map((market) => `${market}-market-status`),
2931
transport,
3032
inputParameters,
33+
requestTransforms: [
34+
(req: AdapterRequest<TypeFromDefinition<typeof inputParameters.definition>>) => {
35+
const data = req.requestContext.data
36+
data.market = data.market.toLowerCase()
37+
return req
38+
},
39+
],
3140
})

packages/sources/tradinghours/src/transport/market-status.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import { makeLogger } from '@chainlink/external-adapter-framework/util'
44

55
import type { BaseEndpointTypes } from '../endpoint/market-status'
66

7-
export const markets = ['forex', 'metals', 'wti'] as const
7+
export const markets = ['forex', 'metals', 'wti', 'nyse'] as const
88

99
export type Market = (typeof markets)[number]
1010

1111
const marketToFinId: Record<Market, string> = {
1212
forex: 'US.CHNLNK.FX',
1313
metals: 'US.CHNLNK.METAL',
1414
wti: 'US.CHNLNK.WTI',
15+
nyse: 'US.NYSE',
1516
}
1617

17-
function isMarket(v: any): v is Market {
18+
function isMarket(v: string): v is Market {
1819
return markets.includes(v as Market)
1920
}
2021

@@ -33,10 +34,6 @@ type ResponseBody = {
3334
next_bell: string // 2024-06-02T17:00:00-05:00
3435
}
3536
}
36-
meta: {
37-
utc_time: string // 2024-05-31T21:37:34+00:00
38-
time: string // 2024-05-31T21:37:34+00:00
39-
}
4037
}
4138

4239
export type HttpEndpointTypes = BaseEndpointTypes & {
@@ -93,9 +90,6 @@ export const transport = new HttpTransport<HttpEndpointTypes>({
9390
data: {
9491
result: marketStatus,
9592
},
96-
timestamps: {
97-
providerIndicatedTimeUnixMs: new Date(res.data.meta.time).getTime(),
98-
},
9993
},
10094
},
10195
]

packages/sources/tradinghours/test/integration/__snapshots__/adapter.test.ts.snap

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ exports[`Market status endpoint should return success with closed 1`] = `
1010
"timestamps": {
1111
"providerDataReceivedUnixMs": 1641035471111,
1212
"providerDataRequestedUnixMs": 1641035471111,
13-
"providerIndicatedTimeUnixMs": 1717191454000,
1413
},
1514
}
1615
`;
@@ -25,7 +24,20 @@ exports[`Market status endpoint should return success with open 1`] = `
2524
"timestamps": {
2625
"providerDataReceivedUnixMs": 1641035471111,
2726
"providerDataRequestedUnixMs": 1641035471111,
28-
"providerIndicatedTimeUnixMs": 1717191454000,
27+
},
28+
}
29+
`;
30+
31+
exports[`Market status endpoint should return success with open with uppercase market 1`] = `
32+
{
33+
"data": {
34+
"result": 2,
35+
},
36+
"result": 2,
37+
"statusCode": 200,
38+
"timestamps": {
39+
"providerDataReceivedUnixMs": 1641035471111,
40+
"providerDataRequestedUnixMs": 1641035471111,
2941
},
3042
}
3143
`;

packages/sources/tradinghours/test/integration/adapter.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ describe('Market status endpoint', () => {
4343
market: 'forex',
4444
},
4545
}
46+
const openDataUppercase = {
47+
data: {
48+
endpoint: 'market-status',
49+
market: 'FOREX',
50+
},
51+
}
4652
const closedData = {
4753
data: {
4854
endpoint: 'market-status',
@@ -77,4 +83,18 @@ describe('Market status endpoint', () => {
7783
expect(response.body).toMatchSnapshot()
7884
expect(response.body.result).toEqual(MarketStatus.CLOSED)
7985
})
86+
87+
it('should return success with open with uppercase market', async () => {
88+
mockResponseSuccess()
89+
90+
const response = await (context.req as SuperTest<Test>)
91+
.post('/')
92+
.send(openDataUppercase)
93+
.set('Accept', '*/*')
94+
.set('Content-Type', 'application/json')
95+
.expect('Content-Type', /json/)
96+
.expect(200)
97+
expect(response.body).toMatchSnapshot()
98+
expect(response.body.result).toEqual(MarketStatus.OPEN)
99+
})
80100
})

packages/sources/tradinghours/test/integration/fixtures.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ export const mockResponseSuccess = (): nock.Scope =>
2727
next_bell: '2024-06-02T17:00:00-05:00',
2828
},
2929
},
30-
meta: {
31-
utc_time: '2024-05-31T21:37:34+00:00',
32-
time: '2024-05-31T21:37:34+00:00',
33-
},
3430
},
3531
['Content-Type', 'application/json'],
3632
)
@@ -66,10 +62,6 @@ export const mockResponseSuccess = (): nock.Scope =>
6662
next_bell: '2024-06-02T17:00:00-05:00',
6763
},
6864
},
69-
meta: {
70-
utc_time: '2024-05-31T21:37:34+00:00',
71-
time: '2024-05-31T21:37:34+00:00',
72-
},
7365
},
7466
['Content-Type', 'application/json'],
7567
)

0 commit comments

Comments
 (0)