Skip to content

Microstructure Indicators

order_imbalance(currency, by='hour', root=None)

Compute hourly order imbalance for a given currency using historical_fiat data.

Parameters:

Name Type Description Default
currency str

Fiat currency code.

required
by hour

Aggregation level.

'hour'
root path - like

Root of processed data from Phase 1.

None

Returns:

Type Description
DataFrame

One row per (date, hour) with: - date - hour - currency - buy_volume - sell_volume - imbalance

Source code in src\p2p_analytics\microstructure.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def order_imbalance(
    currency: str,
    by: Literal["hour"] = "hour",
    root: str | None = None,
) -> pd.DataFrame:
    """
    Compute hourly order imbalance for a given currency using historical_fiat data.

    Parameters
    ----------
    currency : str
        Fiat currency code.
    by : {'hour'}, default 'hour'
        Aggregation level.
    root : path-like, optional
        Root of processed data from Phase 1.

    Returns
    -------
    pandas.DataFrame
        One row per (date, hour) with:
        - date
        - hour
        - currency
        - buy_volume
        - sell_volume
        - imbalance
    """
    df = load_binance_currency(currency, root=root)
    return _order_imbalance_core(df, currency, by=by)