# Oracle Prices & API Information

### Daily Volume-Weighted Average Price Reference:

Price calculated daily at 00:05:00 UTC

Trade data (prices, volume) collected from BingX, BitGet, BitMart, Coinex and Mexc.

For each one-hour interval beginning from 00:00 UTC until 23:59:59 UTC every day, all trades are first ordered by price. The
total volume of the interval is summed. Next, the first and last quartiles of volume are removed, leaving the middle 50% of
volume prices. If a trade straddles the upper- or lower-quartile threshold, its volume is split - so that 50% of total volume
is always achieved. For each trade, price is multiplied by volume, and then all are summed and divided by the 50% total volume.
This gives a volume weighted hourly average price. Lastly, the arithmetic mean of all hourly averages is taken. If there exists
any hour for which there is no volume, for consistency, the daily price will not be calculated. This approach combines the
benefits of:

- TWAP (time-weighted average price)
- volume-weighting
- median price-filtering

### Hourly Volume-Weighted Average Price Reference:

Price calculated hourly at {hour}:05:00 UTC

Trade data (prices, volume) collected from BingX, BitGet, BitMart, Coinex, and Mexc.

For each fifteen-minute interval beginning from xx:00 until xx:59:59 every hour, all trades are first ordered by price.
The total volume of the interval is summed. Next, the first and last quartiles of volume are removed, leaving the middle
50% of volume prices. If a trade straddles the upper- or lower-quartile threshold, its volume is split - so that 50% of
total volume is always achieved. For each trade, price is multiplied by volume, and then all are summed and divided by
the 50% total volume. This gives a volume weighted quarterly average price. Lastly, the arithmetic mean of all quarterly
averages is taken. If there exists any quarter for which there is no volume, for consistency, the hourly price will not
be calculated. This approach combines the benefits of:

- TWAP (time-weighted average price)
- volume-weighting
- median price-filtering

Oracle Prices Historic Lookup

Ticker A | Ticker B | Price Type | Year | Month | Day | Time Begin (UTC) | Time End (UTC) | Price |
---|---|---|---|---|---|---|---|---|

NEXA |

** prices available beginning 2024-07-23 @ 17:00:00 UTC

wallywallet.org/_api/v0/now/dailyavg/usdt/nexa

----------------------------------------

HISTORIC LOOKUP DAILY AVERAGE:

wallywallet.org/_api/v0/dailyavg/usdt/nexa?time=< epoch seconds >

----------------------------------------

CURRENT HOURLY AVERAGE:

wallywallet.org/_api/v0/now/hourlyavg/usdt/nexa

----------------------------------------

HISTORIC LOOKUP HOURLY AVERAGE:

wallywallet.org/_api/v0/hourlyavg/usdt/nexa?time=< epoch seconds >

###
Current Averages require no query parameters, and reflect price for
the previous period - day or hour - as of the time the request is made.
If a price was not calculated for that period, the previous period's
price is returned. Prices are calculated 5 minutes after the day or hour.
All times are given in UTC.

Historic Averages require one query parameter: time (in epoch seconds).
The time parameter must be less than or equal to current time, to be
considered valid. These endpoints return a price for the previous period
- day or hour (if one was calculated) - prior to the value of epoch seconds
given. Prices are calculated 5 minutes after the day or hour. All times
are given in UTC.

{ "type": String, "msg": Object of { "data": String (32 byte hex) "signature": String (64 byte hex) }, "epochSeconds": Long, "price": Decimal number in a String, "pairPriceUnit": String }Example response:

###
EXAMPLE REQUEST QUERY STRINGS:

Current Daily Average:

http://wallywallet.org/_api/v0/now/dailyavg/usdt/nexa

----------------------------------------

Current Hourly Average:

http://wallywallet.org/_api/v0/now/hourlyavg/usdt/nexa

----------------------------------------

Historic Lookup Daily Average:

http://wallywallet.org/_api/v0/dailyavg/usdt/nexa?time=1722489634

----------------------------------------

Historic Lookup Hourly Average:

http://wallywallet.org/_api/v0/hourlyavg/usdt/nexa?time=1722489634

Returns parsed data object with four fields:

tickerA, tickerB, epochSeconds, and price

@Serializable

data class OraclePrice(val type: String,

val msg: OracleMsg,

val epochSeconds: Long,

@Serializable(with = BigDecimalSerializer::class)val price: BigDecimal)

val pairPriceUnit: String,

data class ParsedData( val tickerA: String,

val tickerB: String,

val epochSeconds: Long,

val price: Long)

fun hexStringToByteArray(hex: String): ByteArray {

val result = ByteArray(hex.length / 2)

for (i in hex.indices step 2)

{

val byte = hex.substring(i, i + 2).toInt(16).toByte()

result[i / 2] = byte

}

return result

}

fun parseData(data: ByteArray): ParsedData {

require(data.size == 32) { "Data must be exactly 32 bytes" }

val string1 = String(data.sliceArray(0..7)).trimEnd { it.toInt() == 0 }

val string2 = String(data.sliceArray(8..15)).trimEnd { it.toInt() == 0 }

val longBuffer1 = ByteBuffer.wrap(data.sliceArray(16..23))

.order(ByteOrder.LITTLE_ENDIAN)

val unsignedLongValue1 = longBuffer1.long

val longBuffer2 = ByteBuffer.wrap(data.sliceArray(24..31))

.order(ByteOrder.LITTLE_ENDIAN)

val unsignedLongValue2 = longBuffer2.long

return ParsedData(string1, string2, unsignedLongValue1, unsignedLongValue2)

}

val response = client.get("https://wallywallet.org/_api/v0/hourlyavg/usdt/nexa?

time=1722489634").bodyAsText()

val message = Json.decodeFromString< OraclePrice>(response).msg

val data = message.data

val signature = message.signature

val byteArray = hexStringToByteArray(data)

val parsedData = parseData(byteArray)

code goes here