Introduction:
The User Portfolio query gives a summary of the total portfolio balance and the breakdown of the each asset for a given account.
It's possible to query the portfolio balance at different time points, either HOURLY
, DAILY
, WEEKLY
or MONTHLY
(30 days).
The portfolio balance will be given at the nearest hour of the given time.
Availability
The portfolio data is only available from 16th Feb 2021 onwards.
Authentication
Provide your API key in the headers
{
"x-api-key": "your-key-here"
}
Sample GraphQL Queries:
Get the latest user portfolio balance:
Not passing any parameters to the portfolio query will get you the latest available portfolio balance at the nearest hour.
query UserPortfolioQuery {
user {
portfolio {
items {
timestamp
total {
value
timestamp
currency
}
balances {
items {
amount {
currency
timestamp
value
}
asset {
name
}
}
}
}
}
}
}
Result
{
"data": {
"user": {
"portfolio": {
"items": [
{
"timestamp": "2021-03-02T16:00:00.000Z",
"total": {
"value": "9131.364413355",
"timestamp": "2021-03-02T16:00:00.000Z",
"currency": "GBP"
},
"balances": {
"items": [
{
"amount": {
"currency": "ETH",
"timestamp": "2021-03-02T16:00:00.000Z",
"value": "0.519577995"
},
"asset": {
"name": "Ethereum"
}
},
{
"amount": {
"currency": "BTC",
"timestamp": "2021-03-02T16:00:00.000Z",
"value": "0.24864699"
},
"asset": {
"name": "Bitcoin"
}
},
...
]
}
}
]
}
}
}
}
Get user portfolio balance for a specific date and time:
Pass in an endDate
(ISO 8601 date and time format) parameter on the portfolio query to get the portfolio balance on a specific date and time.
query UserPortfolioQuery {
user {
portfolio(endDate: "2021-03-01T12:00:00.000Z") {
items {
timestamp
total {
value
timestamp
currency
}
balances {
items {
amount {
currency
timestamp
value
}
asset {
name
}
}
}
}
}
}
}
Result
{
"data": {
"user": {
"portfolio": {
"items": [
{
"timestamp": "2021-03-01T12:00:00.000Z",
"total": {
"value": "9131.364413355",
"timestamp": "2021-03-01T12:00:00.000Z",
"currency": "GBP"
},
"balances": {
"items": [
{
"amount": {
"currency": "ETH",
"timestamp": "2021-03-01T12:00:00.000Z",
"value": "0.519577995"
},
"asset": {
"name": "Ethereum"
}
},
{
"amount": {
"currency": "BTC",
"timestamp": "2021-03-01T12:00:00.000Z",
"value": "0.24864699"
},
"asset": {
"name": "Bitcoin"
}
},
...
]
}
}
]
}
}
}
}
Get user portfolio balances within specific times:
Provide a startDate
, endDate
and timePeriod
. The startDate and endDate must be in ISO 8601 date and time format and the timePeriod can be either HOURLY
, DAILY
, WEEKLY
or MONTHLY
(30 days).
A sequence of portfolio balance will be returned from the specified startDate to the specified endDate with a frequency defined by the timePeriod.
There is a limit of 200 portfolio balance time periods within the specified startDate and endDate. Portfolio balances exceeding the 200 limit will not be included in the response.
query UserPortfolioQuery {
user {
portfolio(startDate: "2021-02-23T12:00:00.000Z", endDate: "2021-03-02T12:00:00.000Z", timePeriod: WEEKLY) {
items {
timestamp
total {
value
timestamp
currency
}
balances {
items {
amount {
currency
timestamp
value
}
asset {
name
}
}
}
}
}
}
}
Result
{
"data": {
"user": {
"portfolio": {
"items": [
{
"timestamp": "2021-03-02T12:00:00.000Z",
"total": {
"value": "2284557.6364358384",
"timestamp": "2021-03-02T12:00:00.000Z",
"currency": "GBP"
},
"balances": {
"items": [
{
"amount": {
"currency": "ETH",
"timestamp": "2021-03-02T12:00:00.000Z",
"value": "0.519577995"
},
"asset": {
"name": "Ethereum"
}
},
{
"amount": {
"currency": "BTC",
"timestamp": "2021-03-02T12:00:00.000Z",
"value": "0.24864699"
},
"asset": {
"name": "Bitcoin"
}
},
...
]
}
},
{
"timestamp": "2021-02-23T12:00:00.000Z",
"total": {
"value": "2069491.9749807473",
"timestamp": "2021-02-23T12:00:00.000Z",
"currency": "GBP"
},
"balances": {
"items": [
{
"amount": {
"currency": "ETH",
"timestamp": "2021-02-23T12:00:00.000Z",
"value": "0.519577995"
},
"asset": {
"name": "Ethereum"
}
},
{
"amount": {
"currency": "BTC",
"timestamp": "2021-02-23T12:00:00.000Z",
"value": "0.19737407"
},
"asset": {
"name": "Bitcoin"
}
},
...
]
}
}
]
}
}
}
}
Get the portfolio balance in another currency:
Converting the portfolio balance to another currency is done by using the in(currency: "<CURRENCY>")
query available in the Amount
type.
The timestamp
field under the in(currency: "<CURRENCY>")
query represents the timestamp of the conversion rate used.
query UserPortfolioQuery {
user {
portfolio {
items {
timestamp
total {
value
timestamp
currency
in(currency: "USD") {
currency
value
timestamp
}
}
balances {
items {
amount {
value
timestamp
currency
in(currency: "USD") {
currency
value
timestamp
}
}
asset {
name
}
}
}
}
}
}
}
Result
{
"data": {
"user": {
"portfolio": {
"items": [
{
"timestamp": "2021-03-02T16:00:00.000Z",
"total": {
"currency": "GBP",
"value": "9131.364413355",
"timestamp": "2021-03-02T16:00:00.000Z",
"in": {
"currency": "USD",
"value": "12692.5965345635",
"timestamp": "2021-03-02T16:12:00.000Z"
}
},
"balances": {
"items": [
{
"amount": {
"currency": "ETH",
"value": "0.519577995",
"timestamp": "2021-03-02T16:00:00.000Z",
"in": {
"currency": "USD",
"value": "926.25531981892",
"timestamp": "2021-03-02T16:12:00.000Z"
}
},
"asset": {
"name": "Ethereum"
}
},
{
"amount": {
"currency": "BTC",
"value": "0.24864699",
"timestamp": "2021-03-02T16:00:00.000Z",
"in": {
"currency": "USD",
"value": "13965.31",
"timestamp": "2021-03-02T16:12:00.000Z"
}
},
"asset": {
"name": "Bitcoin"
}
},
...
]
}
}
]
}
}
}
}