Skip to content

Gain Loss ​

POST tradeview/gainLoss

The Gain and Loss API provides insights into the gains and losses of trades within a specified date range. It allows users to filter results based on the status of the trades, whether they are open or closed.

Request Parameters ​

The request body should be in JSON format and include the following fields:

FieldTypeRequiredDescription
statusstringfalseThe status of the trades. Possible values: open (default) / close.
fromDatestringtrueThe start date for the gain/loss calculation in YYYY-MM-DD format.
toDatestringtrueThe end date for the gain/loss calculation in YYYY-MM-DD format.

Sample Request Body ​

json
{
    "status": "close",
    "fromDate": "2022-10-24",
    "toDate": "2024-10-24"
}

Sample Code ​

bash
curl -X POST 'https://tradeapi.samco.in/tradeview/gainLoss' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'x-session-token: <SESSION_TOKEN>' \
  -d '{"status":"close","fromDate":"2022-10-24","toDate":"2024-10-24"}'
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Sample {
  public static void main(String[] args) throws Exception {
    String requestBody = """
        {
          "status": "close",
          "fromDate": "2022-10-24",
          "toDate": "2024-10-24"
        }
        """;

    HttpClient client = HttpClient.newHttpClient();

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://tradeapi.samco.in/tradeview/gainLoss"))
        .header("Content-Type", "application/json")
        .header("Accept", "application/json")
        .header("x-session-token", "<SESSION_TOKEN>")
        .POST(HttpRequest.BodyPublishers.ofString(requestBody))
        .build();

    HttpResponse<String> response =
        client.send(request, HttpResponse.BodyHandlers.ofString());
    System.out.println(response.body());
  }
}
js
(async () => {
  const headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'x-session-token': '<SESSION_TOKEN>',
  };

  const requestBody = {
    status: "close",
    fromDate: "2022-10-24",
    toDate: "2024-10-24"
  };

  const response = await fetch('https://tradeapi.samco.in/tradeview/gainLoss', {
    method: 'POST',
    headers,
    body: JSON.stringify(requestBody),
  });

  const data = await response.json();
  console.log(data);
})();
py
import requests
import json

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'x-session-token': '<SESSION_TOKEN>',
}

requestBody = {
  "status": "close",
  "fromDate": "2022-10-24",
  "toDate": "2024-10-24"
}

r = requests.post('https://tradeapi.samco.in/tradeview/gainLoss',
  data=json.dumps(requestBody),
  headers=headers)

print(r.json())

Sample Response ​

json
{
    "serverTime": "29/10/24 13:23:18",
    "msgId": "1cc16113-e30d-4d4b-b1ca-8b738ef7150c",
    "status": "Success",
    "statusMessage": "Analytics Details retrieved successfully.",
    "gainLossValue": {
        "realizedGL": "-905.38",
        "unrealizedGL": "0.00"
    }
}

Response Key Descriptions ​

FieldTypeDescription
serverTimestringServer timestamp in DD/MM/YY HH:mm:ss format.
msgIdstringUnique message identifier.
statusstringResponse status (e.g., Success).
statusMessagestringBrief status message.
gainLossValueobjectContains realized and unrealized gains/losses.
gainLossValue.realizedGLstringTotal realized gain/loss.
gainLossValue.unrealizedGLstringTotal unrealized gain/loss.