orderly-positions-tpsl

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Orderly Network: Positions & TP/SL

Orderly Network:仓位与止盈/止损(TP/SL)

This skill covers position management, PnL tracking, leverage settings, and configuring Take-Profit (TP) and Stop-Loss (SL) orders for risk management.
本技能涵盖仓位管理、盈亏(PnL)追踪、杠杆设置,以及配置止盈(TP)和止损(SL)订单以进行风险管理。

When to Use

使用场景

  • Building a position management interface
  • Implementing risk management with TP/SL
  • Tracking unrealized PnL
  • Adjusting leverage settings
  • 构建仓位管理界面
  • 实现带止盈/止损的风险管理
  • 追踪未实现盈亏
  • 调整杠杆设置

Prerequisites

前置条件

  • Open positions on Orderly
  • Understanding of perpetual futures
  • API key with
    read
    and
    trading
    scopes
  • 在Orderly Network上持有开放仓位
  • 了解永续合约概念
  • 拥有包含
    read
    trading
    权限的API密钥

Position Data Structure

仓位数据结构

typescript
interface Position {
  symbol: string; // e.g., "PERP_ETH_USDC"
  position_qty: number; // Positive = long, Negative = short
  average_open_price: number; // Entry price
  mark_price: number; // Current mark price
  unrealized_pnl: number; // Unrealized profit/loss
  unrealized_pnl_roi: number; // ROI percentage
  mmr: number; // Maintenance margin ratio
  imr: number; // Initial margin ratio
  notional: number; // Position value
  leverage: number; // Current leverage
  est_liq_price: number; // Estimated liquidation price
  cost_position: number; // Position cost
  settle_price: number; // Settlement price
  unsettled_pnl: number; // Unsettled PnL
}
typescript
interface Position {
  symbol: string; // e.g., "PERP_ETH_USDC"
  position_qty: number; // Positive = long, Negative = short
  average_open_price: number; // Entry price
  mark_price: number; // Current mark price
  unrealized_pnl: number; // Unrealized profit/loss
  unrealized_pnl_roi: number; // ROI percentage
  mmr: number; // Maintenance margin ratio
  imr: number; // Initial margin ratio
  notional: number; // Position value
  leverage: number; // Current leverage
  est_liq_price: number; // Estimated liquidation price
  cost_position: number; // Position cost
  settle_price: number; // Settlement price
  unsettled_pnl: number; // Unsettled PnL
}

Get Positions (REST API)

获取仓位(REST API)

typescript
// Get all positions
GET /v1/positions

// Get position for specific symbol
GET /v1/position/{symbol}

// Example response
{
  "success": true,
  "data": {
    "rows": [
      {
        "symbol": "PERP_ETH_USDC",
        "position_qty": 0.5,
        "average_open_price": 3000,
        "mark_price": 3100,
        "unrealized_pnl": 50,
        "unrealized_pnl_roi": 0.0333,
        "mmr": 0.01,
        "imr": 0.02,
        "notional": 1550,
        "leverage": 10,
        "est_liq_price": 2700
      }
    ]
  }
}
typescript
// Get all positions
GET /v1/positions

// Get position for specific symbol
GET /v1/position/{symbol}

// Example response
{
  "success": true,
  "data": {
    "rows": [
      {
        "symbol": "PERP_ETH_USDC",
        "position_qty": 0.5,
        "average_open_price": 3000,
        "mark_price": 3100,
        "unrealized_pnl": 50,
        "unrealized_pnl_roi": 0.0333,
        "mmr": 0.01,
        "imr": 0.02,
        "notional": 1550,
        "leverage": 10,
        "est_liq_price": 2700
      }
    ]
  }
}

React SDK: usePositionStream

React SDK:usePositionStream

Stream positions in real-time with automatic PnL updates:
typescript
import { usePositionStream } from '@orderly.network/hooks';

function PositionsTable() {
  const {
    rows,
    aggregated,
    totalUnrealizedROI,
    isLoading
  } = usePositionStream();

  if (isLoading) return <div>Loading positions...</div>;

  return (
    <div>
      <div className="summary">
        <h3>Total Unrealized PnL: {aggregated?.totalUnrealizedPnl?.toFixed(2)} USDC</h3>
        <p>ROI: {(totalUnrealizedROI * 100).toFixed(2)}%</p>
      </div>

      <table>
        <thead>
          <tr>
            <th>Symbol</th>
            <th>Size</th>
            <th>Entry Price</th>
            <th>Mark Price</th>
            <th>Unrealized PnL</th>
            <th>Leverage</th>
            <th>Liq. Price</th>
          </tr>
        </thead>
        <tbody>
          {rows.map((position) => (
            <tr key={position.symbol}>
              <td>{position.symbol}</td>
              <td className={position.position_qty > 0 ? 'long' : 'short'}>
                {position.position_qty > 0 ? '+' : ''}{position.position_qty}
              </td>
              <td>{position.average_open_price.toFixed(2)}</td>
              <td>{position.mark_price.toFixed(2)}</td>
              <td className={position.unrealized_pnl >= 0 ? 'profit' : 'loss'}>
                {position.unrealized_pnl.toFixed(2)} USDC
              </td>
              <td>{position.leverage}x</td>
              <td>{position.liq_price.toFixed(2)}</td>
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
}
通过自动更新盈亏的方式实时流式获取仓位数据:
typescript
import { usePositionStream } from '@orderly.network/hooks';

function PositionsTable() {
  const {
    rows,
    aggregated,
    totalUnrealizedROI,
    isLoading
  } = usePositionStream();

  if (isLoading) return <div>Loading positions...</div>;

  return (
    <div>
      <div className="summary">
        <h3>Total Unrealized PnL: {aggregated?.totalUnrealizedPnl?.toFixed(2)} USDC</h3>
        <p>ROI: {(totalUnrealizedROI * 100).toFixed(2)}%</p>
      </div>

      <table>
        <thead>
          <tr>
            <th>Symbol</th>
            <th>Size</th>
            <th>Entry Price</th>
            <th>Mark Price</th>
            <th>Unrealized PnL</th>
            <th>Leverage</th>
            <th>Liq. Price</th>
          </tr>
        </thead>
        <tbody>
          {rows.map((position) => (
            <tr key={position.symbol}>
              <td>{position.symbol}</td>
              <td className={position.position_qty > 0 ? 'long' : 'short'}>
                {position.position_qty > 0 ? '+' : ''}{position.position_qty}
              </td>
              <td>{position.average_open_price.toFixed(2)}</td>
              <td>{position.mark_price.toFixed(2)}</td>
              <td className={position.unrealized_pnl >= 0 ? 'profit' : 'loss'}>
                {position.unrealized_pnl.toFixed(2)} USDC
              </td>
              <td>{position.leverage}x</td>
              <td>{position.liq_price.toFixed(2)}</td>
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
}

Close Position

平仓

Partial Close

部分平仓

typescript
import { usePositionClose } from '@orderly.network/hooks';

function ClosePositionButton({ symbol, positionQty }: { symbol: string; positionQty: number }) {
  const { closePosition, isClosing } = usePositionClose();

  const handleClose = async (percentage: number) => {
    const quantity = Math.abs(positionQty) * (percentage / 100);
    await closePosition({
      symbol,
      qty: quantity,
      side: positionQty > 0 ? 'SELL' : 'BUY',
    });
  };

  return (
    <div>
      <button onClick={() => handleClose(25)} disabled={isClosing}>Close 25%</button>
      <button onClick={() => handleClose(50)} disabled={isClosing}>Close 50%</button>
      <button onClick={() => handleClose(100)} disabled={isClosing}>Close 100%</button>
    </div>
  );
}
typescript
import { usePositionClose } from '@orderly.network/hooks';

function ClosePositionButton({ symbol, positionQty }: { symbol: string; positionQty: number }) {
  const { closePosition, isClosing } = usePositionClose();

  const handleClose = async (percentage: number) => {
    const quantity = Math.abs(positionQty) * (percentage / 100);
    await closePosition({
      symbol,
      qty: quantity,
      side: positionQty > 0 ? 'SELL' : 'BUY',
    });
  };

  return (
    <div>
      <button onClick={() => handleClose(25)} disabled={isClosing}>Close 25%</button>
      <button onClick={() => handleClose(50)} disabled={isClosing}>Close 50%</button>
      <button onClick={() => handleClose(100)} disabled={isClosing}>Close 100%</button>
    </div>
  );
}

Market Close (REST API)

市价平仓(REST API)

typescript
// Close entire position at market price
POST /v1/order
Body: {
  symbol: 'PERP_ETH_USDC',
  side: positionQty > 0 ? 'SELL' : 'BUY',
  order_type: 'MARKET',
  order_quantity: Math.abs(positionQty).toString(),
  reduce_only: true,
}
typescript
// Close entire position at market price
POST /v1/order
Body: {
  symbol: 'PERP_ETH_USDC',
  side: positionQty > 0 ? 'SELL' : 'BUY',
  order_type: 'MARKET',
  order_quantity: Math.abs(positionQty).toString(),
  reduce_only: true,
}

Leverage Management

杠杆管理

Get Current Leverage

获取当前杠杆

typescript
GET /v1/client/leverage?symbol={symbol}

// Response
{
  "success": true,
  "data": {
    "leverage": 10,
    "max_leverage": 25
  }
}
typescript
GET /v1/client/leverage?symbol={symbol}

// Response
{
  "success": true,
  "data": {
    "leverage": 10,
    "max_leverage": 25
  }
}

Set Leverage

设置杠杆

typescript
POST /v1/client/leverage
Body: {
  symbol: 'PERP_ETH_USDC',
  leverage: 15,  // New leverage value
}

// React SDK
import { useLeverage } from '@orderly.network/hooks';

function LeverageSlider({ symbol }: { symbol: string }) {
  const { leverage, maxLeverage, setLeverage, isLoading } = useLeverage(symbol);

  const handleChange = async (newLeverage: number) => {
    try {
      await setLeverage(newLeverage);
    } catch (error) {
      console.error('Failed to set leverage:', error);
    }
  };

  return (
    <div>
      <label>Leverage: {leverage}x</label>
      <input
        type="range"
        min="1"
        max={maxLeverage}
        value={leverage}
        onChange={(e) => handleChange(parseInt(e.target.value))}
        disabled={isLoading}
      />
    </div>
  );
}
typescript
POST /v1/client/leverage
Body: {
  symbol: 'PERP_ETH_USDC',
  leverage: 15,  // New leverage value
}

// React SDK
import { useLeverage } from '@orderly.network/hooks';

function LeverageSlider({ symbol }: { symbol: string }) {
  const { leverage, maxLeverage, setLeverage, isLoading } = useLeverage(symbol);

  const handleChange = async (newLeverage: number) => {
    try {
      await setLeverage(newLeverage);
    } catch (error) {
      console.error('Failed to set leverage:', error);
    }
  };

  return (
    <div>
      <label>Leverage: {leverage}x</label>
      <input
        type="range"
        min="1"
        max={maxLeverage}
        value={leverage}
        onChange={(e) => handleChange(parseInt(e.target.value))}
        disabled={isLoading}
      />
    </div>
  );
}

Take-Profit / Stop-Loss Orders

止盈/止损订单

TP/SL Order Types

止盈/止损订单类型

TypeDescription
TAKE_PROFIT
Trigger when price reaches target (profit)
STOP_LOSS
Trigger when price drops below threshold
TRAILING_STOP
Dynamic stop that follows price
类型描述
TAKE_PROFIT
当价格达到目标价位时触发(获利)
STOP_LOSS
当价格跌破阈值时触发
TRAILING_STOP
随价格动态调整的止损订单

Using useTPSLOrder Hook

使用useTPSLOrder钩子

typescript
import { useTPSLOrder } from '@orderly.network/hooks';

function TPSSettings({ position }: { position: Position }) {
  const [computed, { setValue, submit, validate, reset }] = useTPSLOrder(position);

  const handleSubmit = async () => {
    try {
      await validate();
      await submit();
      console.log('TP/SL order placed');
    } catch (error) {
      console.error('TP/SL failed:', error);
    }
  };

  return (
    <div className="tpsl-form">
      <h4>Take Profit</h4>
      <div>
        <label>Trigger Price</label>
        <input
          type="number"
          placeholder="TP Price"
          onChange={(e) => setValue('tp_trigger_price', e.target.value)}
        />
      </div>
      <div>
        <label>Or Offset %</label>
        <input
          type="number"
          placeholder="e.g., 5 for 5%"
          onChange={(e) => setValue('tp_offset_percentage', parseFloat(e.target.value))}
        />
      </div>

      <h4>Stop Loss</h4>
      <div>
        <label>Trigger Price</label>
        <input
          type="number"
          placeholder="SL Price"
          onChange={(e) => setValue('sl_trigger_price', e.target.value)}
        />
      </div>
      <div>
        <label>Or Offset %</label>
        <input
          type="number"
          placeholder="e.g., -5 for -5%"
          onChange={(e) => setValue('sl_offset_percentage', parseFloat(e.target.value))}
        />
      </div>

      <button onClick={handleSubmit}>Set TP/SL</button>
    </div>
  );
}
typescript
import { useTPSLOrder } from '@orderly.network/hooks';

function TPSSettings({ position }: { position: Position }) {
  const [computed, { setValue, submit, validate, reset }] = useTPSLOrder(position);

  const handleSubmit = async () => {
    try {
      await validate();
      await submit();
      console.log('TP/SL order placed');
    } catch (error) {
      console.error('TP/SL failed:', error);
    }
  };

  return (
    <div className="tpsl-form">
      <h4>Take Profit</h4>
      <div>
        <label>Trigger Price</label>
        <input
          type="number"
          placeholder="TP Price"
          onChange={(e) => setValue('tp_trigger_price', e.target.value)}
        />
      </div>
      <div>
        <label>Or Offset %</label>
        <input
          type="number"
          placeholder="e.g., 5 for 5%"
          onChange={(e) => setValue('tp_offset_percentage', parseFloat(e.target.value))}
        />
      </div>

      <h4>Stop Loss</h4>
      <div>
        <label>Trigger Price</label>
        <input
          type="number"
          placeholder="SL Price"
          onChange={(e) => setValue('sl_trigger_price', e.target.value)}
        />
      </div>
      <div>
        <label>Or Offset %</label>
        <input
          type="number"
          placeholder="e.g., -5 for -5%"
          onChange={(e) => setValue('sl_offset_percentage', parseFloat(e.target.value))}
        />
      </div>

      <button onClick={handleSubmit}>Set TP/SL</button>
    </div>
  );
}

REST API: Algo Orders for TP/SL

REST API:用于止盈/止损的算法订单

typescript
// Place TP/SL order (creates both TP and SL as child orders)
POST /v1/algo/order
Body: {
  symbol: 'PERP_ETH_USDC',
  algo_type: 'TP_SL',
  quantity: 5.5,
  trigger_price_type: 'MARK_PRICE',
  child_orders: [
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'TAKE_PROFIT',
      side: 'SELL',
      type: 'MARKET',
      trigger_price: 3500,
      reduce_only: true
    },
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'STOP_LOSS',
      side: 'SELL',
      type: 'MARKET',
      trigger_price: 2800,
      reduce_only: true
    }
  ]
}

// Positional TP/SL (attached to entire position)
POST /v1/algo/order
Body: {
  symbol: 'PERP_ETH_USDC',
  algo_type: 'POSITIONAL_TP_SL',
  trigger_price_type: 'MARK_PRICE',
  child_orders: [
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'TAKE_PROFIT',
      side: 'SELL',
      type: 'CLOSE_POSITION',
      trigger_price: 3500,
      reduce_only: true
    },
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'STOP_LOSS',
      side: 'SELL',
      type: 'CLOSE_POSITION',
      trigger_price: 2800,
      reduce_only: true
    }
  ]
}
typescript
// Place TP/SL order (creates both TP and SL as child orders)
POST /v1/algo/order
Body: {
  symbol: 'PERP_ETH_USDC',
  algo_type: 'TP_SL',
  quantity: 5.5,
  trigger_price_type: 'MARK_PRICE',
  child_orders: [
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'TAKE_PROFIT',
      side: 'SELL',
      type: 'MARKET',
      trigger_price: 3500,
      reduce_only: true
    },
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'STOP_LOSS',
      side: 'SELL',
      type: 'MARKET',
      trigger_price: 2800,
      reduce_only: true
    }
  ]
}

// Positional TP/SL (attached to entire position)
POST /v1/algo/order
Body: {
  symbol: 'PERP_ETH_USDC',
  algo_type: 'POSITIONAL_TP_SL',
  trigger_price_type: 'MARK_PRICE',
  child_orders: [
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'TAKE_PROFIT',
      side: 'SELL',
      type: 'CLOSE_POSITION',
      trigger_price: 3500,
      reduce_only: true
    },
    {
      symbol: 'PERP_ETH_USDC',
      algo_type: 'STOP_LOSS',
      side: 'SELL',
      type: 'CLOSE_POSITION',
      trigger_price: 2800,
      reduce_only: true
    }
  ]
}

STOP Orders (Stop Market)

STOP订单(止损市价单)

typescript
POST /v1/algo/order
Body: {
  symbol: 'PERP_ETH_USDC',
  algo_type: 'STOP',
  quantity: 5.5,
  side: 'BUY',
  type: 'LIMIT',
  trigger_price_type: 'MARK_PRICE',
  trigger_price: 4.203,
  price: 3.5  // Limit price for the triggered order
}
typescript
POST /v1/algo/order
Body: {
  symbol: 'PERP_ETH_USDC',
  algo_type: 'STOP',
  quantity: 5.5,
  side: 'BUY',
  type: 'LIMIT',
  trigger_price_type: 'MARK_PRICE',
  trigger_price: 4.203,
  price: 3.5  // Limit price for the triggered order
}

Cancel TP/SL Orders

取消止盈/止损订单

typescript
// Cancel single algo order
DELETE /v1/algo/order?order_id={order_id}&symbol={symbol}

// Cancel all algo orders for symbol
DELETE /v1/algo/orders?symbol={symbol}

// React SDK
const [algoOrders, { cancelAlgoOrder }] = useAlgoOrderStream();
await cancelAlgoOrder(orderId);
typescript
// Cancel single algo order
DELETE /v1/algo/order?order_id={order_id}&symbol={symbol}

// Cancel all algo orders for symbol
DELETE /v1/algo/orders?symbol={symbol}

// React SDK
const [algoOrders, { cancelAlgoOrder }] = useAlgoOrderStream();
await cancelAlgoOrder(orderId);

Position History

仓位历史

typescript
GET /v1/position_history?symbol={symbol}&start={timestamp}&end={timestamp}

// Response includes closed positions with realized PnL
typescript
GET /v1/position_history?symbol={symbol}&start={timestamp}&end={timestamp}

// Response includes closed positions with realized PnL

PnL Calculations

盈亏计算

Unrealized PnL

未实现盈亏

typescript
// For LONG positions
unrealizedPnL = (markPrice - averageOpenPrice) * positionQty;

// For SHORT positions
unrealizedPnL = (averageOpenPrice - markPrice) * Math.abs(positionQty);
typescript
// 多头仓位
unrealizedPnL = (markPrice - averageOpenPrice) * positionQty;

// 空头仓位
unrealizedPnL = (averageOpenPrice - markPrice) * Math.abs(positionQty);

ROI

投资回报率(ROI)

typescript
// Return on Investment
roi = unrealizedPnL / ((averageOpenPrice * Math.abs(positionQty)) / leverage);
typescript
// Return on Investment
roi = unrealizedPnL / ((averageOpenPrice * Math.abs(positionQty)) / leverage);

Liquidation Price

强平价格

typescript
// For LONG positions
liqPrice = averageOpenPrice * (1 - mmr - 1 / leverage);

// For SHORT positions
liqPrice = averageOpenPrice * (1 + mmr + 1 / leverage);
typescript
// 多头仓位
liqPrice = averageOpenPrice * (1 - mmr - 1 / leverage);

// 空头仓位
liqPrice = averageOpenPrice * (1 + mmr + 1 / leverage);

Risk Metrics

风险指标

typescript
// Available fields from GET /v1/positions response:
{
  "current_margin_ratio_with_orders": 1.2385,
  "free_collateral": 450315.09,
  "initial_margin_ratio": 0.1,
  "initial_margin_ratio_with_orders": 0.1,
  "maintenance_margin_ratio": 0.05,
  "maintenance_margin_ratio_with_orders": 0.05,
  "margin_ratio": 1.2385,
  "open_margin_ratio": 1.2102,
  "total_collateral_value": 489865.71,
  "total_pnl_24_h": 0
}
typescript
// 从GET /v1/positions响应中获取的可用字段:
{
  "current_margin_ratio_with_orders": 1.2385,
  "free_collateral": 450315.09,
  "initial_margin_ratio": 0.1,
  "initial_margin_ratio_with_orders": 0.1,
  "maintenance_margin_ratio": 0.05,
  "maintenance_margin_ratio_with_orders": 0.05,
  "margin_ratio": 1.2385,
  "open_margin_ratio": 1.2102,
  "total_collateral_value": 489865.71,
  "total_pnl_24_h": 0
}

Margin vs Collateral: Understanding the Hierarchy

保证金与抵押物:理解层级关系

Orderly uses a multi-layer risk system. Here's how the pieces fit together:
Your Deposit
[Collateral Factor] → Determines effective collateral value
Effective Collateral (what you can actually use)
[IMR/MMR] → Required margin per position
Used Collateral (locked in positions)
Free Collateral (available for new trades)
Orderly Network采用多层风险系统,各部分关系如下:
您的存款
[抵押物系数] → 计算有效抵押物价值
有效抵押物(实际可使用的金额)
[IMR/MMR] → 每个仓位所需的保证金
已用抵押物(被仓位锁定的金额)
可用抵押物(可用于新交易的金额)

The Three Layers Explained

三层机制详解

1. Collateral Factor (Token Level)
  • Set per token by Orderly risk team
  • Example: USDC = 1.0, USDT = 0.95
  • Applied when you deposit: $1000 USDT × 0.95 = $950 effective collateral
  • Where to find it:
    GET /v1/public/token
2. IMR/MMR (Position Level)
  • IMR (Initial Margin Ratio): Minimum collateral needed to OPEN a position
  • MMR (Maintenance Margin Ratio): Minimum collateral needed to KEEP a position open
  • Determined by leverage: 10x leverage = 10% IMR, ~5% MMR
  • Applied to position notional: $10,000 position × 10% IMR = $1,000 required
  • Where to find it: Position object or symbol info
3. Account Margin Ratio (Account Level)
  • margin_ratio = total_collateral / total_notional
  • If this drops toward MMR, you're approaching liquidation
  • Where to find it:
    GET /v1/client/holding
1. 抵押物系数(代币级别)
  • 由Orderly Network风险团队为每个代币设置
  • 示例:USDC = 1.0,USDT = 0.95
  • 存款时应用该系数:1000 USDT × 0.95 = 950美元有效抵押物
  • 查询方式
    GET /v1/public/token
2. IMR/MMR(仓位级别)
  • IMR(初始保证金比例):开仓所需的最低抵押物
  • MMR(维持保证金比例):维持仓位开放所需的最低抵押物
  • 由杠杆倍数决定:10倍杠杆对应10% IMR,约5% MMR
  • 应用于仓位名义价值:10,000美元仓位 × 10% IMR = 1,000美元所需保证金
  • 查询方式:仓位对象或代币信息
3. 账户保证金比例(账户级别)
  • margin_ratio = total_collateral / total_notional
  • 当该比例接近MMR时,您的仓位将面临强平风险
  • 查询方式
    GET /v1/client/holding

Calculation Example

计算示例

Deposit: $10,000 USDC (collateral_factor = 1.0)
Effective Collateral: $10,000

Open Position: $50,000 ETH-PERP at 10x leverage
IMR Required: $50,000 × 10% = $5,000
MMR Required: $50,000 × 5% = $2,500

After opening:
- Used Collateral: $5,000
- Free Collateral: $5,000
- Margin Ratio: $10,000 / $50,000 = 20%

Liquidation happens when:
- Margin Ratio drops to MMR (5%)
- That means your collateral drops to $2,500
- Or position grows to $200,000 notional
Key Takeaway: You need sufficient effective collateral (after collateral factor) to meet IMR requirements (determined by leverage). The margin_ratio tells you how close you are to liquidation (determined by MMR).
存款:10,000 USDC(抵押物系数=1.0)
有效抵押物:10,000美元

开仓:50,000美元ETH永续合约,10倍杠杆
所需IMR:50,000美元 × 10% = 5,000美元
所需MMR:50,000美元 × 5% = 2,500美元

开仓后:
- 已用抵押物:5,000美元
- 可用抵押物:5,000美元
- 保证金比例:10,000美元 / 50,000美元 = 20%

强平触发条件:
- 保证金比例降至MMR(5%)
- 即抵押物价值降至2,500美元
- 或仓位名义价值增至200,000美元
关键要点:您需要足够的有效抵押物(扣除抵押物系数后)来满足IMR要求(由杠杆倍数决定)。保证金比例反映了您距离强平的风险程度(由MMR决定)。

Common Issues

常见问题

"Position would exceed max leverage" error

“Position would exceed max leverage”错误

  • Current notional with new leverage exceeds limits
  • Reduce position size or increase collateral
  • 当前仓位名义价值加上新杠杆超过限制
  • 减小仓位规模或增加抵押物

"Insufficient margin for TP/SL" error

“Insufficient margin for TP/SL”错误

  • TP/SL orders require available margin
  • Close some positions or add collateral
  • 止盈/止损订单需要可用保证金
  • 平仓部分仓位或增加抵押物

TP/SL not triggering

止盈/止损未触发

  • Check if trigger_price is valid
  • Verify the order is in NEW status
  • Market may have gapped past trigger
  • 检查触发价格是否有效
  • 验证订单状态是否为NEW
  • 市场价格可能跳空越过触发价

Liquidation risk

强平风险

  • Monitor margin_ratio closely
  • Set stop-losses early
  • Watch funding rates for extended positions
  • 密切监控保证金比例
  • 尽早设置止损订单
  • 长期持有仓位时关注资金费率

Related Skills

相关技能

  • orderly-trading-orders - Placing orders
  • orderly-websocket-streaming - Real-time position updates
  • orderly-sdk-react-hooks - Full SDK reference
  • orderly-api-authentication - Signing requests
  • orderly-trading-orders - 下单操作
  • orderly-websocket-streaming - 实时仓位更新
  • orderly-sdk-react-hooks - 完整SDK参考
  • orderly-api-authentication - 请求签名