Add historical perp stats endpoint

This commit is contained in:
Riordan Panayides 2021-08-31 00:49:16 +01:00
parent 83dc6696a9
commit aa1dbc8c0a
1 changed files with 35 additions and 1 deletions

View File

@ -80,13 +80,47 @@ app.get("/spot/change/24", async (req, res) => {
}
})
app.get("/perp", async (req, res) => {
try {
const mangoGroup = req.query.mangoGroup as string
if (!mangoGroup) {
throw new Error("Missing mangoGroup param")
}
const stats = await sequelize.query(
`SELECT time_bucket('60 minutes', time) AS "hourly",
"name",
first("longFunding", "time")::float AS "oldestLongFunding",
first("shortFunding", "time")::float AS "oldestShortFunding",
last("longFunding", "time")::float AS "latestLongFunding",
last("shortFunding", "time")::float AS "latestShortFunding",
avg("openInterest")::float AS "openInterest",
avg("baseOraclePrice")::float AS "baseOraclePrice",
min("time") AS "time"
FROM perp_market_stats
WHERE time > current_date - interval '90' day AND "mangoGroup" = :mangoGroup
GROUP BY "hourly", "name"
ORDER BY "hourly" ASC;`,
{
replacements: { mangoGroup },
type: QueryTypes.SELECT,
}
)
res.send(stats)
} catch (e) {
console.log("Error inserting data", e)
}
})
app.get("/perp/funding_rate", async (req, res) => {
try {
const market = req.query.market as string
const mangoGroup = req.query.mangoGroup as string
if (!market) {
throw new Error("Missing mangoGroup param")
throw new Error("Missing market param")
}
if (!mangoGroup) {
throw new Error("Missing mangoGroup param")