Function getAveragePrice

  • Calculates VWAP (Volume Weighted Average Price) for a symbol.

    Uses the last 5 1-minute candles to calculate:

    • Typical Price = (high + low + close) / 3
    • VWAP = sum(typical_price * volume) / sum(volume)

    If volume is zero, returns simple average of close prices.

    Parameters

    • symbol: string

      Trading pair symbol (e.g., "BTCUSDT")

    Returns Promise<number>

    Promise resolving to VWAP price

    const vwap = await getAveragePrice("BTCUSDT");
    console.log(vwap); // 50125.43