Get coin gains and losses
Find gains and losses data for a specific coin over different time intervals. On Coinranking we use this endpoint on our coin detail page.
https://api.coinranking.com/v2/coin/:uuid/gains-and-losses
Preview access
Free, Basic and Startup plans can test this endpoint with five successful requests per account per UTC day. Use the documented endpoint URL with your existing API key. Preview access is applied automatically. The allowance resets at 00:00 UTC.
All API keys, resource IDs, query parameters and pagination requests share this endpoint's allowance for your account. Failed requests do not consume the preview allowance. Successful previews also count toward your normal API usage, and your plan's result, historical-window and rate limits still apply. See endpoint previews for limits, response headers and quota errors.
Path parameters
| Parameter | Description |
|---|---|
uuid String | UUID of the coin you want to request gains and losses for. UUIDs of coins can be found using the Get coins endpoint or by checking the URL on coinranking.com, e.g. https://coinranking.com/coin/Qwsogvtv82FCd+bitcoin-btc is the URL for Bitcoin, and the part before the + (Qwsogvtv82FCd) is the UUID. |
Query parameters
| Parameter | Description |
|---|---|
referenceCurrencyUuid (optional) String | UUID of coin (either fiat or crypto), in which all the prices are calculated. Defaults to US Dollar, but you can use any coin. You can find UUIDs for reference currencies in any coin endpoint, including a convenient dedicated reference currency endpoint Default value: yhjMzLPhuIDlExample:
https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/gains-and-losses?referenceCurrencyUuid=5k-_VTxqtCEI
|
interval (optional) String | Time interval for the gains and losses calculation Default value: dayAllowed values: day week month Example:
https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/gains-and-losses?interval=week
|
limit (optional) Number | Number of gains and losses entries to return Default value: 50 Maximum value: 100Example:
https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/gains-and-losses?limit=25
|
Code examples
curl 'https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/gains-and-losses?referenceCurrencyUuid=5k-_VTxqtCEI&interval=week&limit=25' \
-H 'x-access-token: your-api-key' \
-G const options = {
headers: {
'x-access-token': 'your-api-key',
},
};
fetch('https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/gains-and-losses?referenceCurrencyUuid=5k-_VTxqtCEI&interval=week&limit=25', options)
.then((response) => response.json())
.then((result) => console.log(result)); <?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/gains-and-losses?referenceCurrencyUuid=5k-_VTxqtCEI&interval=week&limit=25",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"x-access-token: your-api-key"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; import requests
headers = {
'x-access-token': 'your-api-key'
}
response = requests.request("GET", "https://api.coinranking.com/v2/coin/Qwsogvtv82FCd/gains-and-losses?referenceCurrencyUuid=5k-_VTxqtCEI&interval=week&limit=25", headers=headers)
print(response.text) Response
HTTP/1.1 200 OK
{
"status": "success",
"data": {
"gainsAndLosses": [
{
"timestamp": 1640995200,
"price": "47156.85",
"change": "2.34"
},
{
"timestamp": 1640908800,
"price": "46078.12",
"change": "-1.87"
},
{
"timestamp": 1640822400,
"price": "46952.73",
"change": "0.92"
}
]
}
} Response fields
| Property | Description |
|---|---|
status String | Status of the request Allowed values:success |
data Object | |
data.gainsAndLosses Object[] | Array of gains and losses data points |
data.gainsAndLosses.timestamp Number | Epoch timestamp of the data point |
data.gainsAndLosses.price String | Price of the coin at this timestamp |
data.gainsAndLosses.change String | Percentage change from the previous interval |
Error response
HTTP/1.1 404 Not Found
{
"status": "fail",
"type": "COIN_NOT_FOUND",
"message": "Coin not found"
} Error responses
| Name type | Description |
|---|---|
COIN_NOT_FOUND Object | The coin could not be found. Try another UUID |
GAINS_AND_LOSSES_NOT_FOUND Object | Gains and losses data could not be found for this coin |
| Name type | Description |
|---|---|
VALIDATION_ERROR Object | The request could not be validated. The response should provide more details. |
REFERENCE_UNAVAILABLE Object | The reference currency used in the request is not available. Choose another UUID. |