How can I get municipal instruments data with a list of cusip?

I have a list of cusip data about municipal bonds with around 50000 length, and I wanna get their historical rating with rd.discovery.search, but the followting code doesn't work.

What should I do?

cusip = ['18085PMP6', '613340Q27', '181012B','10141PAM5'
,'181059KB','181000LH1'] # The actual length is 500000
ratings = rd.discovery.search(
view = rd.discovery.Views.MUNICIPAL_INSTRUMENTS,
query = cusip,
select = "CUSIP, Ratings"
)

Best Answer

  • wasin.w
    wasin.w admin
    Answer ✓

    Hello @eikon11

    Thank you for contacting us. According to the RD Library reference, the query parameter of the rd.discovery.search method supports string only, not an array.

    search.png

    However, the query string supports the boolean operator, so you can use the "A OR B OR C ..." query as follows:

    cusip = ['18085PMP6', '613340Q27', '181012B','10141PAM5','181059KB','181000LH1'] # The actual length is 500000
    ratings = rd.discovery.search(
        view = rd.discovery.Views.MUNICIPAL_INSTRUMENTS,
        query = ' OR '.join(cusip),
        select = "CUSIP, Ratings"
    )
    ratings

    ** Note**: You may need to split 50000 items to multiple lists and sends request multiple times instead of sending one request with 50000 items.

    search-2.png I hope this helps.