Dynamically create a list of RICs for the WithRics property

Hello,


I'm writing in C# and trying to determine if it's possible to pull a snapshot (not a subscription) of data for multiple RICs at a time, however I want to determine the list of RICs at runtime. In my testing I've been able to get the below to work without issue.

            realtime.SetupDataRequest()
               .WithRics("AAPL.O", "MSFT.O", "TRN.N","TSLA.O","F")
               .WithFields("OPEN_PRC","ACVOL_1","PCTCHG_YTD")
               .OnDataReceived(DataReceivedCallback)
               .CreateAndSend();

However, what I'd like to do is something like this:

            string rics = "\"AAPL.O\", \"MSFT.O\", \"TRN.N\", \"TSLA.O\", \"F\"";
            realtime.SetupDataRequest()
               .WithRics(rics)
               .WithFields("OPEN_PRC","ACVOL_1","PCTCHG_YTD")
               .OnDataReceived(DataReceivedCallback)
               .CreateAndSend();

Which would allow me to dynamically build the list of RICs at run time. Is something like that possible and if so can someone point me to in the right direction? Thank you very much.

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @xmeadow

    You can create a List<string> and then add RICs into that list.

    List<string> rics = new List<string>();
    rics.Add("AAPL.O");
    rics.Add("MSFT.O");
    rics.Add("TRN.N");
    rics.Add("TSLA.O");
    rics.Add("F");
    realtime.SetupDataRequest()
        .WithRics(rics)
        .WithFields("OPEN_PRC", "ACVOL_1", "PCTCHG_YTD")
       .OnDataReceived(DataReceivedCallback)
       .CreateAndSend();

    Otherwise, you can create a list from a comma-separated string by using the Split method.

    string rics = "AAPL.O,MSFT.O,TRN.N,TSLA.O,F";
    realtime.SetupDataRequest()
        .WithRics(rics.Split(','))
        .WithFields("OPEN_PRC", "ACVOL_1", "PCTCHG_YTD")
       .OnDataReceived(DataReceivedCallback)
       .CreateAndSend();

Answers

  • xmeadow
    xmeadow Newcomer

    This works great, thank you. I also found that you can pass a string array

    string rics[] = new string[5]

    But using a dynamic list is even better. Thank you.