Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dist/smartapi-java-2.2.3.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.angelbroking.smartapi</groupId>
<artifactId>smartapi-java</artifactId>
<version>2.2.2</version>
<version>2.2.3</version>
<packaging>jar</packaging>

<name>smartapi-java</name>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/angelbroking/smartapi/Routes.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public Routes() {
put("api.market.data", "/rest/secure/angelbroking/market/v1/quote");
put("api.margin.batch", "/rest/secure/angelbroking/margin/v1/batch");
put("api.individual.order", "/rest/secure/angelbroking/order/v1/details/");
put("api.estimateCharges", "/rest/secure/angelbroking/brokerage/v1/estimateCharges");
put("api.verifyDis", "/rest/secure/angelbroking/edis/v1/verifyDis");
put("api.generateTPIN", "/rest/secure/angelbroking/edis/v1/generateTPIN");
put("api.getTranStatus", "/rest/secure/angelbroking/edis/v1/getTranStatus");
put("api.optionGreek", "/rest/secure/angelbroking/marketData/v1/optionGreek");
put("api.gainersLosers", "/rest/secure/angelbroking/marketData/v1/gainersLosers");
put("api.putCallRatio", "/rest/secure/angelbroking/marketData/v1/putCallRatio");
put("api.oIBuildup", "/rest/secure/angelbroking/marketData/v1/OIBuildup");
}
};
}
Expand Down
163 changes: 163 additions & 0 deletions src/main/java/com/angelbroking/smartapi/SmartConnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -862,5 +862,168 @@ public JSONObject getIndividualOrderDetails(String orderId) throws IOException,
throw new JSONException(String.format("%s while fetching margin data %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));
}
}


public JSONObject estimateCharges(List<EstimateChargesParams> estimateChargesParams) throws IOException, SmartAPIException {
try {
JSONArray ordersArray = new JSONArray();

for (EstimateChargesParams params : estimateChargesParams) {
JSONObject order = new JSONObject();
order.put("product_type", params.product_type);
order.put("transaction_type", params.transaction_type);
order.put("quantity", params.quantity);
order.put("price", params.price);
order.put("exchange", params.exchange);
order.put("symbol_name", params.symbol_name);
order.put("token", params.token);
ordersArray.put(order);
}

JSONObject requestBody = new JSONObject();
requestBody.put("orders", ordersArray);

String url = routes.get("api.estimateCharges");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, requestBody, accessToken);
return response;
} catch (SmartAPIException ex) {
log.error("{} while fetching estimateCharges data {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s while fetching estimateCharges data %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while fetching estimateCharges data {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s while fetching estimateCharges data %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while fetching estimateCharges data {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s while fetching estimateCharges data %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));

}
}

public JSONObject verifyDis(JSONObject params) throws SmartAPIException, IOException {
try{
String url = routes.get("api.verifyDis");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response;
}catch (SmartAPIException ex) {
log.error("{} while verifyDis {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s in verifyDis %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while verifyDis {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s in verifyDis %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while verifyDis {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s in verifyDis %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));

}
}

public JSONObject generateTPIN(JSONObject params) throws SmartAPIException, IOException {
try{
String url = routes.get("api.generateTPIN");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response;
}catch (SmartAPIException ex) {
log.error("{} while generateTPIN {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s in generateTPIN %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while generateTPIN {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s in generateTPIN %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while generateTPIN {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s in generateTPIN %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));

}
}

public JSONObject getTranStatus(JSONObject params) throws SmartAPIException, IOException {
try{
String url = routes.get("api.getTranStatus");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response;
}catch (SmartAPIException ex) {
log.error("{} while getTranStatus {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s in getTranStatus %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while getTranStatus {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s in getTranStatus %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while getTranStatus {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s in getTranStatus %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));

}
}

public JSONObject optionGreek(JSONObject params) throws SmartAPIException, IOException {
try{
String url = routes.get("api.optionGreek");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response;
}catch (SmartAPIException ex) {
log.error("{} while optionGreek {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s in optionGreek %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while optionGreek {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s in optionGreek %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while optionGreek {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s in optionGreek %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));

}
}

public JSONObject gainersLosers(JSONObject params) throws SmartAPIException, IOException {
try{
String url = routes.get("api.gainersLosers");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response;
}catch (SmartAPIException ex) {
log.error("{} while gainersLosers {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s in gainersLosers %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while gainersLosers {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s in gainersLosers %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while gainersLosers {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s in gainersLosers %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));

}
}

public JSONObject putCallRatio() throws IOException, SmartAPIException {
try {
String url = routes.get("api.putCallRatio");
JSONObject response = smartAPIRequestHandler.getRequest(this.apiKey, url, accessToken);
return response;
} catch (SmartAPIException ex) {
log.error("{} while getting putCallRatio {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s in getting putCallRatio %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while getting putCallRatio {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s while fetching putCallRatio data %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while getting putCallRatio {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s while fetching putCallRatio data %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));
}
}

public JSONObject oIBuildup(JSONObject params) throws SmartAPIException, IOException {
try{
String url = routes.get("api.oIBuildup");
JSONObject response = smartAPIRequestHandler.postRequest(this.apiKey, url, params, accessToken);
return response;
}catch (SmartAPIException ex) {
log.error("{} while oIBuildup {}", SMART_API_EXCEPTION_OCCURRED, ex.toString());
throw new SmartAPIException(String.format("%s in oIBuildup %s", SMART_API_EXCEPTION_ERROR_MSG, ex));
} catch (IOException ex) {
log.error("{} while oIBuildup {}", IO_EXCEPTION_OCCURRED, ex.getMessage());
throw new IOException(String.format("%s in oIBuildup %s", IO_EXCEPTION_ERROR_MSG, ex.getMessage()));
} catch (JSONException ex) {
log.error("{} while oIBuildup {}", JSON_EXCEPTION_OCCURRED, ex.getMessage());
throw new JSONException(String.format("%s in oIBuildup %s", JSON_EXCEPTION_ERROR_MSG, ex.getMessage()));

}
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.angelbroking.smartapi.models;

public class EstimateChargesParams {

public String product_type;
public String transaction_type;
public String quantity;
public String price;
public String exchange;
public String symbol_name;
public String token;
}
16 changes: 16 additions & 0 deletions src/main/java/com/angelbroking/smartapi/sample/APITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ public static void main(String[] args) throws SmartAPIException {
/* log.info("Individual Order"); */
examples.getIndividualOrder(smartConnect, "1000051");

examples.estimateCharges(smartConnect);

examples.verifyDis(smartConnect);

examples.generateTPIN(smartConnect);

examples.getTranStatus(smartConnect);

examples.optionGreek(smartConnect);

examples.gainersLosers(smartConnect);

examples.putCallRatio(smartConnect);

examples.oIBuildup(smartConnect);


/* SmartAPITicker */
String clientId = "<clientId>";
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/angelbroking/smartapi/sample/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,87 @@ public void onOrderUpdate(String data) {
}
});
}

public void estimateCharges(SmartConnect smartConnect) throws SmartAPIException, IOException {
List<EstimateChargesParams> estimateChargesParamsList = new ArrayList<>();
EstimateChargesParams estimate_Charges_Params = new EstimateChargesParams();
estimate_Charges_Params.product_type = Constants.PRODUCT_DELIVERY;
estimate_Charges_Params.transaction_type = Constants.TRANSACTION_TYPE_BUY;
estimate_Charges_Params.quantity = "10";
estimate_Charges_Params.price = "800";
estimate_Charges_Params.exchange = Constants.EXCHANGE_NSE;
estimate_Charges_Params.symbol_name = "745AS33";
estimate_Charges_Params.token = "17117";

estimateChargesParamsList.add(estimate_Charges_Params);

JSONObject jsonObject = smartConnect.estimateCharges(estimateChargesParamsList);
log.info("response {} ", jsonObject);
}

public void verifyDis(SmartConnect smartConnect) throws SmartAPIException, IOException {

JSONObject payload = new JSONObject();
payload.put("isin", "INE242A01010");
payload.put("quantity", "1");

JSONObject jsonObject = smartConnect.verifyDis(payload);
log.info("response {} ", jsonObject);
}

public void generateTPIN(SmartConnect smartConnect) throws SmartAPIException, IOException {

JSONObject payload = new JSONObject();
payload.put("dpId", "33200");
payload.put("ReqId", "1431307824801952");
payload.put("boid", "1203320018563571");
payload.put("pan", "JZTPS2255C");

JSONObject jsonObject = smartConnect.generateTPIN(payload);
log.info("response {} ", jsonObject);
}

public void getTranStatus(SmartConnect smartConnect) throws SmartAPIException, IOException {

JSONObject payload = new JSONObject();
payload.put("ReqId", "1431307824801952");

JSONObject jsonObject = smartConnect.getTranStatus(payload);
log.info("response {} ", jsonObject);
}

public void optionGreek(SmartConnect smartConnect) throws SmartAPIException, IOException {

JSONObject payload = new JSONObject();
payload.put("name", "TCS");
payload.put("expirydate", "25MAR2024");

JSONObject jsonObject = smartConnect.optionGreek(payload);
log.info("response {} ", jsonObject);
}

public void gainersLosers(SmartConnect smartConnect) throws SmartAPIException, IOException {

JSONObject payload = new JSONObject();
payload.put("datatype", "PercOIGainers");
payload.put("expirytype", "NEAR");

JSONObject jsonObject = smartConnect.gainersLosers(payload);
log.info("response {} ", jsonObject);
}

public void putCallRatio(SmartConnect smartConnect) throws SmartAPIException, IOException {
JSONObject response = smartConnect.putCallRatio();
log.info("response {} ", response);
}

public void oIBuildup(SmartConnect smartConnect) throws SmartAPIException, IOException {

JSONObject payload = new JSONObject();
payload.put("expirytype", "NEAR");
payload.put("datatype", "Long Built Up");

JSONObject jsonObject = smartConnect.oIBuildup(payload);
log.info("response {} ", jsonObject);
}
}
15 changes: 15 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>DENY</onMatch>
<onMismatch>ACCEPT</onMismatch>
</filter>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<logger name="com.angelbroking.smartapi" level="INFO">
<appender-ref ref="STDOUT" />
</logger>

<root level="ERROR">
<appender-ref ref="ERROR_FILE" />
</root>
Expand Down