返回顶部
o

orderly-positions-tpsl仓位止盈止损

Monitor positions in real-time, configure Take-Profit/Stop-Loss orders, and manage risk with leverage settings

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
235
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

orderly-positions-tpsl

技能名称: orderly-positions-tpsl
详细描述:

Orderly Network:仓位与止盈止损

本技能涵盖仓位管理、盈亏追踪、杠杆设置,以及配置止盈(TP)和止损(SL)订单以进行风险管理。

使用场景

  • - 构建仓位管理界面
  • 使用止盈止损实现风险管理
  • 追踪未实现盈亏
  • 调整杠杆设置

前置条件

  • - 在 Orderly 上持有未平仓仓位
  • 了解永续合约
  • 具有 read 和 trading 权限的 API 密钥

仓位数据结构

typescript
interface Position {
symbol: string; // 例如 PERPETHUSDC
position_qty: number; // 正数 = 多头,负数 = 空头
averageopenprice: number; // 开仓均价
mark_price: number; // 当前标记价格
unrealized_pnl: number; // 未实现盈亏
unrealizedpnlroi: number; // 收益率百分比
mmr: number; // 维持保证金率
imr: number; // 初始保证金率
notional: number; // 仓位价值
leverage: number; // 当前杠杆
estliqprice: number; // 预估强平价
cost_position: number; // 仓位成本
settle_price: number; // 结算价格
unsettled_pnl: number; // 未结算盈亏
}

获取仓位(REST API)

typescript
// 获取所有仓位
GET /v1/positions

// 获取特定交易对的仓位
GET /v1/position/{symbol}

// 示例响应
{
success: true,
data: {
rows: [
{
symbol: PERPETHUSDC,
position_qty: 0.5,
averageopenprice: 3000,
mark_price: 3100,
unrealized_pnl: 50,
unrealizedpnlroi: 0.0333,
mmr: 0.01,
imr: 0.02,
notional: 1550,
leverage: 10,
estliqprice: 2700
}
]
}
}

React SDK:usePositionStream

实时流式传输仓位,并自动更新盈亏:

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

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

if (isLoading) return

正在加载仓位...
;

return (



总未实现盈亏:{aggregated?.totalUnrealizedPnl?.toFixed(2)} USDC


收益率:{(totalUnrealizedROI * 100).toFixed(2)}%


{rows.map((position) => ( ))}
交易对 数量 开仓价 标记价 未实现盈亏 杠杆 强平价
{position.symbol} 0 ? long : short}> {position.positionqty > 0 ? + : }{position.positionqty} {position.averageopenprice.toFixed(2)} {position.mark_price.toFixed(2)} = 0 ? profit : loss}> {position.unrealized_pnl.toFixed(2)} USDC {position.leverage}x {position.liq_price.toFixed(2)}
); }

平仓

部分平仓

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 (






);
}

市价平仓(REST API)

typescript
// 以市价平掉整个仓位
POST /v1/order
Body: {
symbol: PERPETHUSDC,
side: positionQty > 0 ? SELL : BUY,
order_type: MARKET,
order_quantity: Math.abs(positionQty).toString(),
reduce_only: true,
}

杠杆管理

获取当前杠杆

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

// 响应
{
success: true,
data: {
leverage: 10,
max_leverage: 25
}
}

设置杠杆

typescript
POST /v1/client/leverage
Body: {
symbol: PERPETHUSDC,
leverage: 15, // 新的杠杆值
}

// 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(设置杠杆失败:, error);
}
};

return (



type=range
min=1
max={maxLeverage}
value={leverage}
onChange={(e) => handleChange(parseInt(e.target.value))}
disabled={isLoading}
/>

);
}

止盈/止损订单

止盈止损订单类型

类型描述
TAKEPROFIT价格达到目标时触发(获利)
STOPLOSS
价格跌破阈值时触发 | | TRAILING_STOP | 跟随价格的动态止损 |

使用 useTPSLOrder Hook

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(止盈止损订单已下达);
} catch (error) {
console.error(止盈止损失败:, error);
}
};

return (


止盈




type=number
placeholder=止盈价格
onChange={(e) => setValue(tptriggerprice, e.target.value)}
/>



type=number
placeholder=例如 5 表示 5%
onChange={(e) => setValue(tpoffsetpercentage, parseFloat(e.target.value))}
/>

止损

setValue(sltriggerprice, e.target.value)} />

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 orderly-positions-tpsl-1776199413 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 orderly-positions-tpsl-1776199413 技能

通过命令行安装

skillhub install orderly-positions-tpsl-1776199413

下载

⬇ 下载 orderly-positions-tpsl v1.0.0(免费)

文件大小: 4.87 KB | 发布时间: 2026-4-15 10:54

v1.0.0 最新 2026-4-15 10:54
Orderly Positions TP/SL 1.0.0 – Initial Release

- Monitor open positions in real-time, with live PnL and ROI updates.
- Configure Take-Profit and Stop-Loss (TP/SL) orders for risk management.
- Adjust position leverage and manage margin settings.
- Close positions partially or fully via market or SDK methods.
- Simple API and React SDK integration for building position management interfaces.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large