Skip to content

Commit

Permalink
optimize fetch tronscan
Browse files Browse the repository at this point in the history
  • Loading branch information
tronsave authored Mar 3, 2025
1 parent fd174b6 commit 440e590
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fees/tronsave/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { CHAIN } from "../../helpers/chains";
import { httpGet } from "../../utils/fetchURL";

const TRON_SAVE_ADDRESS = "TWZEhq5JuUVvGtutNgnRBATbF8BnHGyn4S";
const LIMIT = 20;
const LIMIT = 50;

const getDailyFees = async (fromTimestamp: number, endTimestamp: number) => {
let start = 0;
let totalFees = 0;
let hasMoreData = true;

while (hasMoreData) {
const trxTransactions = await httpGet(`https://apilist.tronscanapi.com/api/transfer/trx?address=${TRON_SAVE_ADDRESS}&start=${start}&limit=${LIMIT}&direction=2&&reverse=false&fee=true&db_version=1&start_timestamp=${fromTimestamp}&end_timestamp=${endTimestamp}`);
const trxTransactions = await httpGet(`https://apilist.tronscanapi.com/api/transfer/trx?address=${TRON_SAVE_ADDRESS}&start=${start}&limit=${LIMIT}&direction=2&reverse=false&start_timestamp=${fromTimestamp}&end_timestamp=${endTimestamp}`);

if (!trxTransactions.data || trxTransactions.data.length === 0) {
if (trxTransactions.page_size === 0) {
break;
}

totalFees += trxTransactions.data.reduce((acc: number, curr: any) => acc + Number(curr.amount) / 1000000, 0);
// If we got fewer results than the limit, we've reached the end
if (trxTransactions.data.length < LIMIT) {
if (trxTransactions.page_size < LIMIT) {
hasMoreData = false;
} else {
// Move to the next page
Expand Down

0 comments on commit 440e590

Please sign in to comment.