💰
Sudo Gitbook
  • 👋Welcome to Sudo
  • Overview
    • 💡What is Sudo
    • ✨Sudo Features
  • Trade on Sudo
    • 💎Start trading
      • Supported Assets
      • Fees
      • Market Hours
    • 📚Educational Resources
      • What Are Perpetual Futures?
      • Using Leverage Wisely
      • Risk Management Fundamentals
      • What is Sharpe Ratio
      • Real Trading Scenarios
      • Avoiding Rookie Mistakes
  • Liquidity Providers
    • 💰How to provide liquidity
    • 🛰️SLP
    • 🏦SLP Staking
  • S Rewards
    • S Card
      • Getting S Card
      • S Points
      • Using Your S Card
  • Sudo API
    • Sudo API Reference
      • Trader Data
      • Market Info
  • Sudo SDK
    • Introduction to Sudo SDK
    • Core Concepts
    • Installation and Setup
    • Quick Start
    • 📚v0.0.6
      • API Reference
        • SudoAPI
          • Open Position
          • Decrease Position
          • Pledge In Position
          • Redeem From Position
          • Cancel Order
          • getPositionCapInfoList
          • getPositionInfoList
          • getPositionConfig
        • OracleAPI
          • subOraclePrices
      • Changelog
    • Best Practices
    • Troubleshooting
  • Feature Details
    • Algorithm Balanced Funding Rate (ABFR)
    • Risk control
    • FAQ
    • Roadmap
    • On-chain program
Powered by GitBook
On this page
  1. Sudo SDK
  2. v0.0.6
  3. API Reference
  4. SudoAPI

Decrease Position

The decreasePosition function allows users to reduce the size of an existing position.

Function Signature

decreasePosition(
  pcpId: string,
  collateralToken: string,
  indexToken: string,
  amount: bigint,
  long: boolean,
  indexPrice: number,
  collateralPrice: number,
  isTriggerOrder?: boolean,
  isTakeProfitOrder?: boolean,
  isIocOrder?: boolean,
  pricesSlippage?: number,
  collateralSlippage?: number,
  relayerFee?: bigint
): Promise<TransactionBlock>

Parameters

  • pcpId: The ID of the position to decrease

  • collateralToken: The token used as collateral (e.g., "USDC")

  • indexToken: The token used as the market index (e.g., "BTC")

  • amount: The amount to decrease the position by

  • long: Boolean indicating if this is a long (true) or short (false) position

  • indexPrice: The current price of the index token

  • collateralPrice: The current price of the collateral token

  • isTriggerOrder: Boolean indicating if this is a trigger order (default: false)

  • isTakeProfitOrder: Boolean indicating if this is a take profit order (default: true)

  • isIocOrder: Boolean indicating if this is an IOC (Immediate-or-Cancel) order (default: false)

  • pricesSlippage: Maximum allowed slippage for prices (default: 0.003 or 0.3%)

  • collateralSlippage: Maximum allowed slippage for collateral (default: 0.5 or 50%)

  • relayerFee: Fee paid to the relayer (default: 1)

Return Value

Returns a Promise that resolves to a TransactionBlock object.

Usage Example

const tx = await sudoAPI.decreasePosition(
  '0x123...', // pcpId
  'USDC',     // collateralToken
  'BTC',      // indexToken
  BigInt(500000), // amount (0.5 BTC if BTC has 6 decimals)
  true,       // long position
  50000,      // indexPrice (BTC price in USD)
  1,          // collateralPrice (USDC price in USD)
  false,      // not a trigger order
  true,       // is a take profit order
  false,      // not an IOC order
  0.001,      // pricesSlippage (0.1%)
  0.1,        // collateralSlippage (10%)
  BigInt(2)   // relayerFee
);
PreviousOpen PositionNextPledge In Position

Last updated 9 months ago

📚