# PERP CoinGecko-API
We will only have one endpoint which will give us details about all the pairs that perp supports.
The endpoint will be hosted on `/pairs`
For now the Example Response Looks like this:
#### Example 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_USDC, BTC_USDC, DOT_USDC and any future pairs
]
```
#### How do we get the list of all markets on perp?
We run the following command to get all AMM contract Addresses from metadata.perp.exchange.
```bash
curl 'https://metadata.perp.exchange/production.json' | jq '.layers.layer2.contracts | with_entries(select(.value.name=="Amm")) '
```
##### basic information
**perp team response**: amm.js can be used to query all amm market addresses and get basic information such as symbols of pairs.
https://github.com/perpetual-protocol/perp-contract-demo/blob/main/amms.js
#### How do we get the fields for each AMM ?
We now name and the contract address from above method.
##### Ticker ID / Base Currency / Target Currency / Product Type
Will be calculated from the name of the AMM. Product Type is fixed as perpetual.
##### Funding Rate / Next Funding Rate Timestamp
Funding rate will be fetched from subgraph's funding rate changed event.
We will fetch the latest event in the graph and use that as a funding rate.
We will also add `1 hour` (hardcoded) to the timestamp to get the next update timestamp.
```graphql
{
fundingRateUpdatedEvents(first: 5, orderBy: blockNumber,
orderDirection: desc, , where: { amm_in:
["0x8d22F1a9dCe724D8c1B4c688D75f17A2fE2D32df"]}) {
id
amm
rate
underlyingPrice
timestamp
}
}
```
##### 24hr-High / 24hr-Low / Latest Price
For price data we want to query position data from the subgraph.
using the spot price data. We wil iterate over them to get the high-low details.
```graphql
{
positionChangedEvents(first: 1, orderBy: blockNumber,
orderDirection: desc, where: { amm_in:
["0x8d22F1a9dCe724D8c1B4c688D75f17A2fE2D32df"]}) {
id
spotPrice
fundingPayment
}
}
```
##### Base Volume / Target Volume
We plan on using subgraph to get the all position changed events for past 24 hours for each AMM, then use the following formula
```math
TargetVolume = sum of positionalNotional
BaseVolume = sum of (positionalNotional / spotPrice)
```
##### Open Interest
We need to understand what open interest is. CoinGecko wants the past 24 hours data on open interest.
#### Definitions
* Open Interest: sum of Long and Short positions open on the protocol
* Target Volume: volume of usdc traded for each market.
* Base Volume: volume of eth traded for each market.
* Position: position information for all AMM per trader
* AmmPosition: position information for certain AMM per trader
#### Pending Questiosn and queries
-- How to calculate Open Interest Total?
-- How to calculate Open Interest in past 24 hours?
**perp team response**: for these 2 properties we haven't implemented yet on subgraph, but it should be available in early Feb.
-- The following is a list of fields that we are not working on but are in the coingecko spec document:
- bid
- ask
- next_funding_rate (dont know how to predict)
- contract_price // contract_price_currency (probably not applicable)
-- We are not making an API Endpoint for orderbook as discussed with Nick.
-- Are there any other feilds that we need to work on ?
-- Are there any changes or things we should know before we start implmenting the above?