positions
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePositions - Complete API Reference
仓位管理 - 完整API参考
Manage open positions with automated stop-loss, take-profit, and trailing stop orders.
通过自动化止损、止盈和追踪止损订单管理未平仓仓位。
Chat Commands
聊天命令
View Positions
查看仓位
/positions List all positions
/positions poly Polymarket positions only
/positions futures Futures positions only
/position <id> Position details/positions 列出所有仓位
/positions poly 仅查看Polymarket仓位
/positions futures 仅查看期货仓位
/position <id> 查看仓位详情Stop-Loss
止损(Stop-Loss)
/sl <position-id> at 0.35 Set stop-loss price
/sl <position-id> -10% Stop-loss 10% below entry
/sl poly "Trump" at 0.35 Set by market name/sl <position-id> at 0.35 设置止损价格
/sl <position-id> -10% 止损价为入场价下浮10%
/sl poly "Trump" at 0.35 通过市场名称设置止损Take-Profit
止盈(Take-Profit)
/tp <position-id> at 0.65 Set take-profit price
/tp <position-id> +20% Take-profit 20% above entry
/tp poly "Trump" at 0.65 Set by market name/tp <position-id> at 0.65 设置止盈价格
/tp <position-id> +20% 止盈价为入场价上浮20%
/tp poly "Trump" at 0.65 通过市场名称设置止盈Trailing Stop
追踪止损(Trailing Stop)
/trailing <position-id> 5% Trail 5% from high
/trailing <position-id> $0.05 Trail $0.05 from high/trailing <position-id> 5% 从最高价开始追踪5%
/trailing <position-id> $0.05 从最高价开始追踪0.05美元Partial Exits
部分平仓
/tp <position-id> at 0.55 size 50% Take profit on half
/sl <position-id> at 0.40 size 25% Stop-loss on quarter/tp <position-id> at 0.55 size 50% 止盈平仓一半仓位
/sl <position-id> at 0.40 size 25% 止损平仓四分之一仓位TypeScript API Reference
TypeScript API参考
Create Position Manager
创建仓位管理器
typescript
import { createPositionManager } from 'clodds/positions';
const positions = createPositionManager({
// Monitoring
checkIntervalMs: 5000,
// Execution
orderType: 'market', // 'market' | 'limit'
limitBuffer: 0.01, // Buffer for limit orders
// Storage
storage: 'sqlite',
dbPath: './positions.db',
});
// Start monitoring
await positions.start();typescript
import { createPositionManager } from 'clodds/positions';
const positions = createPositionManager({
// Monitoring
checkIntervalMs: 5000,
// Execution
orderType: 'market', // 'market' | 'limit'
limitBuffer: 0.01, // Buffer for limit orders
// Storage
storage: 'sqlite',
dbPath: './positions.db',
});
// Start monitoring
await positions.start();List Positions
列出仓位
typescript
const all = await positions.list();
for (const pos of all) {
console.log(`${pos.id}: ${pos.platform} ${pos.market}`);
console.log(` Side: ${pos.side}`);
console.log(` Size: ${pos.size}`);
console.log(` Entry: ${pos.entryPrice}`);
console.log(` Current: ${pos.currentPrice}`);
console.log(` P&L: ${pos.pnl} (${pos.pnlPercent}%)`);
console.log(` Stop-loss: ${pos.stopLoss || 'none'}`);
console.log(` Take-profit: ${pos.takeProfit || 'none'}`);
}typescript
const all = await positions.list();
for (const pos of all) {
console.log(`${pos.id}: ${pos.platform} ${pos.market}`);
console.log(` Side: ${pos.side}`);
console.log(` Size: ${pos.size}`);
console.log(` Entry: ${pos.entryPrice}`);
console.log(` Current: ${pos.currentPrice}`);
console.log(` P&L: ${pos.pnl} (${pos.pnlPercent}%)`);
console.log(` Stop-loss: ${pos.stopLoss || 'none'}`);
console.log(` Take-profit: ${pos.takeProfit || 'none'}`);
}Set Stop-Loss
设置止损
typescript
// Absolute price
await positions.setStopLoss({
positionId: 'pos-123',
price: 0.35,
});
// Percentage from entry
await positions.setStopLoss({
positionId: 'pos-123',
percentFromEntry: 10, // 10% below entry
});
// Percentage from current
await positions.setStopLoss({
positionId: 'pos-123',
percentFromCurrent: 5, // 5% below current
});
// Partial stop-loss
await positions.setStopLoss({
positionId: 'pos-123',
price: 0.35,
sizePercent: 50, // Exit 50% of position
});typescript
// Absolute price
await positions.setStopLoss({
positionId: 'pos-123',
price: 0.35,
});
// Percentage from entry
await positions.setStopLoss({
positionId: 'pos-123',
percentFromEntry: 10, // 10% below entry
});
// Percentage from current
await positions.setStopLoss({
positionId: 'pos-123',
percentFromCurrent: 5, // 5% below current
});
// Partial stop-loss
await positions.setStopLoss({
positionId: 'pos-123',
price: 0.35,
sizePercent: 50, // Exit 50% of position
});Set Take-Profit
设置止盈
typescript
// Absolute price
await positions.setTakeProfit({
positionId: 'pos-123',
price: 0.65,
});
// Percentage from entry
await positions.setTakeProfit({
positionId: 'pos-123',
percentFromEntry: 20, // 20% above entry
});
// Multiple take-profit levels
await positions.setTakeProfit({
positionId: 'pos-123',
levels: [
{ price: 0.55, sizePercent: 25 }, // 25% at 0.55
{ price: 0.60, sizePercent: 25 }, // 25% at 0.60
{ price: 0.70, sizePercent: 50 }, // 50% at 0.70
],
});typescript
// Absolute price
await positions.setTakeProfit({
positionId: 'pos-123',
price: 0.65,
});
// Percentage from entry
await positions.setTakeProfit({
positionId: 'pos-123',
percentFromEntry: 20, // 20% above entry
});
// Multiple take-profit levels
await positions.setTakeProfit({
positionId: 'pos-123',
levels: [
{ price: 0.55, sizePercent: 25 }, // 25% at 0.55
{ price: 0.60, sizePercent: 25 }, // 25% at 0.60
{ price: 0.70, sizePercent: 50 }, // 50% at 0.70
],
});Set Trailing Stop
设置追踪止损
typescript
// Percentage trail
await positions.setTrailingStop({
positionId: 'pos-123',
trailPercent: 5, // Trail 5% below high
});
// Absolute trail
await positions.setTrailingStop({
positionId: 'pos-123',
trailAmount: 0.05, // Trail $0.05 below high
});
// Activate after target
await positions.setTrailingStop({
positionId: 'pos-123',
trailPercent: 5,
activateAt: 0.55, // Only start trailing after 0.55
});typescript
// Percentage trail
await positions.setTrailingStop({
positionId: 'pos-123',
trailPercent: 5, // Trail 5% below high
});
// Absolute trail
await positions.setTrailingStop({
positionId: 'pos-123',
trailAmount: 0.05, // Trail $0.05 below high
});
// Activate after target
await positions.setTrailingStop({
positionId: 'pos-123',
trailPercent: 5,
activateAt: 0.55, // Only start trailing after 0.55
});Remove Stops
移除止损/止盈
typescript
// Remove stop-loss
await positions.removeStopLoss('pos-123');
// Remove take-profit
await positions.removeTakeProfit('pos-123');
// Remove trailing stop
await positions.removeTrailingStop('pos-123');
// Remove all
await positions.removeAllStops('pos-123');typescript
// Remove stop-loss
await positions.removeStopLoss('pos-123');
// Remove take-profit
await positions.removeTakeProfit('pos-123');
// Remove trailing stop
await positions.removeTrailingStop('pos-123');
// Remove all
await positions.removeAllStops('pos-123');Event Handlers
事件处理器
typescript
// Stop-loss triggered
positions.on('stopLossTriggered', (position, result) => {
console.log(`🛑 Stop-loss hit: ${position.market}`);
console.log(` Entry: ${position.entryPrice}`);
console.log(` Exit: ${result.exitPrice}`);
console.log(` P&L: ${result.pnl}`);
});
// Take-profit triggered
positions.on('takeProfitTriggered', (position, result) => {
console.log(`✅ Take-profit hit: ${position.market}`);
console.log(` P&L: ${result.pnl}`);
});
// Trailing stop triggered
positions.on('trailingStopTriggered', (position, result) => {
console.log(`📉 Trailing stop hit: ${position.market}`);
console.log(` High: ${position.highWaterMark}`);
console.log(` Exit: ${result.exitPrice}`);
});
// Price approaching stop
positions.on('approaching', (position, type, distance) => {
console.log(`⚠️ ${position.market} ${distance}% from ${type}`);
});typescript
// Stop-loss triggered
positions.on('stopLossTriggered', (position, result) => {
console.log(`🛑 Stop-loss hit: ${position.market}`);
console.log(` Entry: ${position.entryPrice}`);
console.log(` Exit: ${result.exitPrice}`);
console.log(` P&L: ${result.pnl}`);
});
// Take-profit triggered
positions.on('takeProfitTriggered', (position, result) => {
console.log(`✅ Take-profit hit: ${position.market}`);
console.log(` P&L: ${result.pnl}`);
});
// Trailing stop triggered
positions.on('trailingStopTriggered', (position, result) => {
console.log(`📉 Trailing stop hit: ${position.market}`);
console.log(` High: ${position.highWaterMark}`);
console.log(` Exit: ${result.exitPrice}`);
});
// Price approaching stop
positions.on('approaching', (position, type, distance) => {
console.log(`⚠️ ${position.market} ${distance}% from ${type}`);
});Position Summary
仓位汇总
typescript
const summary = await positions.getSummary();
console.log(`Total positions: ${summary.count}`);
console.log(`Total value: $${summary.totalValue}`);
console.log(`Unrealized P&L: $${summary.unrealizedPnl}`);
console.log(`With stop-loss: ${summary.withStopLoss}`);
console.log(`With take-profit: ${summary.withTakeProfit}`);typescript
const summary = await positions.getSummary();
console.log(`Total positions: ${summary.count}`);
console.log(`Total value: $${summary.totalValue}`);
console.log(`Unrealized P&L: $${summary.unrealizedPnl}`);
console.log(`With stop-loss: ${summary.withStopLoss}`);
console.log(`With take-profit: ${summary.withTakeProfit}`);Stop Types
止损类型
| Type | Description |
|---|---|
| Stop-Loss | Exit when price drops to limit losses |
| Take-Profit | Exit when price rises to lock in gains |
| Trailing Stop | Dynamic stop that follows price up |
| Break-Even | Move stop to entry after profit target |
| 类型 | 描述 |
|---|---|
| Stop-Loss(止损) | 当价格下跌至指定价位时平仓以限制损失 |
| Take-Profit(止盈) | 当价格上涨至指定价位时平仓以锁定收益 |
| Trailing Stop(追踪止损) | 随价格上涨动态调整的止损机制 |
| Break-Even(保本止损) | 达到盈利目标后将止损价移动至入场价 |
Order Execution
订单执行
| Option | Description |
|---|---|
| Immediate execution at current price |
| Execute at specified price or better |
| Add buffer to limit price for fills |
| 选项 | 描述 |
|---|---|
| 以当前价格立即执行 |
| 以指定价格或更优价格执行 |
| 为限价订单添加缓冲以确保成交 |
Best Practices
最佳实践
- Always set stops — Don't leave positions unprotected
- Use trailing stops — Lock in gains as price moves
- Partial exits — Scale out at multiple levels
- Monitor approaching — Get alerts before triggers
- Review filled stops — Check execution quality
- 始终设置止损 — 不要让仓位处于无保护状态
- 使用追踪止损 — 随价格上涨锁定收益
- 部分平仓 — 在多个价位逐步减仓
- 监控预警 — 在触发止损/止盈前获取提醒
- 复盘已成交的止损/止盈 — 检查执行质量