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
    },
    "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
purchase.transactionobjectPurchase transaction details
currentobjectCurrent market data
current.priceNativenumberCurrent price in SOL
current.priceUsdnumberCurrent price in USD
current.valueNativenumberPosition value in SOL
current.valueUsdnumberPosition value in USD
profitLossobjectP/L metrics
profitLoss.nativenumberP/L in SOL
profitLoss.usdnumberP/L in USD
profitLoss.percentnumberP/L percentage
stopLossobjectStop loss configuration
stopLoss.percentagenumberStop loss percentage from peak
stopLoss.peakPricenumberHighest price seen

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.


Related Endpoints