Skip to content

Commit fdbb4ad

Browse files
committed
changes to add new trigger range api
1 parent d238fce commit fdbb4ad

File tree

6 files changed

+32
-20
lines changed

6 files changed

+32
-20
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,16 @@ For more details about different mode of quotes and subscribing for them, take a
344344

345345
#### Profile
346346

347-
* Added new profile API call to fetch user details.
347+
* Added new profile API call to fetch user details.
348+
349+
#### Trigger range
350+
351+
* Trigger range API supports fetching trigger range for multiple instruments in one request.
352+
353+
#### TriggerRange (model)
354+
355+
| version 2 | version 3 |
356+
| :---: | :---: |
357+
| start | lower |
358+
| end | upper |
359+
| percent | percentage |

dist/kiteconnect.jar

629 Bytes
Binary file not shown.

kiteconnect/src/com/zerodhatech/kiteconnect/KiteConnect.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,20 +569,17 @@ public Map<String, LTPQuote> getLTP(String[] instruments) throws KiteException,
569569
/**
570570
* Retrieves buy or sell trigger range for Cover Orders.
571571
* @return TriggerRange object is returned.
572-
* @param exchange can be NSE, BSE, MCX
573-
* @param tradingSymbol is the instrument name.
574-
* @param trasactionType "BUY or "SELL".
572+
* @param instruments is the array of tradingsymbol and exchange or instrument token.
573+
* @param transactionType "BUY or "SELL".
575574
* @throws KiteException is thrown for all Kite trade related errors.
576575
* @throws JSONException is thrown when there is exception while parsing response.
577576
* @throws IOException is thrown when there is connection related error.
578577
*/
579-
public TriggerRange getTriggerRange(String exchange, String tradingSymbol, String trasactionType) throws KiteException, JSONException, IOException {
580-
Map<String, Object> params = new HashMap<>();
581-
params.put("transaction_type", trasactionType);
582-
583-
String url = routes.get("market.trigger_range").replace(":exchange", exchange).replace(":tradingsymbol", tradingSymbol);
584-
JSONObject response = new KiteRequestHandler(proxy).getRequest(url, params, apiKey, accessToken);
585-
return gson.fromJson(String.valueOf(response.get("data")), TriggerRange.class);
578+
public Map<String, TriggerRange> getTriggerRange(String[] instruments, String transactionType) throws KiteException, JSONException, IOException {
579+
String url = routes.get("market.trigger_range").replace(":transaction_type", transactionType.toLowerCase());
580+
JSONObject response = new KiteRequestHandler(proxy).getRequest(url, "i", instruments, apiKey, accessToken);
581+
Type type = new TypeToken<Map<String, TriggerRange>>(){}.getType();
582+
return gson.fromJson(String.valueOf(response.get("data")), type);
586583
}
587584

588585
/** Retrieves historical data for an instrument.

kiteconnect/src/com/zerodhatech/kiteconnect/Routes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Routes(){
7373
put("market.instruments", "/instruments/:exchange");
7474
put("market.quote", "/quote");
7575
put("market.historical", "/instruments/historical/:instrument_token/:interval");
76-
put("market.trigger_range", "/instruments/:exchange/:tradingsymbol/trigger_range");
76+
put("market.trigger_range", "/instruments/trigger_range/:transaction_type");
7777

7878
put("quote.ohlc", "/quote/ohlc");
7979
put("quote.ltp", "/quote/ltp");

kiteconnect/src/com/zerodhatech/models/TriggerRange.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88
public class TriggerRange {
99

10-
@SerializedName("start")
11-
public double start;
12-
@SerializedName("end")
13-
public double end;
14-
@SerializedName("percent")
15-
public double percent;
10+
@SerializedName("lower")
11+
public double lower;
12+
@SerializedName("upper")
13+
public double upper;
14+
@SerializedName("percentage")
15+
public double percentage;
1616
}

sample/src/Examples.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ public void placeCoverOrder(KiteConnect kiteConnect) throws KiteException, IOExc
116116
/** Get trigger range.*/
117117
public void getTriggerRange(KiteConnect kiteConnect) throws KiteException, IOException {
118118
// You need to send transaction_type, exchange and tradingsymbol to get trigger range.
119-
TriggerRange triggerRange = kiteConnect.getTriggerRange(Constants.EXCHANGE_CDS, "USDINR18JANFUT", Constants.TRANSACTION_TYPE_BUY);
120-
System.out.println(triggerRange.start);
119+
String[] instruments = {"BSE:INFY", "NSE:APOLLOTYRE", "NSE:SBIN"};
120+
Map<String, TriggerRange> triggerRangeMap = kiteConnect.getTriggerRange(instruments, Constants.TRANSACTION_TYPE_BUY);
121+
System.out.println(triggerRangeMap.get("NSE:SBIN").lower);
122+
System.out.println(triggerRangeMap.get("NSE:APOLLOTYRE").upper);
123+
System.out.println(triggerRangeMap.get("BSE:INFY").percentage);
121124
}
122125

123126
/** Get orderbook.*/

0 commit comments

Comments
 (0)