Search code examples
c++bloomberg

Bloomberg API argument passing


As part of my project for downloading volatilities for many options, my previous code saves the CHAIN_TICKERS for a given equity in a text file (BB.txt) in the following format:

MSFT US 01/20/17 C23
MSFT US 01/20/17 C25
MSFT US 01/20/17 C30
MSFT US 01/20/17 C33
MSFT US 01/20/17 C35
MSFT US 01/20/17 C38
MSFT US 01/20/17 C40
MSFT US 01/20/17 C43
MSFT US 01/20/17 C45
MSFT US 01/20/17 C47
MSFT US 01/20/17 C50
MSFT US 01/20/17 C52.5
MSFT US 01/20/17 C55
MSFT US 01/20/17 C57.5
MSFT US 01/20/17 C60
MSFT US 01/20/17 C65
MSFT US 01/20/17 C70

First, I defined a structure to save the relevant data for the different options:

struct option{
string ticker;
char date;
double strike;
double vol;
} options [1000];

Now, for my further analysis I wish to download the volatility for these options. Currently I just read the text file line by line and then pass the ticker to the download function inside a for-loop.

std::fstream myfile("BB.txt");
int linenumber = 0;
string linetext;
string ticker;
while (std::getline(myfile, linetext))
{
    options[linenumber].ticker = linetext;
    linenumber++;
}


for (int i = 0; i < linenumber; i++)
{
    std::cout << options[i].ticker << endl;
    ticker = options[i].ticker;
    try
    {
        example.run2(ticker);
    }
    catch (Exception &e)
    {
        std::cerr << "Library Exception!!!" << e.description() << std::endl;
    }
}

The code for my run2 looks as follows:

public void run2(string ticker)
{ ...
request.append("securities", ticker);
request.append("fields", "IVOL_MID");
CorrelationId cid(this);
session.sendRequest(request, cid);

(followed by the eventhandler processMessage taken from the SimpleRefDataOverrideExample.cpp of the Bloomberg API)

Now, the problem is in the line:

request.append("securities", ticker);

Error C2664: cannot convert argument 2 from 'std::string' to 'bool', so it seems like the appended value has to be a bool value? This seems confusing to me, since before I've always entered text such as "MSFT US EQUITY" into the field without any problems.

So, how can I pass my ticker to the run2 function so that the volatility for the respective ticker is downloaded?

(Also, is there an easier way than exporting all my CHAIN_TICKERS to a text file and then reimporting?)


Solution

  • There is documentation blpapi::Request here.There is no overload of blpapi::Request::append taking a std::string in the second position. The complaint about bool is just your compiler trying to make a guess about which overload you might have meant.

    Try instead the version taking a const char *, using ticker.c_str():

    request.append("securities", ticker.c_str());