From 1c516b6b6609c037c607346c8ab156694564ea3e Mon Sep 17 00:00:00 2001 From: Michael Xiao Date: Fri, 17 Jan 2025 16:19:19 -0500 Subject: [PATCH] Lower request to bx-digital (#3634) --- .changeset/polite-books-flow.md | 5 +++ packages/sources/bx-digital/src/index.ts | 2 +- .../sources/bx-digital/src/transport/price.ts | 38 +++++++++++++------ .../__snapshots__/adapter.test.ts.snap | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 .changeset/polite-books-flow.md diff --git a/.changeset/polite-books-flow.md b/.changeset/polite-books-flow.md new file mode 100644 index 0000000000..817c19fa0d --- /dev/null +++ b/.changeset/polite-books-flow.md @@ -0,0 +1,5 @@ +--- +'@chainlink/bx-digital-adapter': patch +--- + +Adjust rate limiter diff --git a/packages/sources/bx-digital/src/index.ts b/packages/sources/bx-digital/src/index.ts index ddd5f7c548..a2dc712f31 100644 --- a/packages/sources/bx-digital/src/index.ts +++ b/packages/sources/bx-digital/src/index.ts @@ -11,7 +11,7 @@ export const adapter = new Adapter({ rateLimiting: { tiers: { default: { - rateLimit1m: 6, + rateLimit1m: 1, note: 'Reasonable limits', }, }, diff --git a/packages/sources/bx-digital/src/transport/price.ts b/packages/sources/bx-digital/src/transport/price.ts index 24e5723bdd..6c3db0e56d 100644 --- a/packages/sources/bx-digital/src/transport/price.ts +++ b/packages/sources/bx-digital/src/transport/price.ts @@ -40,11 +40,31 @@ export const httpTransport = new HttpTransport({ }) } - return params.map((param) => { - const security = response.data.find((r) => r.securityId == param.securityId) - if (security && !isNaN(Number(security?.closingPrice))) { + const missing = params + .filter((p) => !response.data.map((s) => s.securityId).includes(p.securityId)) + .map((p) => ({ + params: p, + response: { + errorMessage: `The data provider didn't return any value for ${p.securityId}`, + statusCode: 502, + }, + })) + + const valid = response.data.map((security) => { + const params = { + securityId: security.securityId, + } + if (isNaN(Number(security?.closingPrice))) { return { - params: param, + params, + response: { + errorMessage: `The data provider didn't return valid value for ${security.securityId}`, + statusCode: 502, + }, + } + } else { + return { + params, response: { result: Number(security.closingPrice), data: { @@ -55,15 +75,9 @@ export const httpTransport = new HttpTransport({ }, }, } - } else { - return { - params: param, - response: { - errorMessage: `The data provider didn't return any value for ${param.securityId}`, - statusCode: 502, - }, - } } }) + + return valid.concat(missing) }, }) diff --git a/packages/sources/bx-digital/test/integration/__snapshots__/adapter.test.ts.snap b/packages/sources/bx-digital/test/integration/__snapshots__/adapter.test.ts.snap index b9e1695683..03cb60123c 100644 --- a/packages/sources/bx-digital/test/integration/__snapshots__/adapter.test.ts.snap +++ b/packages/sources/bx-digital/test/integration/__snapshots__/adapter.test.ts.snap @@ -2,7 +2,7 @@ exports[`execute price endpoint should return failure for Nan 1`] = ` { - "errorMessage": "The data provider didn't return any value for 3", + "errorMessage": "The data provider didn't return valid value for 3", "statusCode": 502, "timestamps": { "providerDataReceivedUnixMs": 978347471111,