Downloading All Instruments
-
In the c# API, which function / command to use to download all instruments ?
-
Write a class and code like this...
public class NSEInstrument
{
[JsonProperty("token")]
public string token { get; set; }
[JsonProperty("symbol")]
public string symbol { get; set; }
[JsonProperty("name")]
public string name { get; set; }
}public List<NSEInstrument> GetNSEInstruments() { WebRequest webRequest = WebRequest.Create("https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json"); HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); if (response.StatusDescription == "OK") { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); List<NSEInstrument> data = JsonConvert.DeserializeObject<List<NSEInstrument>>(responseFromServer); return data; } return null; }
-
@vcb
Implement a class like this...
public class NSEInstrument
{
[JsonProperty("token")]
public string token { get; set; }
[JsonProperty("symbol")]
public string symbol { get; set; }
[JsonProperty("name")]
public string name { get; set; }
}And write this function...
public List<NSEInstrument> GetNSEInstruments()
{
WebRequest webRequest = WebRequest.Create("https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json");
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
if (response.StatusDescription == "OK")
{
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
List<NSEInstrument> data = JsonConvert.DeserializeObject<List<NSEInstrument>>(responseFromServer);
return data;
}
return null;
}Call this function to get all the instruments and tokens