# APIs for Funding ARB Analytics

### Endpoints

### 1. Logging In (\*\*\*Required First Step \*\*\*)

* Endpoint: /login&#x20;
* Method: POST&#x20;
* Description: login and retrieve JWT token

a. Request

* Headers: Content-Type: application/json&#x20;
* Query Parameters: None
* Body:
  * username (string): The username of the user.
  * password (string): The password of the user.

b. Responce

* Status Code: 200 OK
* Body:

```
{ "access_token": "<access_token>", "refresh_token": "<refresh_token>" }
```

c. Example

```
fetch('https://max1-funding-arb.uc.r.appspot.com/login', {
   method: 'POST',
   headers: {
       'Content-Type': 'application/json'
   },
   body: JSON.stringify({
       username: 'username',
       password: 'password'
   })
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

### 2. Get Raw Data Table (requires JWT token)

* Endpoint: /raw\_data\_table
* Method: GET
* Description: Retrieves all records from the raw\_data\_table.

a. Request

* Headers: None
* Query Parameters: None
* Body: None

b. Response

* Status Code: 200 OK
* **Body:** JSON array of objects containing the raw data records.

c. Example

```
fetch('https://max1-funding-arb.uc.r.appspot.com/raw_data_table', {
   method: 'GET',
   headers: {
       'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE'
   }
})
.then(response => {
   if (!response.ok) {
       throw new Error('Network response was not ok');
   }
   return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

d. Response Example

```
[
{"funding_id":1,"fundingrate":"-0.00021167","fundingtime":1713456000000,"markprice":"63515.40000000","symbol":"BTCUSD_PERP","time":"Thu, 27 Jun 2024 08:03:24 GMT"},
{"funding_id":2,"fundingrate":"-0.00029339","fundingtime":1713484800000,"markprice":"63477.88531564","symbol":"BTCUSD_PERP","time":"Thu, 27 Jun 2024 08:03:24 GMT"},
  …
]
```

### 3.1  Get Portfolio Track Records (requires JWT token)

* Endpoint: /portfolio\_track\_records
* Method: GET
* Description: Retrieves all records from the portfolio\_track\_records table.

a. Request

* Headers: None
* Query Parameters:
* &#x20; \- page (optional): The page number to retrieve. Defaults to all records if not provided.
* &#x20; \- limit (optional): The number of records per page. Defaults to all records if not provided.
* Body: None

b. Response

* Status Code: 200 OK
* Body: JSON array of objects containing the portfolio track records.

c. Example

```
fetch('https://max1-funding-arb.uc.r.appspot.com/portfolio_track_records?page=1&limit=60, {
   method: 'GET',
   headers: {
       'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE'
   }
})
.then(response => {
   if (!response.ok) {
       throw new Error('Network response was not ok');
   }
   return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

```

d. Response Example

```
{[ 
{"id":1,"money_at_risk_percent":"-0.7635539234855009","net_exposure_value":"-0.7577440087800085","portfolio_implied_30days_earnings":"0.8605773848134116","portfolio_implied_apr":"0.10406109150689863","timestamp":"Fri, 28 Jun 2024 04:20:33 GMT","total_assets_value":"99.23909569098001"},

{"id":2,"money_at_risk_percent":"-0.7301864268488106","net_exposure_value":"-0.7248933446900026","portfolio_implied_30days_earnings":"0.8606027411036695","portfolio_implied_apr":"0.10402641079258573","timestamp":"Fri, 28 Jun 2024 07:05:01 GMT","total_assets_value":"99.27510537526001"},
…..
],
"total_records": 120, 
"page": 1, 
"limit": 60
}
```

### 3.2 Get Latest Portfolio Data food a time range (requires JWT token)

* Endpoint: /track\_records\_daily\_latest
* Method: GET
* Description: retrieves the latest records for each day up to 1:00 UTC within a specified date range. If no date range is provided, it fetches the latest records up to 1:00 UTC for all available days.

a. Request

* Headers: None
* Query Parameters:&#x20;
* &#x20; \- start\_date (optional, string, format: YYYY-MM-DD
* &#x20; \- The start date of the range from which to fetch records.
* &#x20; \- Example: 2024-08-03
* &#x20; \- end\_date (optional, string, format: YYYY-MM-DD)
* &#x20; \- The end date of the range up to which to fetch records.
* &#x20; \- Example: 2024-09-02
* Body: None

b. Response

* Status Code: 200 OK
* Body: JSON array of objects containing the track of records data.

c. Example

```
fetch('https://max1-funding-arb.uc.r.appspot.com/track_records_daily_latest?start_date=2024-08-03&end_date=2024-09-02', {
   method: 'GET',
   headers: {
       'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE'
   }
})
.then(response => {
   if (!response.ok) {
       throw new Error('Network response was not ok');
   }
   return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
// Some code
```

### 4. Get Portfolio Latest Data (requires JWT token)

* Endpoint: /portfolio\_latest
* Method: GET
* Description: Retrieves all records from the portfolio\_latest table.

a. Request

* Headers: None
* Query Parameters: None
* Body: None

b. Response

* Status Code: 200 OK
* Body: JSON array of objects containing the latest portfolio data.

c. Example

```
fetch('https://max1-funding-arb.uc.r.appspot.com/portfolio_latest', {
   method: 'GET',
   headers: {
       'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE'
   }
})
.then(response => {
   if (!response.ok) {
       throw new Error('Network response was not ok');
   }
   return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

d. Response Example

```
[ 
{"amount":"6.8792","assets_types":"Crypto","assets_value":"62.2633","implied_apr":"0.0","mark_price":"9.051","order_value_required":"0.0","portfolio_allocation":"0.6271","product_category":"Coin-M Futures","symbol":"UNI","target_allocation_percent":"0.0","utc_timestamp":"Tue, 02 Jul 2024 08:20:19 GMT"},
{"amount":"0.2512","assets_types":"Crypto","assets_value":"37.0242","implied_apr":"0.0","mark_price":"147.389","order_value_required":"0.0","portfolio_allocation":"0.3729","product_category":"Coin-M Futures","symbol":"SOL","target_allocation_percent":"0.0","utc_timestamp":"Tue, 02 Jul 2024 08:20:19 GMT"},

  …
]
```

### 5. Get Monitor APR Attribute Data (requires JWT token)

* Endpoint: /monitor\_apr\_attribute
* Method: GET
* Description: Retrieves all records from the monitor\_apr\_attribute table.

a. Request

* Headers: None
* Query Parameters: None
* Body: None

b. Response

* Status Code: 200 OK
* Body: JSON array of objects containing the monitor APR attribute data.

c. Example

```
fetch('https://max1-funding-arb.uc.r.appspot.com/monitor_apr_attribute', {
   method: 'GET',
   headers: {
       'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE'
   }
})
.then(response => {
   if (!response.ok) {
       throw new Error('Network response was not ok');
   }
   return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

d. Response Example

```
[
 {"30_day_cum_funding":"0.09370907999999999","3_day_cum_funding":"0.1376676","7_day_cum_funding":"0.07607777142857143","allocation_percentage":"0.4","apr_id":1,"apr_score":"0.1449632622857143","next_funding_rate":"0.2306664","previous_funding_rate":"0.14273280000000002","simulator_id":null,"symbol":"BNBUSD_PERP","time":"Thu, 27 Jun 2024 08:00:00 GMT"},

{"30_day_cum_funding":"0.12468504000000001","3_day_cum_funding":"0.13084440000000003","7_day_cum_funding":"0.09699222857142857","allocation_percentage":"0.35","apr_id":2,"apr_score":"0.11432026971428573","next_funding_rate":"0.10800000000000001","previous_funding_rate":"0.10800000000000001","simulator_id":null,"symbol":"RUNEUSD_PERP","time":"Thu, 27 Jun 2024 08:00:00 GMT"},
…..
]

```

### 6. Refresh Token

1. Endpoint: /refresh
2. Method: POST
3. Description: This endpoint allows a user to refresh their access token using a valid refresh token.

a. Request

* Headers&#x20;
  * Authorization: Bearer \<refresh\_token>
  * Content-Type: application/json
* Body: None

b. Response

* Status Code: 200 OK
* Body: {"access\_token": "\<new\_access\_token>"}

### 7. Trigger Cloud Function DataSync

1. Endpoint: /run\_dataSync
2. Method: GET
3. Description: Triggers the dataSync function to fetch data and store into database&#x20;

a. Request

* Headers: None
* Query Parameters: None
* Body: None

b. Response

* Status Code: 200 OK
* Body: None

### 8. Trigger Cloud Run Monitor

1. Endpoint: /run\_monitor
2. Method: GET
3. Description: Triggers the monitor instance to fetch data and store into database

a. Request

* Headers: None
* Query Parameters: None
* Body: None

b. Response

* Status Code: 200 OK
* Body: None

### 9. Trigger Cloud Run Portfolio

1. Endpoint: /run\_portfolio
2. Method: GET
3. Description: Triggers the portfolio instance to fetch data and store into database

a. Request

* Headers: None
* Query Parameters: None
* Body: None

b. Response

* Status Code: 200 OK
* Body: None


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kira.trading/api-end-points/apis-for-funding-arb-analytics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
