Skip to content

Commit

Permalink
Lower request to bx-digital (#3634)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxiao-cll authored Jan 17, 2025
1 parent 5a1a720 commit 1c516b6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-books-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/bx-digital-adapter': patch
---

Adjust rate limiter
2 changes: 1 addition & 1 deletion packages/sources/bx-digital/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const adapter = new Adapter({
rateLimiting: {
tiers: {
default: {
rateLimit1m: 6,
rateLimit1m: 1,
note: 'Reasonable limits',
},
},
Expand Down
38 changes: 26 additions & 12 deletions packages/sources/bx-digital/src/transport/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,31 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
})
}

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: {
Expand All @@ -55,15 +75,9 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
},
},
}
} else {
return {
params: param,
response: {
errorMessage: `The data provider didn't return any value for ${param.securityId}`,
statusCode: 502,
},
}
}
})

return valid.concat(missing)
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1c516b6

Please sign in to comment.