Skip to content

Basket Margin Calculator

POST basket/spanCalculator

This API calculates the margin requirements for a basket of financial instruments, including futures and options, by evaluating potential risks across various market scenarios. It determines the minimum margin needed to cover potential losses, ensuring sufficient margin is maintained to protect against significant market fluctuations.

Parameters

NameTypeRequiredDescription
basketIdstringtrueThis is the unique identifier for the basket. The span calculator will use this ID to retrieve details about the basket and perform the necessary calculations.

Sample Request Body

json
requestBody={
    "basketId" :"63"
}

Sample Code

bash
curl -X POST 'https://tradeapi.samco.in/basket/spanCalculator' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'x-session-token: <SESSION_TOKEN>' \
  -d '{"basketId":"63"}'
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 = """
        {
          "basketId": "63"
        }
        """;

    HttpClient client = HttpClient.newHttpClient();

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://tradeapi.samco.in/basket/spanCalculator"))
        .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 = {
    basketId: "63"
  };

  const response = await fetch('https://tradeapi.samco.in/basket/spanCalculator', {
    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 = {
  "basketId": "63"
}

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

print(r.json())

Sample Responses

json
{
    "serverTime": "20/08/24 19:17:32",
    "msgId": "493edbec-ee44-4022-a7d2-b2431eae8c28",
    "status": "Success",
    "statusMessage": "Peak Margin and Final Margin Calculated Successfully",
    "spanDetails": {
        "maxMargin": 11.56,
        "finalMargin": 23.1
    }
}
json
{
    "serverTime": "20/08/24 19:27:51",
    "status": "Failure",
    "statusMessage": "No such Basket found"
}

Response Schema

Status Code 200

NameTypeDescription
serverTimestringThis indicates the timestamp of when the response was generated by the server.
msgIdstringA unique identifier for the message or response. It helps in tracking and referencing the specific response.
statusstringStatus of the order cancellation request. Can be success, error or failure.
statusMessagestringProvides a human-readable description of the status.
spanDetailsobjectThis is an object containing detailed information about the margins.
maxMarginstringThe maximum margin required for the basket order.
finalMarginstringThe final margin amount required after considering all adjustments.