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:
| Field | Type | Required | Description |
|---|---|---|---|
| status | string | false | The status of the trades. Possible values: open (default) / close. |
| fromDate | string | true | The start date for the gain/loss calculation in YYYY-MM-DD format. |
| toDate | string | true | The 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
| Field | Type | Description |
|---|---|---|
| serverTime | string | Server timestamp in DD/MM/YY HH:mm:ss format. |
| msgId | string | Unique message identifier. |
| status | string | Response status (e.g., Success). |
| statusMessage | string | Brief status message. |
| gainLossValue | object | Contains realized and unrealized gains/losses. |
| gainLossValue.realizedGL | string | Total realized gain/loss. |
| gainLossValue.unrealizedGL | string | Total unrealized gain/loss. |