question

Upvotes
Accepted
68 3 4 8

InstrumentList and InstrumentListItems

Hello everybody,

InstrumentListOperations.GetAllInstruments(List) returns a type IDssEnumerable<InstrumentListItem>, that represents an InstrumentList.

If you want to add an instrument to that list, by InstrumentListOperations.AppendIdentifiers, you need an InstrumentList type as a first argument.

How can I do the conversion ?

C#'s ToList() does not do it.

I imagine the answer lays somewhere in the documentation ?

tick-history-rest-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
11.3k 25 8 13
@Hubert CANEVET

I'm not sure that I understand your question correctly. Please correct me if I'm wrong. The GetAllInstruments will return the IDssEnumerable<InstrumentListItem> which represents all InstrumentListItems in the InstrumentList.

If you want to add an identifier, you can use the InstrumentList object that contains the ListId property. There is no need to know the existing InstrumentListItem in the InstrumentList. The ListId can be retrieved in the following situations.

- after the InstrumentListOperations.Create is called (if you create new InstrumentList)

var instrumentList = new InstrumentList { Name = "TestInstrumentList" };
extractionsContext.InstrumentListOperations.Create(instrumentList);
 
IEnumerable<InstrumentIdentifier> appendIdentifiers = new[] {
    new InstrumentIdentifier
    {
        Identifier = "IBM.N",
        IdentifierType = IdentifierType.Ric
    }};
extractionsContext.InstrumentListOperations.AppendIdentifiers(instrumentList, appendIdentifiers, false);

or

- returned from InstrumentListOperations.GetByName (if there is existing InstrumentList and you know its name)

var instrumentList = ExtractionsContext.InstrumentListOperations.GetByName("TestInstrumentList");

var appendResult = ExtractionsContext.InstrumentListOperations.AppendIdentifiers(
        instrumentList,
    new[] {
            new InstrumentIdentifier
            {
                Identifier = "IBM.N",
                IdentifierType = IdentifierType.Ric
            }
    },false);

or

- you can set ListId directly, if you have already know the Instrument list Id

var instrumentList = new InstrumentList();
instrumentList.ListId = "0x05cc948a738b3026";
var appendResult = ExtractionsContext.InstrumentListOperations.AppendIdentifiers(
        instrumentList,
    new[] {
            new InstrumentIdentifier
            {
                Identifier = "IBM.N",
                IdentifierType = IdentifierType.Ric
            }
    }, false
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
68 3 4 8

Before getting a better answer, here is how I did it.

  /// <summary>
  /// Adds an instrument to a list
  /// </summary>
  /// <param name="extractionsContext"></param>
  /// <param name="list">InstrumentList that has to receive instruments</param>
  /// <param name="toAppend">list of new instruments</param>
  public void AddInstrumentsToList(ExtractionsContext extractionsContext,
      InstrumentList list, List<InstrumentIdentifier> toAppend)
  {
     extractionsContext.InstrumentListOperations.AppendIdentifiers
                                         (list, toAppend, false);
  }

A few remarks about execution : the new instruments are added into the list as appears on the web interface, but the API call only reflects it at the following session. I imagine a refresh instruction was required to get it quicker.

In the "toAppend" list, as the name sets it you only put the new identifiers.

By default I instructed not to keep duplicates, for other preferences see the last argument of AppendIdentifiers.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
68 3 4 8

Hello,

Well, thank you for your answer, I think we illustrated differently the same reality : on one side you manage an InstrumentList, of its type, on the other side you manage the fields to add in a collection of InstrumentIdentifiers, and there is not necessarily any conversion between those both forms, except by writing a loop to transfer data from one to the other if needed.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
68 3 4 8

I feel it could have made sense to accept both answers, but that is not allowed by the forum. So, Veerapath's one will do, until someone shows us a documentation telling that a function exists to do the conversion.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
68 3 4 8
A few remarks about execution : the new instruments are added into the 
list as appears on the web interface, but the API call only reflects it 
at the following session. I imagine a refresh instruction was required 
to get it quicker.

Does anybody have any clue to access quicker to that list once created ?

I already have to propose a session when scheduling a request, and another one when retrieving the results, it would be nice to avoid a third one.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

and of course, if I search it by id although I give the description, it will be very long until it appears ..

I think I do not clearly understand your question. Could you please elaborate on this sentense: "but the API call only reflects it at the following session."? How you propose a session? It also is very helpful, if you can share your code.

Upvotes
11.3k 25 8 13
@Hubert CANEVET

I guess that you use the Count property of InstrumentList object to verify if the new instruments are added, after the AppendIdentifiers is called. The AppendIdentifiers call normally doesn't update the Count property. You need to call InstrumentListOperations.Get to get updated information of Instrument list. Below is the code demonstrating how the Get method is used.

var instrumentList = ExtractionsContext.InstrumentListOperations.GetByName("TestInstrumentList");
System.Console.WriteLine(instrumentList.Count);

var appendResult = ExtractionsContext.InstrumentListOperations.AppendIdentifiers(
  instrumentList,
  new[] {
  new InstrumentIdentifier
  {
  Identifier = "THB=",
  IdentifierType = IdentifierType.Ric
  }
}, false);

instrumentList = ExtractionsContext.InstrumentListOperations.Get(instrumentList.ListId);
System.Console.WriteLine(instrumentList.Count);
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
68 3 4 8

Hello,

Oh, InstrumentList.Count returns the number of instruments, but you mean this is an undocumented functionality ?

Good to know, thank you.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea