Get instruments listed in an exchange
To get the list of the instruments listed in an exchange, the following methods are avalilable:
public InstrumentResponse getAllInstruments(String exchange) {
.......................
}
Here at the time of calling the method you just have to pass the value of the exchange. The value must be from the list of exchanges which you can get by calling the getSubscribedExchanges() method.
Example.
GfeedClient gc=new GfeedClient("WEB SOCKET ENDPOINT URL","API KEY");
...................................................
InstrumentResponse ir=gc.getAllInstruments("NSE");
if(ir.instruments!=null){
for(int i=0;i<ir.instruments.size();i++) {
System.out.println(
(i+1)+ "::Name : "+ ir.instruments.get(i).name+
" Symbol : "+ ir.instruments.get(i).tradeSymbol+
" Identifier : "+ ir.instruments.get(i).identifier+
" Exchange : "+ ir.request.exchange
);
}
}
A word of caution is that, when calling this method it is going to dump really huge data set which might sometimes become difficult to handle. So, use this method only when necessary. In another way you can get the list of instruments in an exchange in a filtered way.
public InstrumentResponse getAllInstruments(String exchange,Map<String,String> optionalParameters) {
..........................
}
Here along with the valid exchange value[use getSubscribedExchanges() to see the valid values], you can pass some optional parameters to filter the response using Map. Here point to be noted is that, for the map which has to be passed as argument, the Keys of the <key,value> pairs are constants and predefined. The valid values can be obtained by calling other methods.
The list of supported <key,value> pairs:
-
<Constants.INSTRUMENT_TYPE_KEY,instrument_type_value>
The valid values for instrument_type_value can be found in the response of getInstumentTypes(...) method. -
<Constants.PRODUCT_KEY,product_value>
The valid values for product_value can be found in the response of getProducts(...) method. -
<Constants.OPTION_TYPE_KEY,option_type>
The valid values for option_type can be found in the response of getOptionTypes(...) method. -
<Constants.EXPIRY_DATE_KEY,expiry_date>
The valid values for expiry_date can be found in the response of getExpiryDates(...) method. -
<Constants.STRIKE_PRICE_KEY,strike_price>
The valid values for strike_price can be found in the response of getStrikePrices(...) method.
Sample optional parameters map
Map<String,String> optionalParameters = new HashMap<String,String>();
optionalParameters.put(Constants.INSTRUMENT_TYPE_KEY, "FUTIDX");
optionalParameters.put(Constants.PRODUCT_KEY, "BANKNIFTY");
optionalParameters.put(Constants.OPTION_TYPE_KEY, "CE");
optionalParameters.put(Constants.EXPIRY_DATE_KEY, "30Aug2018");
optionalParameters.put(Constants.STRIKE_PRICE_KEY, "8000");
The return type of the getAllInstruments(...) method consists of the following fields:
-
InstrumentRequest request
-
List<Instrument> instruments
This is the actual list of instruments where each element contains the following information. All are public fields.
Variable Name | Type |
---|---|
identifier | String |
name | String |
expiry | String |
strikePrice | double |
product | String |
priceQuotationUnit | String |
optionType | String |
productMonth | String |
underlyingAsset | String |
underlyingAssetExpiry | String |
indexName | String |
tradeSymbol | String |
Example
To print the identifier for the first instrument in theinstruments
List you an write
InstrumentResponse ir=gc.getAllInstruments("NSE");
System.out.println(ir.instruments.get(0).identifier);
-
String responseMessage
The valid response equals toConstants.INSTRUMENT_RESULT_RESPONSE
.
Dhelm® is a trademark of the KNC Solutions Private Limited.
For any query email at developer@kncsolutions.in
- Home
- Initialization and connection to web socket api
- Getting the list for subscribed exchanges
- Get instruments listed in an exchange
- Search instruments with keyword
- Get Last Quote
- Get snapshot data
- Get historical data
- Get required details
- Get account details
- Get market messages
- Get exchange messages
- Subscribe to realtime data
- Subscribe to realtime snapshot data
- Glossary of Methods
- Conclusion