How to frame json request for fetching RIC values for multiple ISIN values using java?

Options
meera_c
meera_c Newcomer

This is the json request:

JSONObject searchJSONObject = new JSONObject();

searchJSONObject.put(
"SearchRequest",
new JSONObject()

.put("IdentifierType", "Isin")


.put("Identifier",
new JSONArray().put("ISIN1").put("ISIN2"))


.put("PreferredIdentifierType", "Ric"));

I am getting the following error:

org.apache.http.client.HttpResponseException: Bad Request

Is this the correct way to frame the request? If not, how else can it be done?

Best Answer

  • @meera_c, your code generates an array of instruments, but as pointed out by Veerapath, if you want several they should all be in a single string.

    This is the request generated by the code in your query:

    {"SearchRequest":{"PreferredIdentifierType":"Ric","Identifier":["ISIN1","ISIN2"],"IdentifierType":"Isin"}}

    This is what is required:

    {"SearchRequest":{"PreferredIdentifierType":"Ric","Identifier":"ISIN1, ISIN2","IdentifierType":"Isin"}}

    So the code should be along these lines:

    JSONObject searchJSONObject = new JSONObject()
    .put("SearchRequest", new JSONObject()
    .put("IdentifierType", "Isin")
    .put("Identifier", "ISIN1, ISIN2")
    .put("PreferredIdentifierType", "Ric"));

    But again, as mentioned in my previous comment, using InstrumentSearch for more than 1 ISIN has severe limitations, I do not recommend using it that way.

Answers