# API

{% hint style="info" %}
YFX is currently deployed on Arbitrum One, you can directly call the smart contract to trade, buy YLP, sell YLP.
{% endhint %}

## Contracts for YFX V3

### Arbitrum

* Manager: [0x29bd0372A8A087e4d34d4098259Cd298d554BAc4](https://arbiscan.io/address/0x29bd0372A8A087e4d34d4098259Cd298d554BAc4)
* Router: [0xebb4871d1be1262C8bd1aa7dfc4C047483f02028](https://arbiscan.io/address/0xebb4871d1be1262C8bd1aa7dfc4C047483f02028)
* InviteManager: [0x0A1c07bd77Ff45743af42b579962C2C36e777f01](https://arbiscan.io/address/0x0A1c07bd77Ff45743af42b579962C2C36e777f01)
* Periphery: [0xEae658B32300ff8544bb03d1b8762466a5e99433](https://arbiscan.io/address/0xEae658B32300ff8544bb03d1b8762466a5e99433)
* Vault: [0x48F4B8f77b1E0EFBBF17b2082F12829b87FD1933](https://arbiscan.io/address/0x48F4B8f77b1E0EFBBF17b2082F12829b87FD1933)
* Insurance Fund: [0x4177EA126f6B87A9D83Cb3292548086D1a971303](https://arbiscan.io/address/0x4177EA126f6B87A9D83Cb3292548086D1a971303)
* MarketPriceFeed: [0x7e5151fe2ec125b7C732cb3728046D3025D75a0c](https://arbiscan.io/address/0x7e5151fe2ec125b7C732cb3728046D3025D75a0c)
* **Pools:**
  * USDC1: [0xdC07Ed24738FC2deb3610f9FD337e59e815E7307](https://arbiscan.io/address/0xdC07Ed24738FC2deb3610f9FD337e59e815E7307)
  * USDC2: [0xB63e869a3A777fbe5E606A0192f9c2c3Bb3a49d9](https://arbiscan.io/address/0xB63e869a3A777fbe5E606A0192f9c2c3Bb3a49d9)
  * ETH: [0x396AA1B82F32e84a970805C0972F17dd1C0DEC56](https://arbiscan.io/address/0x396AA1B82F32e84a970805C0972F17dd1C0DEC56)
  * ARB: [0xe089B57dfC9B05F73bdB25B016d45972147dDd05](https://arbiscan.io/address/0xe089B57dfC9B05F73bdB25B016d45972147dDd05)
* **Markets:**
  * BTC\_USD(USDC): [0xe7F0dac16278388FBB1f4aFa409c512333c28F78](https://arbiscan.io/address/0xe7F0dac16278388FBB1f4aFa409c512333c28F78)
  * ETH\_USD(USDC): [0x7f597c44101Ee16fc48Dc7BD37fCAA21A5bFDA91](https://arbiscan.io/address/0x7f597c44101Ee16fc48Dc7BD37fCAA21A5bFDA91)
  * ARB\_USD(USDC): [0x749140688891A97103c15119D2deeebAe8516d6b](https://arbiscan.io/address/0x749140688891A97103c15119D2deeebAe8516d6b)
  * ETH\_USD(ETH): [0x0472686084b7d756E992d32EdA2613aeF99cf9dE](https://arbiscan.io/address/0x0472686084b7d756E992d32EdA2613aeF99cf9dE)
  * ARB\_USD(ARB): [0xC0927411896B350c6318673f0dd75b7e422c8551](https://arbiscan.io/address/0xC0927411896B350c6318673f0dd75b7e422c8551)
* **Tokens:**
  * USDC [0xaf88d065e77c8cC2239327C5EDb3A432268e5831](https://arbiscan.io/address/0xaf88d065e77c8cC2239327C5EDb3A432268e5831)
  * ARB [0x912CE59144191C1204E64559FE8253a0e49E6548](https://arbiscan.io/address/0x912CE59144191C1204E64559FE8253a0e49E6548)
  * WETH [0x82aF49447D8a07e3bd95BD0d56f35241523fBab1](https://arbiscan.io/address/0x82aF49447D8a07e3bd95BD0d56f35241523fBab1)

### Add Liquidity(Buy YLP)

{% hint style="info" %}
To add liquidity to a pool:
{% endhint %}

1. Approve the Router contract for the base token and amount you would like to add for liquidity
2. Call **Router.addLiquidity** with parameters to add USDC pools or other ERC20 pools
   * **\_pool**: pool address
   * **\_amount**: base token amount you would like to spend
   * **isStakeLp**: true if automatically to stake LP for earn (to be online)
   * **\_deadline**: request deadline timestamp
3. Call **Router.addLiquidityETH** with parameters to add ETH pools
   * **\_pool**: pool address
   * **\_amount**: base token amount you would like to spend, should be less than transaction value
   * **isStakeLp**: true if automatically to stake LP for earn (to be online)
   * **\_deadline**: request deadline timestamp for price protection

### Remove Liquidity ( Sell YLP)

{% hint style="info" %}
To remove liquidity from a pool:
{% endhint %}

1. Call **Router.removeLiquidity** with parameters to remove liquidity from USDC pools or other ERC20 pools:
   * **\_pool**: pool address
   * **\_liquidity**: how much liquidity you would like to remove
   * **isUnstake**: should unstake staked LP from earn (to be online)
   * **\_deadline**: request deadline timestamp for price protection
2. Call **Router.removeLiquidityETH** to remove liquidity from ETH pools, parameters are the same as above.

### Open Position

{% hint style="info" %}
To open a position:
{% endhint %}

1. Approve the Router contract for the margin asset token and amount you would like to spend as the initial margin
2. Call **Router.takerOpen** or **takerOpenETH** with parameters:

   ```
   struct TakerOpenParams {
       address _market;        // market contract address
       bytes32 inviterCode;    // inviter code
       uint128 minPrice;       // min price for the slippage
       uint128 maxPrice;       // max price for the slippage
       uint256 margin;         // margin of this order
       uint16 leverage;    	// leverage
       int8 direction;         // order direction, 1: long, -1: short
       int8 triggerDirection;  // trigger flag {1: index price >= trigger price, -1: index price <= trigger price}
       uint256 triggerPrice;	// trigger price
       uint256 deadline;		// request deadline timestamp for price protection
   }
   ```

### Close Position

{% hint style="info" %}
To Close a position:
{% endhint %}

* Call **Router.takerClose** with parameters:

  ```
  struct TakerCloseParams {
      address _market;            // market contract address
      uint256 id;                 // position id
      bytes32 inviterCode;        // inviter code
      uint128 minPrice;           // min price for the slippage
      uint128 maxPrice;           // max price for the slippage
      uint256 amount;             // position amount to close
      int8 triggerDirection;      // trigger flag {1: index price >= trigger price, -1: index price <= trigger price}
      uint256 triggerPrice;		// trigger price
      uint256 deadline;			// request deadline timestamp for price protection
  }
  ```

### Liquidate

{% hint style="warning" %}
Everyone can liquidate other positions that should be liquidated. Liquidation keeper can get 2USDC reward each time.

To run a liquidation keeper, you should:
{% endhint %}

1. Trace positions. You can trace positions by our subgraph or listen contract event.
2. Call **Periphery.getPositionStatus** to check if the position can be liquidated. Return value with `true` means this position can be liquidated.
3. Call **Router.liquidateByCommunity** to execute liquidation.
4. Call **Vault.collectExecutedFee** to get liquidation bonus.

### Get Position Info

To get your position information:

* Call **Market.getPositionId** to get position id
  * **\_taker**: position owner address
  * **\_direction**: 1: long, -1: short
* Call **Market.getPosition** with the position id


---

# 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.yfx.com/yfx-v4/api.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.
