OS Trading Engine
API Reference
Endpoints
Historical Swaps

Historical Swaps

View completed trades (closed positions) with full profit/loss information.


Endpoints Overview

MethodEndpointDescription
GET/api/v1/agent-historical-swapsList historical swaps
GET/api/v1/agent-historical-swaps/exportExport swaps as CSV
GET/api/v1/agent-historical-swaps/:idGet a specific swap
POST/api/v1/agent-historical-swapsCreate a swap record
PUT/api/v1/agent-historical-swaps/:idUpdate a swap
DELETE/api/v1/agent-historical-swaps/:idDelete a swap

All historical swap endpoints require JWT authentication.


List Historical Swaps

Get completed trades for an agent with comprehensive filtering.

GET /api/v1/agent-historical-swaps?agentId=:agentId

Query Parameters

ParameterTypeRequiredDescription
agentIdUUIDYesAgent ID
walletAddressstringNoFilter by wallet
tokenAddressstringNoFilter by token
tokenSymbolstringNoFilter by symbol
startPurchaseTimeISO 8601NoPurchase date from
endPurchaseTimeISO 8601NoPurchase date to
startSaleTimeISO 8601NoSale date from
endSaleTimeISO 8601NoSale date to
signalIdintegerNoFilter by signal
minProfitLossUsdnumberNoMinimum P/L USD
maxProfitLossUsdnumberNoMaximum P/L USD
limitintegerNoMax results (default: 100, max: 1000)
offsetintegerNoSkip results (default: 0)

Response

Success (200)

[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "agentId": "123e4567-e89b-12d3-a456-426614174000",
    "walletAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
    "tokenAddress": "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
    "tokenSymbol": "BONK",
    "amount": "1000000",
    "purchasePrice": "0.00000234",
    "salePrice": "0.00000280",
    "changePercent": "19.66",
    "profitLossUsd": "4.60",
    "profitLossSol": "0.046",
    "purchaseTime": "2025-01-18T10:00:00.000Z",
    "saleTime": "2025-01-20T14:30:00.000Z",
    "purchaseTransactionId": "abc123",
    "saleTransactionId": "def456",
    "signalId": "12345",
    "closeReason": "manual",
    "createdAt": "2025-01-20T14:30:00.000Z"
  }
]

Response Fields

FieldTypeDescription
idUUIDSwap record ID
agentIdUUIDAgent ID
walletAddressstringWallet address
tokenAddressstringToken mint address
tokenSymbolstringToken ticker
amountstringToken amount traded
purchasePricestringBuy price in SOL
salePricestringSell price in SOL
changePercentstringPrice change percentage
profitLossUsdstringP/L in USD
profitLossSolstringP/L in SOL
purchaseTimeISO 8601When position was opened
saleTimeISO 8601When position was closed
purchaseTransactionIdstringBuy transaction ID
saleTransactionIdstringSell transaction ID
signalIdstringOriginating signal ID
closeReasonstringWhy position was closed

Close Reasons

ReasonDescription
manualManually closed by user
stop_lossTriggered by stop loss
stale_tradeClosed due to position age limit

Example

# Get profitable trades
curl -X GET "https://your-instance.com/api/v1/agent-historical-swaps?agentId=123e...&minProfitLossUsd=0" \
  -H "Authorization: Bearer <access_token>"
 
# Get trades for a specific token
curl -X GET "https://your-instance.com/api/v1/agent-historical-swaps?agentId=123e...&tokenSymbol=BONK" \
  -H "Authorization: Bearer <access_token>"

Export Swaps

Export historical swaps as CSV for analysis.

GET /api/v1/agent-historical-swaps/export?agentId=:agentId

Query Parameters

Same as List Historical Swaps.

Response

Returns CSV file with headers:

  • id, tokenAddress, tokenSymbol, amount
  • purchasePrice, salePrice, changePercent
  • profitLossUsd, profitLossSol
  • purchaseTime, saleTime, closeReason

Example

curl -X GET "https://your-instance.com/api/v1/agent-historical-swaps/export?agentId=123e..." \
  -H "Authorization: Bearer <access_token>" \
  -o trades.csv

Get Historical Swap

Get a specific swap by ID.

GET /api/v1/agent-historical-swaps/:id

Path Parameters

ParameterTypeDescription
idUUIDSwap record ID

Response

Success (200)

Returns the swap object.


Performance Analysis

Use query filters to analyze trading performance:

# This month's trades
curl "...?agentId=123&startSaleTime=2025-01-01T00:00:00Z"
 
# Losing trades (for analysis)
curl "...?agentId=123&maxProfitLossUsd=-0.01"
 
# Stop loss triggered trades
curl "...?agentId=123&closeReason=stop_loss"

Related Endpoints