# API Integrations for Flexible Term Vaults (V4)

{% hint style="success" %}
I**MPORTANT: If you are just starting an API integration, you should use the** [**Version 5 API**](https://sandboxdocs.opentrade.io/opentrade-sandbox/version-5-integrations)**.** It is able to query both V4 and V5 vaults but has several important improvements that will make your life easier. **The Version 4 API  (REST & graphQL) will be deprecated by the end of 2025.** This documentation remains published for customers who are already using the V4 API.&#x20;
{% endhint %}

## Getting Started

### API Types

OpenTrade offers users two different types of API. Both enable users to query the protocol and platform and retrieve data on vaults, loans, transactions, and accounts.&#x20;

#### <mark style="color:yellow;">**REST API**</mark>

The REST API can be used to make queries that return the latest state of vaults, loans, transactions and accounts.&#x20;

#### <mark style="color:yellow;">**GraphQL API**</mark>

The GraphQL API enables users to build complex queries and retrieve data over a historical period of time e.g. between June 1, 2024 and September 1, 2024.&#x20;

To learn more about the difference between REST and graphQL APIs, read more [here](https://blog.postman.com/graphql-vs-rest/).

### API Status & Monitoring

OpenTrade monitors the APIs' statuses continuosly and provides a status page which customers can access at anytime to check for and track issues, incidents, planned upgrades, and downtime.&#x20;

You can access the status page [here](https://status.opentrade.io).&#x20;

### Authentication

Both APIs require API keys to authenticate, in the sandbox and in production.&#x20;

{% hint style="info" %}
To request an API key, please inquire with your account manager.&#x20;
{% endhint %}

### Full Documentation & Test Environments

For the REST API, we provide a [Swagger collection](https://app.swaggerhub.com/apis-docs/OpenTrade/open-trade_api/4.0) that enables you to review and test the API.&#x20;

For the GraphQL API, we provide a Postman collection that enables you to review the API, manually build queries, and test them.&#x20;

{% hint style="info" %}
To access the graphQL Postman collection, please inquire with your account manager. We require the email addresses of the team members you would like to have access to the Postman collection. They will then receive invitations via email to join our Postman partner workspace.&#x20;
{% endhint %}

### Terminology

OpenTrade implements many of the  ERC-4626 and ERC-20 standards. In some cases, the terminology we use in the product is different from those in the code. They are primarily

| Term in Code | Display Name |
| ------------ | ------------ |
| Pool         | Vault        |
| Shares       | Vault Tokens |
| Assets       | USDC, EURC   |

### Decimals / Formatting

The API returns numerical data types that should be rounded using the following conventions to calculate the display value.&#x20;

For example, stablecoin values in the API should be rounded to 6 decimal places, where *totalOutstandingLoanPrincipal* of 1000000 would be equal to 1 USDC.&#x20;

<table><thead><tr><th width="230">Type</th><th width="108">Decimals</th><th width="232">Example in Code</th><th>Example in Display</th></tr></thead><tbody><tr><td>assets </td><td>6</td><td>1000000</td><td>1 USDC/EURC</td></tr><tr><td>shares</td><td>6</td><td>1000000</td><td>1 Vault Token</td></tr><tr><td>exchangeRate</td><td>18</td><td>1000261149376738066</td><td>1.000261</td></tr><tr><td>interestRate</td><td>2</td><td>500</td><td>5.00%</td></tr></tbody></table>
