Skip to content

contango.stream.indicators.state.vwap_state

contango.stream.indicators.state.vwap_state

VWAPState

Bases: Enum

The current price location relative to VWAP.

Attributes:

Name Type Description
BELOW_LOWER

The price is below the lower band.

BETWEEN_LOWER_AND_MIDDLE

The price is between the lower & VWAP band.

ABOVE_MIDDLE

The price is above the VWAP band.

get_state classmethod

get_state(price: float, snapshot: VWAPSnapshot) -> VWAPState

Returns the zone of the price relative to the VWAP bands.

Parameters:

Name Type Description Default
price float

The close price for the current bar.

required
snapshot VWAPSnapshot

The VWAP snapshot for the current bar.

required

Returns:

Name Type Description
VWAPState VWAPState

The price relative to the VWAP snapshot.

Source code in src\contango\stream\indicators\state\vwap_state.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@classmethod
def get_state(cls, price: float, snapshot: VWAPSnapshot) -> VWAPState:
    """
    Returns the zone of the price relative to the VWAP bands.

    Args:
        price: The close price for the current bar.
        snapshot: The VWAP snapshot for the current bar.

    Returns:
        VWAPState: The price relative to the VWAP snapshot.
    """
    if price < snapshot.lower:
        return VWAPState.BELOW_LOWER
    if price < snapshot.vwap:
        return VWAPState.BETWEEN_LOWER_AND_VWAP
    return VWAPState.ABOVE_VWAP