Search code examples
c++bloomberg

c++ bloomberg api correlationId


I'm using the bloomberg api to code a cpp project.
When I need to send a request to the Bloomberg data feed, I must send the request with an ID. For example:

session->sendRequest(*request, CorrelationId(20));

The CorrelationId is provided by the bloomberg api to generate an ID.
The ID here is 20. The result coming from the bloomberg data feed contains the ID 20 so that I can identity the result and the request. Meaning that when I get the result from the data feed, there is something like this:
correlationId=[ valueType=INT classId=0 value=20 ]

Now I want to make a string ID, instead of the int ID. For example, I want to generate an ID like CorrelationId("US543119ES").
If I do this, I get no error but the ID in the result becomes:
correlationId=[ valueType=POINTER classId=0 value=00731378 ]

It seems that the ID becomes a pointer and it sends the value of the pointer, instead of the content of the pointer. Obviously value=00731378 is an address.

Is it impossible to generate a string ID?
If possible, what should I do?
I've found the documentation of CorrelationId.

There are two constructors of CorrelationId that I don't know how to use, I don't know if one of them is what I need:

CorrelationId (void *value, int classId=0);
template<typename TYPE >
CorrelationId (const TYPE &smartPtr, void *pointerValue, int classId=0);

Solution

  • If we want to generate a string ID, we can just send the address of the string. Then the bloomberg data feed will send us back the address, whose type is void *. So we just need to convert it into char *. Here is an example:

    // sending
    const char * id = "abc";
    session->sendRequest(*request, CorrelationId(const_cast<char *>(id))); // it can't take "const char *"
    
    // handling response
    cout << (char *)message.correlationId().asPointer(); // it will show "abc".