app.js
/**
 * Called when there is a new high in the funding rate
 * @param symbol
 * @param oldRate
 * @param newRate
 */
Called when there is a new high in the funding rate
@param symbol
@param oldRate
@param newRate
Called when there is a new high in the funding rate @param symbol @param oldRate @param newRate
function onFundingRateChanged(symbol, oldRate, newRate) {
    if (rateUpdates[symbol] === undefined) {
        rateUpdates[symbol] = 0;
    }
    rateUpdates[symbol] += 1;
    trackRate(symbol, newRate);
    if (oldRate > newRate) {
        return;
    }
    if (rateUpdates[symbol] > 100) {
        const best = recentBestRate(symbol);
        logger.results(`${symbol.toUpperCase()} Last Rate: ${util.roundDown(newRate * 100, 4)}% (APR ${util.roundDown(newRate * 100 * 365, 2)}%).`);
        rateUpdates[symbol] = 0;
    }
    if (!alertWebhook) {
        return;
    }
    const options = fundingMarkets.find(market => market.symbol === symbol);
    if (!options.alerts) {
        return;
    }
    options.alerts.sort((a, b) => a.rate - b.rate);
    options.alerts.forEach((alert) => {
        if (alert.lastTriggered === undefined) {
            alert.lastTriggered = moment().subtract(1, 'hours');
        }
        const freq = alert.maxFrequency || 5;
        const justNow = moment().subtract(freq, 'minutes');
        const rate = alert.rate / 100.0;
        if (newRate >= rate && oldRate < rate) {
            if (alert.lastTriggered.isBefore(justNow)) {
                logger.error(`Alert fired - ${symbol} rates crossed over ${alert.rate}%. was ${oldRate}, now ${newRate}`);
                callWebhook(alertWebhook, alert.alertMessage, rate, newRate, oldRate);
                alert.lastTriggered = moment();
            } else {
                logger.results(`${symbol} rates crossed over ${alert.rate}%. But sent alert in last ${freq} minutes.`);
            }
        }
    });
}
function onFundingRateChanged ( symbol , oldRate , newRate ) { if ( rateUpdates [ symbol ] === undefined ) { rateUpdates [ symbol ] = 0 ; } rateUpdates [ symbol ] += 1 ; trackRate ( symbol , newRate ) ; if ( oldRate > newRate ) { return ; } if ( rateUpdates [ symbol ] > 100 ) { const best = recentBestRate ( symbol ) ; logger . results ( ` ${ symbol . toUpperCase ( ) } ${ util . roundDown ( newRate * 100 , 4 ) } ${ util . roundDown ( newRate * 100 * 365 , 2 ) } ` ) ; rateUpdates [ symbol ] = 0 ; } if ( ! alertWebhook ) { return ; } const options = fundingMarkets . find ( market => market . symbol === symbol ) ; if ( ! options . alerts ) { return ; } options . alerts . sort ( ( a , b ) => a . rate - b . rate ) ; options . alerts . forEach ( ( alert ) => { if ( alert . lastTriggered === undefined ) { alert . lastTriggered = moment ( ) . subtract ( 1 , 'hours' ) ; } const freq = alert . maxFrequency || 5 ; const justNow = moment ( ) . subtract ( freq , 'minutes' ) ; const rate = alert . rate / 100.0 ; if ( newRate >= rate && oldRate < rate ) { if ( alert . lastTriggered . isBefore ( justNow ) ) { logger . error ( ` ${ symbol } ${ alert . rate } ${ oldRate } ${ newRate } ` ) ; callWebhook ( alertWebhook , alert . alertMessage , rate , newRate , oldRate ) ; alert . lastTriggered = moment ( ) ; } else { logger . results ( ` ${ symbol } ${ alert . rate } ${ freq } ` ) ; } } } ) ; }
Called when there is a new high in the funding rate
 @param symbol
 @param oldRate
 @param newRate
Called when there is a new high in the funding rate @param symbol @param oldRate @param newRate
// only interested in the rate going up... // Show the rate (occasionally) // See if they have a webhook url defined // Any alert levels configured for this market // get the alerts into rate order (lowest rate first) // See if we've crossed over the alert threshold