diff --git a/script/blockchain/binance.ts b/script/blockchain/binance.ts index 6b6beeb28..5d888cea5 100644 --- a/script/blockchain/binance.ts +++ b/script/blockchain/binance.ts @@ -26,7 +26,11 @@ let cachedAssets = []; async function retrieveBep2AssetList(): Promise { console.log(`Retrieving token asset infos from: ${binanceUrlTokenAssets}`); - const { assetInfoList } = await axios.get(binanceUrlTokenAssets).then(r => r.data); + const { assetInfoList } = await axios.get(binanceUrlTokenAssets) + .then(r => r.data) + .catch(function (error) { + console.log(JSON.stringify(error)) + }); console.log(`Retrieved ${assetInfoList.length} token asset infos`); return assetInfoList } @@ -128,6 +132,10 @@ export class BinanceAction implements ActionInterface { async updateAuto(): Promise { // retrieve missing token images; BEP2 (bep8 not supported) const bep2InfoList = await retrieveBep2AssetList(); + if (bep2InfoList.length < 5) { + console.log(`ERROR: No Binance token info is returned! ${bep2InfoList.length}`); + return; + } const denylist: string[] = readJsonFile(getChainDenylistPath(binanceChain)) as string[]; const toFetch = findImagesToFetch(bep2InfoList, denylist); @@ -140,6 +148,10 @@ export class BinanceAction implements ActionInterface { // binance chain list const tokenList = await generateBinanceTokensList(); + if (tokenList.length < 5) { + console.log(`ERROR: no token pair info available from Binance DEX! ${tokenList.length}`); + return; + } const list = createTokensList("BNB", tokenList, "2020-10-03T12:37:57.000+00:00", // use constants here to prevent changing time every time 0, 1, 0); @@ -159,8 +171,24 @@ class BinanceMarket { async function generateBinanceTokensList(): Promise { const decimals = CoinType.decimals(CoinType.binance) const BNBSymbol = CoinType.symbol(CoinType.binance) - const markets: [BinanceMarket] = await axios.get(`${config.binanceDexURL}/v1/markets?limit=10000`).then(r => r.data); - const tokens = await axios.get(`${config.binanceDexURL}/v1/tokens?limit=10000`).then(r => r.data); + const markets: BinanceMarket[] = await axios.get(`${config.binanceDexURL}/v1/markets?limit=10000`) + .then(r => r.data) + .catch(function (error) { + console.log(JSON.stringify(error)) + }); + if (markets.length < 5) { + console.log(`ERROR: No markets info is returned from Binance DEX! ${markets.length}`); + return []; + } + const tokens = await axios.get(`${config.binanceDexURL}/v1/tokens?limit=10000`) + .then(r => r.data) + .catch(function (error) { + console.log(JSON.stringify(error)) + }); + if (tokens.length < 5) { + console.log(`ERROR: No tokens info is returned from Binance DEX! ${tokens.length}`); + return []; + } const tokensMap = Object.assign({}, ...tokens.map(s => ({[s.symbol]: s}))); const pairsMap = {} const pairsList = new Set();