Skip to content

Commit

Permalink
fix: Add logic to bypass OKX API rate limit (#2227)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Gamja authored Feb 3, 2025
1 parent fcb2df3 commit 556dc56
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions _script/evm_okx/evm_okx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,39 @@ async function main() {
(item) => !!item.platforms[assetPlatformId]
);

const response = await fetch(
`https://www.okx.com/api/v5/dex/aggregator/all-tokens?chainId=${chainId}`,
{
headers: {
"OK-ACCESS-KEY": apiKey,
"OK-ACCESS-SIGN": cryptoJS.enc.Base64.stringify(
cryptoJS.HmacSHA256(
timestamp +
"GET" +
`/api/v5/dex/aggregator/all-tokens?chainId=${chainId}`,
secretKey
)
),
"OK-ACCESS-TIMESTAMP": timestamp,
"OK-ACCESS-PASSPHRASE": passphrase,
},
}
);
const fetchTokenData = () => {
return new Promise((resolve) => {
setTimeout(async () => {
const response = await fetch(
`https://www.okx.com/api/v5/dex/aggregator/all-tokens?chainId=${chainId}`,
{
headers: {
"OK-ACCESS-KEY": apiKey,
"OK-ACCESS-SIGN": cryptoJS.enc.Base64.stringify(
cryptoJS.HmacSHA256(
timestamp +
"GET" +
`/api/v5/dex/aggregator/all-tokens?chainId=${chainId}`,
secretKey
)
),
"OK-ACCESS-TIMESTAMP": timestamp,
"OK-ACCESS-PASSPHRASE": passphrase,
},
}
).catch((error) => {
console.log(error);
});

const responseData = await response.json();
resolve(responseData);
}, 31000); // NOTE For OKX API rate limit
});
};

const jsonResponse = await response.json();
const fetchedTokenData = await fetchTokenData();

const erc20Assets = jsonResponse.data || [];
const erc20Assets = fetchedTokenData.data || [];

const currentAssetContractAddresses = currentAssets.map((asset) => {
return asset.contract.toLowerCase();
Expand Down

0 comments on commit 556dc56

Please sign in to comment.