OS Trading Engine
API Reference
Endpoints
Agent Positions

Agent Positions

View and manage open trading positions for agents.


Endpoints Overview

MethodEndpointDescription
GET/api/v1/agent-positions/:agentIdList positions for an agent
POST/api/v1/agent-positions/:agentId/:positionId/closeClose a position

All position endpoints require JWT authentication. Positions can also be accessed via /api/v1/agents/:id/positions.


List Positions

Get all open positions for an agent with enriched market data.

GET /api/v1/agent-positions/:agentId

Path Parameters

ParameterTypeDescription
agentIdUUIDAgent ID

Query Parameters

ParameterTypeRequiredDescription
walletAddressstringNoFilter by specific wallet

Response

Success (200)

[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "agentId": "123e4567-e89b-12d3-a456-426614174000",
    "walletAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
    "tokenAddress": "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
    "tokenSymbol": "BONK",
    "purchase": {
      "priceNative": 0.00000234,
      "priceUsd": 0.000234,
      "amount": 1000000,
      "transaction": {
        "id": "abc123",
        "hash": "5vG3...",
        "time": "2025-01-20T08:00:00.000Z"
      }
    },
    "current": {
      "priceNative": 0.00000256,
      "priceUsd": 0.000256,
      "valueNative": 2.56,
      "valueUsd": 256.00
    },
    "profitLoss": {
      "native": 0.22,
      "usd": 22.00,
      "percent": 9.4,
      "priceChangePercent": 9.4
    },
    "stopLoss": {
      "percentage": 25,
      "peakPrice": 0.00000260
    },
    "takeProfit": {
      "remainingAmount": 750000,
      "levelsHit": 1,
      "realizedProfitSol": 0.05,
      "moonBagActivated": false,
      "moonBagAmount": null
    },
    "createdAt": "2025-01-20T08:00:00.000Z",
    "updatedAt": "2025-01-20T10:30:00.000Z"
  }
]

Response Structure

FieldTypeDescription
idUUIDPosition ID
agentIdUUIDAgent ID
walletAddressstringWallet holding the position
tokenAddressstringToken mint address
tokenSymbolstringToken ticker symbol
purchaseobjectPurchase details
purchase.priceNativenumberPurchase price in SOL
purchase.priceUsdnumberPurchase price in USD
purchase.amountnumberToken amount purchased (original)
purchase.transactionobjectPurchase transaction details
currentobjectCurrent market data
current.priceNativenumberCurrent price in SOL
current.priceUsdnumberCurrent price in USD
current.valueNativenumberPosition value in SOL (remaining tokens)
current.valueUsdnumberPosition value in USD (remaining tokens)
profitLossobjectP/L metrics (realized + unrealized)
profitLoss.nativenumberTotal P/L in SOL
profitLoss.usdnumberTotal P/L in USD
profitLoss.percentnumberTotal P/L percentage (vs original cost)
stopLossobjectStop loss configuration
stopLoss.percentagenumberStop loss percentage from peak
stopLoss.peakPricenumberHighest price seen
takeProfitobjectTake-profit status (if enabled)
takeProfit.remainingAmountnumberTokens remaining after partial sales
takeProfit.levelsHitnumberNumber of take-profit levels triggered
takeProfit.realizedProfitSolnumberSOL profit from take-profit sales
takeProfit.moonBagActivatedbooleanWhether moon bag has been set aside
takeProfit.moonBagAmountnumberTokens reserved as moon bag

For positions with take-profit enabled, profitLoss combines realized profit (from take-profit sales) and unrealized profit (on remaining tokens). The takeProfit.realizedProfitSol shows only the locked-in profit portion.

Example

curl -X GET "https://your-instance.com/api/v1/agent-positions/123e4567-e89b-12d3-a456-426614174000" \
  -H "Authorization: Bearer <access_token>"

Close Position

Manually close an open position by executing a sell trade.

POST /api/v1/agent-positions/:agentId/:positionId/close

Path Parameters

ParameterTypeDescription
agentIdUUIDAgent ID
positionIdUUIDPosition ID

Request

{
  "reason": "manual"
}
FieldTypeRequiredDescription
reasonstringNoClose reason: manual (default) or stop_loss

Response

Success (200)

{
  "success": true,
  "transactionId": "abc123",
  "historicalSwapId": "def456",
  "profitLossSol": 0.22,
  "profitLossUsd": 22.00,
  "changePercent": 9.4,
  "transactionHash": "5vG3..."
}
FieldTypeDescription
successbooleanWhether the close was successful
transactionIdstringSale transaction ID
historicalSwapIdstringHistorical swap record ID
profitLossSolnumberRealized P/L in SOL
profitLossUsdnumberRealized P/L in USD
changePercentnumberPrice change percentage
transactionHashstringOn-chain transaction hash

Error Responses

Position Not Found (404)

{
  "error": "Position not found"
}

Insufficient Balance (400)

{
  "error": "Insufficient token balance"
}

Example

curl -X POST "https://your-instance.com/api/v1/agent-positions/123e.../abc.../close" \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{"reason": "manual"}'
⚠️

Closing a position executes a real trade. In live mode, this sells tokens on-chain via Jupiter.

For positions with take-profit sales, manual close sells only the remaining tokens. The returned P/L includes both realized profit (from previous take-profit sales) and profit from the final close.


Related Endpoints