Skip to main content
GET
/
api
/
v1
/
trade
/
close
Get Closed Orders
curl --request GET \
  --url https://api.example.com/api/v1/trade/close
{
  "message": [
    {
      "orderId": "550e8400-e29b-41d4-a716-446655440000",
      "userId": "user-123",
      "symbol": "btc",
      "type": "buy",
      "quantity": 0.5,
      "leverage": 10,
      "openPrice": 45000.00,
      "closePrice": 46000.00,
      "openTime": "2024-03-01T10:00:00.000Z",
      "closeTime": "2024-03-01T11:30:00.000Z",
      "profitLoss": 500.00,
      "takeProfit": 47000.00,
      "stopLoss": 44000.00
    }
  ]
}
Retrieves a list of all closed trading orders for the authenticated user from the database. This endpoint provides access to your complete trading history including profit/loss data.

Authentication

This endpoint requires authentication via JWT token in the Authorization header.
Authorization: Bearer <your_jwt_token>

Query Parameters

This endpoint does not accept any query parameters. It automatically returns all closed orders for the authenticated user.

Response

message
array
Array of closed orders
message[].orderId
string
Unique identifier for the order
message[].userId
string
User ID who placed the order
message[].symbol
string
Trading pair symbol (btc, eth, sol)
message[].type
string
Order type (buy or sell)
message[].quantity
number
Amount of cryptocurrency traded
message[].leverage
integer
Leverage multiplier used (1-100)
message[].openPrice
number
Price at which the order was opened
message[].closePrice
number
Price at which the order was closed
message[].openTime
string
Timestamp when the order was opened (ISO 8601)
message[].closeTime
string
Timestamp when the order was closed (ISO 8601)
message[].profitLoss
number
Realized profit or loss from the trade
message[].takeProfit
number | null
Take profit price level (if set)
message[].stopLoss
number | null
Stop loss price level (if set)

Examples

Successful Request

curl -X GET "http://localhost:8000/api/v1/trade/close" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
{
  "message": [
    {
      "orderId": "550e8400-e29b-41d4-a716-446655440000",
      "userId": "user-123",
      "symbol": "btc",
      "type": "buy",
      "quantity": 0.5,
      "leverage": 10,
      "openPrice": 45000.00,
      "closePrice": 46000.00,
      "openTime": "2024-03-01T10:00:00.000Z",
      "closeTime": "2024-03-01T11:30:00.000Z",
      "profitLoss": 500.00,
      "takeProfit": 47000.00,
      "stopLoss": 44000.00
    }
  ]
}

Error Responses

Error: Unauthorized

{
  "error": "Unauthorized"
}

Error: Token Expired

{
  "error": "Token expired or invalid ❌"
}

Use Cases

Trading Performance Analysis

const analyzeTradingPerformance = async (token) => {
  const response = await fetch('http://localhost:8000/api/v1/trade/close', {
    headers: { 'Authorization': `Bearer ${token}` }
  });
  
  const { message: orders } = await response.json();
  
  const totalPnL = orders.reduce((sum, order) => sum + order.profitLoss, 0);
  const winRate = orders.filter(o => o.profitLoss > 0).length / orders.length;
  const avgProfit = totalPnL / orders.length;
  
  return { totalPnL, winRate, avgProfit, totalTrades: orders.length };
};

Export Trading History

const exportTradingHistory = async (token) => {
  const response = await fetch('http://localhost:8000/api/v1/trade/close', {
    headers: { 'Authorization': `Bearer ${token}` }
  });
  
  const { message: orders } = await response.json();
  
  // Convert to CSV
  const csv = orders.map(o => 
    `${o.orderId},${o.symbol},${o.type},${o.quantity},${o.openPrice},${o.closePrice},${o.profitLoss}`
  ).join('\n');
  
  return csv;
};

Build docs developers (and LLMs) love