resample_trades_into_ohlcv#

resample_trades_into_ohlcv(df, timeframe)[source]#

Resample incoming “tick” data.

  • The incoming DataFrame is not groupe by pairs yet, but presents stream of data from the blockchain.

    It must have columns pair, amount, price, exchange_rate. It will be indexed by timestamp for the operations.

  • There must be a price given externally for the first open

  • Build OHLCV dataframe from individual trades

  • Handle any exchange rate conversion

  • Any missing values will be filled with the last valid close

  • Exchange rate resample is the avg exchange rate of the candle. Thus, resampled data might not be accurately converted between native quote asset and US dollar value. Any currency conversion must happen before.

… and be timestamp indexed.

Parameters:
  • df (DataFrame) –

    DataFrame of incoming trades.

    Must have columns price, amount

  • freq

    Pandas frequency string for the new timeframe duration.

    E.g. D for daily.

    See https://stackoverflow.com/a/35339226/315168

  • offset – Allows you to “shift” candles

  • conversion – Convert the incomign values if needed

  • timeframe (Timeframe) –

Returns:

OHLCV dataframes that are grouped by pair.

Open price is not the price of the previous close, but the first trade done within the timeframe.

Return type:

DataFrame