How to use on-chain TWAP
calculate_twap
set_checkpoint
function.
data_type
: enum of the data type you are requesting (See DataType structure). By providing the enum data type, you also provide the pair id (for spot entries), or the pair id and the expiration timestamp (for futures)aggregation_mode
: aggregation mode to use for combining the many data sources available in Pragma. Use the structure AggregationMode defined in Pragma. Option must currently be set to MEDIAN
or MEAN
, . Additional options VWAP
, EXPONENTIAL_DECAY
are coming soon.time
: The duration (in seconds ) over which you want to calculate the TWAP. The TWAP will be calculated between start_time
and start_time
+ time
.start_time
: The start time (in seconds) from which you want to calculate the TWAP. The TWAP will be calculated between start_time
and start_time
+ time
.twap
: The TWAP for the requested data type, aggregation mode, time and start time. The TWAP is multiplied by 10^decimals.decimals
: number of decimals, i.e. , the number of places that value has been shifted to allow for greater accuracy.