💻API

This document primarily contains guidelines and technical documentation for MYX smart contracts. You can utilize these documents to understand the MYX protocol smart contracts and develop on-chain integrations.

General API Information

Apis

  • List of Trading Pairs

GET /v2/quote/market/contracts

Retrieve all contract trading pairs

Parameters: None

Response:

{
  "code": 0,
  "msg": "Success",
  "data": [
    {
      "contract_index": 1,
      "ticker_id": "BTC-USDC", //Identifier of a ticker with delimiter to separate base/target, eg. BTC-PERP
      "base_currency": "BTC", //Symbol/currency code of base pair, eg. BTC
      "target_currency": "USDC", //Symbol/currency code of target pair, eg. ETH
      "last_price": 61681.74480976, //Last transacted price of base currency based on given target currency
      "base_volume": 1758.7498, //24 hour trading volume in base pair volume
      "target_volume": 108836479.78206, //24 hour trading volume in target pair volume
      "high": 62748.59803949, //Rolling 24-hours highest transaction price
      "low": 61133.51105089, //Rolling 24-hours lowest transaction price
      "product_type": "Perpetual", //What product is this? Futures, Perpetual, Options?
      "open_interest": 3.827820648391355e+51, //The open interest in the last 24 hours in contracts
      "index_price": 61681.74480976, //Underlying index price
      "index_name": "BTC", //Name of the underlying index if any
      "index_currency": "USDC", //Underlying currency for index
      "funding_rate": 0.00003708, //Current funding rate
      "next_funding_rate": 0.00002753, //Upcoming predicted funding rate
      "next_funding_rate_timestamp": 1715738400000 //Timestamp of the next funding rate change
    }
  ]
}
  • Description of Trading Pairs

Retrieve all contract trading pair descriptions

Parameters:

Name
Type
Mandatory
Description

ticker_id

STRING

Y

ARB-USDC、BTC-USDC、ETH-USD

Response:

Liquidity Management:

Users can manage liquidity by interacting with the Pool contract, enabling liquidity management through the Pool.

Add Liquidity

  • When adding liquidity, the indexToken and stableToken need to be approved to the Router contract. The contract will then transfer the corresponding LP token quantity to the user based on their input.

  • The user adding liquidity is the process of the user purchasing MLP. The contract will allocate the corresponding MLP of the trading pair to the user based on the current balance of the pool and the set fee. MLP is an ERC20 token.

Adding liquidity for others:

  • A parameter called "receiver" is defined. After adding liquidity, the acquired MLP can be sent directly to the receiver.

Add liquidity, using ETH:

Removing Liquidity

  • Removing liquidity is the process of users redeeming tokens. According to the pool's desired weight, more of the undisired tokens will be paid to users.

  • When a portion of tokens in the liquidity pool is locked, which results in an insufficient quantity of tokens, the redeeming operation will pay more of the available tokens. In case that the assets available for this operation are insufficient due to the reserve of assets, the transaction fails.

Removing Liquidity and Specifying Another Receiver

  • A additional parameter called "receiver" is defined. After removing liquidity, the corresponding tokens will be sent to the receiver's address.

Multicall Contract

Router inherits from the Multicall contract. Its main function is to allow calling multiple methods of a contract in a single transaction.

Support for ETH

  • ETH support is implemented through Multicall. When adding liquidity, first call wrapETH, transfer the corresponding ETH to receive the corresponding WETH. addLiquidity is called simultaneously.

Position Management

Users can place orders through the Router, and the orders will be stored in the OrderManager contract. The Keeper will monitor placed orders and execute those that meet the conditions.

Retrieve Trading Pair Index

  • Retrieve the pairIndex using indexToken and stableToken. The pairIndex will be required for subsequent contract parameters.

Opening Positions or Managing Existing Positions

Open a position and set take-profit and stop-loss

Decreasing or Closing a Position

Creating Multiple Decrease Orders

  • The parameter is an array of DecreasePositionRequest.

Limit Orders

  • For limit orders, set the TradeType to LIMIT and specify the price. You can set limit orders for opening, adding, or reducing positions.

Cancel Order

Order Execution

  • The keeper will monitor all orders and execute them when conditions are met. The keeper-related contract mechanism will be introduced in the keeper document.

Get Positions Info

The user's address, trading pair index, and whether the user is going long or short serve as keys to the user's position.

Get information on the user's position

The Router provides an option to cancel all orders in its position.

Transaction Fee

A transaction fee will be charged when trade is executed.

  • When there are more long open interest than short, and a user goes long: a taker fee is charged. When there are more long open interest than short, and a user goes short: a maker fee is charged. When there are more short open interest than long, and a user goes short: a taker fee is charged. When there are more short open interest than long, and a user goes long: a maker fee is charged.

VIP and Commissions

The protocol supports VIP and commissions. For details on these two, please refer to the relevant VIP document.

To claim VIP return fees and commissions, you can directly call the claimUserTradingFee method in the FeeCollector contract.

Last updated