# API Reference

Secured Finance provides GraphQL APIs via The Graph protocol to query data from our smart contracts. This section documents how to use these APIs to access data from our protocols.

## What You'll Learn

* How to query data from the Fixed-Rate Lending protocol
* Examples of common queries and their responses
* How to use GraphQL to build custom queries
* How to use our interactive API documentation with "Test It" functionality

## Key Components

### Subgraphs

Secured Finance maintains subgraphs for its protocols:

* [Fixed-Rate Lending Subgraph](https://docs.secured.finance/developer-portal/api-reference/fixed-rate-lending-subgraph) - For querying data from the Fixed-Rate Lending protocol

> **Note:** The USDFC Subgraph is currently under development and not yet deployed. USDFC data is only available through the [USDFC SDK](https://docs.secured.finance/developer-portal/sdk-reference/usdfc-sdk).

### Available Networks

Our subgraphs are deployed on the following networks:

| Protocol           | Ethereum | Arbitrum | Filecoin |
| ------------------ | -------- | -------- | -------- |
| Fixed-Rate Lending | ✅        | ✅        | ✅        |

> **Note:** The USDFC Subgraph is currently under development and not yet deployed. USDFC data is only available through the [USDFC SDK](https://docs.secured.finance/developer-portal/sdk-reference/usdfc-sdk) on the Filecoin network.

### Subgraph Endpoints

These are Subgraph endpoint URLs for our production Mainnet and Testnet environments. You can click the URL and try some queries on the GraphQL playground.

#### Fixed-Rate Lending Subgraph

**Ethereum**

* Mainnet: <https://api.studio.thegraph.com/query/64582/sf-prd-mainnet/version/latest>
* Sepolia: <https://api.studio.thegraph.com/query/64582/sf-prd-sepolia/version/latest>

**Arbitrum**

* Mainnet: <https://api.studio.thegraph.com/query/64582/sf-prd-arbitrum-one/version/latest>
* Sepolia: <https://api.studio.thegraph.com/query/64582/sf-prd-arbitrum-sepolia/version/latest>

**Filecoin**

* Mainnet: <https://api.goldsky.com/api/public/project_cm8i6ca9k24d601wy45zzbsrq/subgraphs/sf-filecoin-mainnet/latest/gn>

> **Note:** The Filecoin Calibration testnet endpoints are not provided yet.

## Getting Started

If you're new to GraphQL or The Graph, check out our introduction to subgraphs in the next sections. If you're already familiar with these technologies, you can jump directly to the specific subgraph documentation.

The Graph is a decentralized protocol for indexing and querying blockchain data, making it easier to query the difficult-to-read data stored on the blockchain. The Graph's decentralized approach ensures resilience, eliminating the need for centralized and resource-intensive alternatives.

To view the source of our subgraphs, visit our [GitHub Repository](https://github.com/Secured-Finance/secured-finance-subgraph).

## Interactive API Documentation

We provide interactive API documentation for our Fixed-Rate Lending Subgraph using GitBook's OpenAPI integration. This allows you to explore and test the API directly from the documentation page in real-time.

## Query the Fixed-Rate Lending Subgraph

> Execute a GraphQL query against the Fixed-Rate Lending Subgraph

```json
{"openapi":"3.0.0","info":{"title":"Secured Finance Fixed-Rate Lending API","version":"1.0.0"},"servers":[{"url":"https://api.studio.thegraph.com/query/64582/sf-prd-arbitrum-sepolia/version/latest","description":"Arbitrum Sepolia Testnet"},{"url":"https://api.studio.thegraph.com/query/64582/sf-prd-mainnet/version/latest","description":"Ethereum Mainnet"},{"url":"https://api.studio.thegraph.com/query/64582/sf-prd-arbitrum-one/version/latest","description":"Arbitrum One"},{"url":"https://api.studio.thegraph.com/query/64582/sf-prd-sepolia/version/latest","description":"Ethereum Sepolia"}],"paths":{"/":{"post":{"summary":"Query the Fixed-Rate Lending Subgraph","description":"Execute a GraphQL query against the Fixed-Rate Lending Subgraph","operationId":"querySubgraph","tags":["GraphQL Queries"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["query"],"properties":{"query":{"type":"string","description":"GraphQL query to execute"},"variables":{"type":"object","description":"Variables for the GraphQL query (optional)"}}}}}},"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","description":"The data returned by the query","properties":{"lendingMarkets":{"type":"array","items":{"$ref":"#/components/schemas/LendingMarket"}},"orders":{"type":"array","items":{"$ref":"#/components/schemas/Order"}},"transactions":{"type":"array","items":{"$ref":"#/components/schemas/Transaction"}},"users":{"type":"array","items":{"$ref":"#/components/schemas/User"}},"liquidations":{"type":"array","items":{"$ref":"#/components/schemas/Liquidation"}},"transfers":{"type":"array","items":{"$ref":"#/components/schemas/Transfer"}},"deposits":{"type":"array","items":{"$ref":"#/components/schemas/Deposit"}},"transactionCandleSticks":{"type":"array","items":{"$ref":"#/components/schemas/TransactionCandleStick"}},"takerVolumesByCurrencies":{"type":"array","items":{"$ref":"#/components/schemas/TakerVolumeByCurrency"}}}},"errors":{"type":"array","items":{"type":"object","properties":{"message":{"type":"string"},"locations":{"type":"array","items":{"type":"object","properties":{"line":{"type":"integer"},"column":{"type":"integer"}}}}}},"description":"Any errors that occurred during the query"}}}}}}}}}},"components":{"schemas":{"LendingMarket":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the lending market"},"currency":{"type":"string","format":"bytes","description":"Currency address"},"maturity":{"type":"string","format":"int64","description":"Unix timestamp for the maturity date"},"isActive":{"type":"boolean","description":"Whether the market is active"},"volume":{"type":"string","format":"int64","description":"Total volume of the market"},"openingUnitPrice":{"type":"string","format":"int64","description":"Opening unit price of the market"},"lastLendUnitPrice":{"type":"string","format":"int64","description":"Last unit price for lending"},"lastBorrowUnitPrice":{"type":"string","format":"int64","description":"Last unit price for borrowing"},"offsetAmount":{"type":"string","format":"int64","description":"Offset amount of the market"}}},"Order":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the order"},"orderId":{"type":"string","format":"int64","description":"Order ID in the contract"},"user":{"$ref":"#/components/schemas/User"},"currency":{"type":"string","format":"bytes","description":"Currency address"},"side":{"type":"integer","description":"Order side (0 for LEND, 1 for BORROW)"},"maturity":{"type":"string","format":"int64","description":"Unix timestamp for the maturity date"},"inputUnitPrice":{"type":"string","format":"int64","description":"Input unit price for the order"},"inputAmount":{"type":"string","format":"int64","description":"Input amount for the order"},"filledAmount":{"type":"string","format":"int64","description":"Filled amount of the order"},"status":{"type":"string","enum":["Open","PartiallyFilled","Filled","Killed","Cancelled"],"description":"Order status"},"statusUpdatedAt":{"type":"string","format":"int64","description":"Unix timestamp for status update"},"lendingMarket":{"$ref":"#/components/schemas/LendingMarket"},"isPreOrder":{"type":"boolean","description":"Whether the order is a pre-order"},"type":{"type":"string","enum":["Market","Limit","Unwind"],"description":"Order type"},"isCircuitBreakerTriggered":{"type":"boolean","description":"Whether the circuit breaker was triggered"},"createdAt":{"type":"string","format":"int64","description":"Unix timestamp for order creation"},"blockNumber":{"type":"string","format":"int64","description":"Block number of the order creation"},"txHash":{"type":"string","format":"bytes","description":"Transaction hash of the order creation"}}},"User":{"type":"object","properties":{"id":{"type":"string","description":"Wallet address of the user"},"createdAt":{"type":"string","format":"int64","description":"Unix timestamp for user creation"},"transactionCount":{"type":"string","format":"int64","description":"Number of transactions by the user"},"orderCount":{"type":"string","format":"int64","description":"Number of orders by the user"},"liquidationCount":{"type":"string","format":"int64","description":"Number of liquidations by the user"},"transferCount":{"type":"string","format":"int64","description":"Number of transfers by the user"}}},"Transaction":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the transaction"},"currency":{"type":"string","format":"bytes","description":"Currency address"},"maturity":{"type":"string","format":"int64","description":"Unix timestamp for the maturity date"},"side":{"type":"integer","description":"Transaction side (0 for LEND, 1 for BORROW)"},"executionPrice":{"type":"string","format":"int64","description":"Execution price of the transaction"},"user":{"$ref":"#/components/schemas/User"},"executionType":{"type":"string","enum":["Maker","Taker"],"description":"Execution type"},"futureValue":{"type":"string","format":"int64","description":"Future value of the transaction"},"amount":{"type":"string","format":"int64","description":"Amount of the transaction"},"feeInFV":{"type":"string","format":"int64","description":"Fee in future value"},"averagePrice":{"type":"string","format":"decimal","description":"Average price of the transaction"},"lendingMarket":{"$ref":"#/components/schemas/LendingMarket"},"order":{"$ref":"#/components/schemas/Order"},"createdAt":{"type":"string","format":"int64","description":"Unix timestamp for transaction creation"},"blockNumber":{"type":"string","format":"int64","description":"Block number of the transaction"},"txHash":{"type":"string","format":"bytes","description":"Transaction hash"}}},"Liquidation":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the liquidation"},"collateralCurrency":{"type":"string","format":"bytes","description":"Collateral currency address"},"debtCurrency":{"type":"string","format":"bytes","description":"Debt currency address"},"debtMaturity":{"type":"string","format":"int64","description":"Unix timestamp for the debt maturity"},"debtAmount":{"type":"string","format":"int64","description":"Debt amount"},"user":{"$ref":"#/components/schemas/User"},"timestamp":{"type":"string","format":"int64","description":"Unix timestamp for the liquidation"},"blockNumber":{"type":"string","format":"int64","description":"Block number of the liquidation"},"txHash":{"type":"string","format":"bytes","description":"Transaction hash of the liquidation"}}},"Transfer":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the transfer"},"user":{"$ref":"#/components/schemas/User"},"currency":{"type":"string","format":"bytes","description":"Currency address"},"amount":{"type":"string","format":"int64","description":"Transfer amount"},"transferType":{"type":"string","enum":["Deposit","Withdraw"],"description":"Transfer type"},"timestamp":{"type":"string","format":"int64","description":"Unix timestamp for the transfer"},"blockNumber":{"type":"string","format":"int64","description":"Block number of the transfer"},"txHash":{"type":"string","format":"bytes","description":"Transaction hash of the transfer"}}},"Deposit":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the deposit"},"user":{"$ref":"#/components/schemas/User"},"currency":{"type":"string","format":"bytes","description":"Currency address"},"amount":{"type":"string","format":"int64","description":"Deposit amount"}}},"TransactionCandleStick":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the candle stick"},"interval":{"type":"string","description":"Time interval for the candle stick"},"currency":{"type":"string","format":"bytes","description":"Currency address"},"maturity":{"type":"string","format":"int64","description":"Unix timestamp for the maturity date"},"timestamp":{"type":"string","format":"int64","description":"Unix timestamp for the candle stick"},"open":{"type":"string","format":"int64","description":"Opening price"},"close":{"type":"string","format":"int64","description":"Closing price"},"high":{"type":"string","format":"int64","description":"Highest price"},"low":{"type":"string","format":"int64","description":"Lowest price"},"average":{"type":"string","format":"decimal","description":"Average price"},"volume":{"type":"string","format":"int64","description":"Trading volume"},"volumeInFV":{"type":"string","format":"int64","description":"Trading volume in future value"}}},"TakerVolumeByCurrency":{"type":"object","properties":{"id":{"type":"string","description":"Unique identifier for the taker volume"},"user":{"$ref":"#/components/schemas/User"},"currency":{"type":"string","format":"bytes","description":"Currency address"},"totalVolume":{"type":"string","format":"int64","description":"Total volume for the user and currency"}}}}}}
```

The interactive documentation above allows you to:

1. Explore available endpoints and operations
2. View request and response schemas
3. Try out API calls directly from the documentation using the "Test It" feature
4. See example queries and responses

### Using the Interactive Documentation

1. Browse through the available operations
2. Click on an operation to expand it
3. View the request parameters and example values
4. Click "Test It" to execute a request against the selected server
5. View the response directly in the documentation

For more complex queries, you can also use The Graph's Playground interface by visiting the subgraph endpoints directly.

## Related Resources

* [The Graph Documentation](https://thegraph.com/docs/en/)
* [GraphQL Documentation](https://graphql.org/learn/)
* [Secured Finance GitHub Repositories](https://github.com/Secured-Finance)
