# Perp Finance CoinGecko API
## API endpoints
### /contracts
The /contracts endpoint provides a summary of all contracts traded on the exchange.
Response:
```
[
{
"ticker_id": "ETH_USDC",
"base_currency": "ETH",
"target_currency": "USDC",
"last_price":"1400", // last price of ETH in USDC
"base_volume":"637", // 24 hr volume in ETH
"target_volume":"892538", // 24 hr volume in USDC
"high":”51.3”, // highest price in last 24hrs
“low”:”49.2”, // lowest price in last 24hrs
"product_type": "Perpetual",
"open_interest": ,
"funding_rate": ,
"next_funding_rate_timestamp": , // assumption that it's 1 hr in perp
},
...similar objects for YFI, BTC, DOT and more
]
```
### Response object params
- **ticker_id, base_currency, target_currency, funding_rate**: A ticker like ETH-USDC, BTC-USDC etc.
We need to fetch all available markets on Perp to show these info.
We'll do that by calling redash API for funding rates as it shows funding rates of all the asset pairs alons with asset pairs name as well.
Funding rate can also be fetched from subgraph's funding rate changed event.
```graphql
{
fundingRateUpdatedEvents(first: 5, orderBy: blockNumber,
orderDirection: desc, , where: { amm_in:
["0x8d22F1a9dCe724D8c1B4c688D75f17A2fE2D32df"]}) {
id
amm
rate
underlyingPrice
timestamp
}
}
```
- **base_volume, target_volume**: From redash we can get the volume for past 24 hours in terms of USDC (**target_volume**)
To get volume in eth we need to calculate it over the time unless we do `base_volume = target_volume / priceETH` which would be very wrong due to ETH price volatility during those 24hrs.
**We suggest to add eth volume key stats over time into the redash dashboard**
ADD postionalETH sum in the following query:
```sql
SELECT
SUM(fee) as _fee,
marketPair,
SUM(positionNotional) as _totalNotionalTraded,
CAST(DATE(logTimestamp) as string) as _date
FROM
perp."perp-server-production-TraderPositionLogTable"
WHERE
eventType = 'PositionChanged'
AND DATE_DIFF('DAY', DATE(logTimestamp), CURRENT_DATE()) <
{{ WITHIN_DAYS }}
GROUP BY
DATE(logTimestamp),
marketPair
ORDER BY
DATE(logTimestamp) DESC
```
- **high, low**
For high low we will query subgraph over last 24 hours and get the lowest/higest spot prices given on `PositionChanged` event.
- **last_price**
entry price of last tx(position changed event) => current rate of eth in usdc. Will be queried on subgraph like this:
<!-- For each market we can get
https://metadata.perp.exchange/production.json
"0x0f346e19f01471c02485df1758cfd3d624e399b4", "0x6de775aabeeede8efdb1a257198d56a3ac18c2fd",
"0x8d22f1a9dce724d8c1b4c688d75f17a2fe2d32df",
"0xd41025350582674144102b74b8248550580bb869"
```
{
ammPositions(
where:
{ amm_not_in : ["0x0f346e19f01471c02485df1758cfd3d624e399b4", "0x6de775aabeeede8efdb1a257198d56a3ac18c2fd","0x8d22f1a9dce724d8c1b4c688d75f17a2fe2d32df","0xd41025350582674144102b74b8248550580bb869"]}
){
id
amm
}
}
``` -->
```graphql
{
positionChangedEvents(first: 1, orderBy: blockNumber,
orderDirection: desc, where: { amm_in:
["0x8d22F1a9dCe724D8c1B4c688D75f17A2fE2D32df"]}) {
id
spotPrice
fundingPayment
}
}
```
- **open_interest**
What is open interest -> using long / short open interest, should we add them for total open interest? (mostly yess we add them)
Open interest over last 24 hours? Is that what redash shows us? probably not. It shows us the current open interest across all positions. Coingecko expects open_interest over last 24 hrs, how do we return that?
<br/>
<br/>
<br/>
### Question and Doubts
- What to return for open interest? Redash returns us current open interest for long and short positions of every market. Should we just add them and return?
- How do we get base volume for last 24hrs? (Volume in ETH, DOT etc)
Base Volume and Target Volume can be seen in redash on `USDC Trading Volume by Day`, they should be fetched from **Trades By Market API but that is not working atm**
- Are there any other fields which you'd like to return or any other endpoint to create? Like we could show fees generated over last 24hrs etc.