Forum Navigation:


FORUMS > Programming and Software Forum < refresh >
Topic Title: Anyone using Bloomberg C Client API?
Created On Fri Jul 06, 07 05:10 AM
Topic View:

View thread in raw text format


carfield
Junior Member

Posts: 6
Joined: Jul 2007

Fri Jul 06, 07 05:10 AM
User is offline

I print the response using following code, it work for most of the time. However, for few time it print out broken characters like


2007-06-11 09:46:57,raw output of native process: *' *': .0000 : N.A. : 552^HK-2007061101:00:00-2007061108:10:00-null-null-2007061101:46:36-2007061101:45:35-552^HK|20070611|010000|20070611|081000-HK-0-0
2007-06-11 09:46:57,Mismatched code - gotten: Not found at bloomberg expected: *' *': .0000 : N.A. : 552 HK Equity
2007-06-11 09:46:57,*' *': .0000 : N.A. : 552 HK Equity,20070611,01:00:00,20070611,08:10:00,,
2007-06-11 09:46:59,raw output of native process: P,'à,': .0000 : N.A. P,'à,': .0000 : N.A. P,'à,': .0000 : N.A. 338 HK Equity: .0000 : N.A. : 338^HK-2007061101:00:00-2007061108:10:00-null-null-2007061101:46:37-2007061101:45:37-338^HK|20070611|010000|20070611|081000-HK-0-0
2007-06-11 09:46:59,Mismatched code - gotten: P,'à,' expected: .0000 : N.A. P,'à,': .0000 : N.A. 338 HK Equity: .0000 : N.A. : 338 HK Equity
2007-06-11 09:46:59,.0000 : N.A. P,'à,': .0000 : N.A. 338 HK Equity: .0000 : N.A. : 338 HK Equity,20070611,01:00:00,20070611,08:10:00,.0000,N.A. P,'à,'

Anyone experience this and is there any solution?


int decode_fields_x(bb_msg_fieldsx_t *f)
{
    char *p;
     int lp;
     int i;
     int n;
     int iFoundFlag;
     char *pcSecName;
    /* 
    ** Match this responses request_id to the one that we're 
    ** expecting.  Print a warning if we're getting a response
    ** to a request that's already been fufilled, or if we're
    ** getting a response to an unknown request
    */

     iFoundFlag = 0;

     i = search_req_id(plRequestID, iNumOfRequests, f->comm_header.request_id);

     if (i == -1) {
     }
     else {
          piGotResponse[i] = 1;
          iFoundFlag = i+1;;
          iRecievedRequests ++;
     }


     iFoundFlag--;

    /*
    ** Get the pointer to the first security fields into p.  The field_ptr array will
    ** have the pointers to the fields for each security in the order we 
    ** requested them.  For each security, we will get null-terminated 
    ** strings with the field data, one after another in the order we 
    ** requested the fields.
    */

     for (i=0; i<f->comm_header.num_items; i++) {
          pcSecName = pcSecList + iFoundFlag*piNumOfSecInOneReq[0]*32 + i*32; 
          printf(" %s", pcSecName);
          p = f->field_ptr[i];

          for (n=0; n<iNumOfFields; n++) {
               lp = strlen(p)+1;
               if (is_Bulk_field(piFieldList[n])) {
                    printf (":\t 0x%X  Bulk Data:\t", piFieldList[n]);
                    decodeBulkData (p);
               }
               else {
                    printf (":\t \t%s\t", p);
               }
               p += lp;
          }


     }

     fflush(stdout);

     if (iRecievedRequests == iNumOfRequests) {
      end=0;
      return 1;
     }
     else
       return 0;

}

 
Reply
   
Quote
   
Top
   
Bottom
     



DominicConnor
Senior Member

Posts: 10695
Joined: Jul 2002

Fri Jul 06, 07 10:10 AM
User is offline View users profile

I don't have BB any more, which is both good and bad...
Consider the case where the Search_req gives back -1 which as I recall is some sort of failure
(As it happens I use BB's method as an example in the CQF C++ module as how not to do error handling.


So our -1 doesn't cause iFoundFlag to go up in vlaue, this around the if ( i== -1) block
iFoundFlag
gets the value 0
gets the value -1

You get the security name by using the pSecList and doing pointer arithemetic, but iFoundFlag is -1 so I believe that when you multiply
-1 * piNumOfSecInOneReq[0] you sometimes go into whatever data happens to be stored "below" the pSecList


-------------------------
Discussion on the new regulations on bonuses here.
 
Reply
   
Quote
   
Top
   
Bottom
     



carfield
Junior Member

Posts: 6
Joined: Jul 2007

Tue Jul 10, 07 03:58 AM
User is offline

Thanks a lot. Look like it is the problem, however, in normal case there should not be return -1, only if the binary search function cannot find security in the array, which is also an exception cases without reason, will you have any idea about that?

Have attached the implementation of the search_req_id, and the array hold the pointer return from bb_getdatax or bb_getdata, do you think it is more likely that the allocation of memory of the array have problem?


long search_req_id(long * lReqIDArray, long lNumOfElem, long lReqID) {
     long l=0;
     long r=lNumOfElem;
     long x=0;
     fprintf(stderr, "lNumOfElem=%i, lReqID=%i \n", lNumOfElem, lReqID);
     if (lReqID == BB_VAL_MISSING) {
          fprintf(stderr, "Returning -1: BB_VAL_MISSING \n");
          return -1;
     }
     
     while (r>=0) {
     
          x = (l+r)/2;
          if (lReqID == lReqIDArray[x]) {
               return x;
          }

          if (lReqID < lReqIDArray[x]) {
               r = x-1;
          }
          else {
               l = x+1;
          }

     }
     fprintf(stderr, "Returning -1: ReqID not found, lReqID=%i \n", lReqID);
     return -1;
}

 
Reply
   
Quote
   
Top
   
Bottom
     



DominicConnor
Senior Member

Posts: 10695
Joined: Jul 2002

Tue Jul 10, 07 10:58 AM
User is offline View users profile

A surprisingly high % of packets get mangled, not enough to trash communication, but more than you would think.

I can't rule out memory allocation, but it does not feel like it.
In my experince once you start getting memory allocation problems, it only ever gets worse.
But you report sporadic errors, which to me implies the "input" is occasionally flaky.


-------------------------
Discussion on the new regulations on bonuses here.
 
Reply
   
Quote
   
Top
   
Bottom
     



DominicConnor
Senior Member

Posts: 10695
Joined: Jul 2002

Tue Jul 10, 07 10:58 AM
User is offline View users profile

A surprisingly high % of packets get mangled, not enough to trash communication, but more than you would think.

I can't rule out memory allocation, but it does not feel like it.
In my experince once you start getting memory allocation problems, it only ever gets worse.
But you report sporadic errors, which to me implies the "input" is occasionally flaky.


-------------------------
Discussion on the new regulations on bonuses here.
 
Reply
   
Quote
   
Top
   
Bottom
     



carfield
Junior Member

Posts: 6
Joined: Jul 2007

Tue Jul 10, 07 03:55 PM
User is offline

Thanks a lot.

I guess so, too bad it is not easy to found out the cause of this, will you have any hint for me to debug in this situation?
 
Reply
   
Quote
   
Top
   
Bottom
     



carfield
Junior Member

Posts: 6
Joined: Jul 2007

Mon Jul 30, 07 09:26 AM
User is offline

Finally we've found out the root cause of getting unexpected characters, when we get the result from bloomberg API bb_getdatax() , it will return the requestID; , once we get the response from bloomberg using bb_rcvdata (connection, pBuffer, lBufSize) , pBuffer is a struct containing the requestID (pBuffer->comm_header.request_id) and it suppose to be match. However, when response timeout, request ID from bb_getdatax() will difference from requestID from pBuffer->comm_header.request_id .

See if this information useful to anyone
 
Reply
   
Quote
   
Top
   
Bottom
     



jackkanaska
Junior Member

Posts: 12
Joined: Nov 2007

Mon Nov 26, 07 08:48 PM
User is offline

Hi,

Sorry to bring this thread back out but I was hoping you could share a bit of your code for making requests for historical data and decoding properly. I am new to BB and I'm having problems finding good documentation. Basically I want to do the same as your example, get a number of historical data fields for a list of securities.

Thanks in advance.

Cheers,
Jack
 
Reply
   
Quote
   
Top
   
Bottom
     



carfield
Junior Member

Posts: 6
Joined: Jul 2007

Tue Nov 27, 07 05:20 PM
User is offline

It is just the example5.c which someone post at http://www.experts-exchange.com/Programming/Languages/C/Q_22679606.html

What I've do is:
1) patch [void main( int argc, char **argv)] so that [make_request()] and [response_loop()] run in a loop with same connection
2) feed input in STDIN can call [parse_com_line()] within the loop with suitable parameter ( according to bloomberg, VWAP start day and VWAP end day should not be used; we should use VWAP day )
3) prevent the index mismatch accord to this post mentioned.
 
Reply
   
Quote
   
Top
   
Bottom
     



jackkanaska
Junior Member

Posts: 12
Joined: Nov 2007

Thu Nov 29, 07 05:52 PM
User is offline

Thanks carfield. I actually have the BB API installed and I remember seeing example 5. I just didn't know that one was an example of downloading historical data.
I will let you know how it goes.
Thanks!
Jack

Edited: Thu Nov 29, 07 at 05:52 PM by jackkanaska
 
Reply
   
Quote
   
Top
   
Bottom
     



jackkanaska
Junior Member

Posts: 12
Joined: Nov 2007

Fri Nov 30, 07 07:21 PM
User is offline

Hi,

Ok, so I've had a look at example 5 .... doesn't look too bad.

One question though -- how can I specify the date range and periocity for a historical request? For example, say I want the PE Ratio and EPS for a list of stock from 1990 - 2006, using monthly periocity. I have looked in the bbfields.tbl and I have found the codes (hex) for the 2 fields (PE_RATIO and IS_EPS), but I'm not sure how to specify the date range and periocity.

Thanks again,
Jack
 
Reply
   
Quote
   
Top
   
Bottom
     



carfield
Junior Member

Posts: 6
Joined: Jul 2007

Sat Dec 01, 07 07:36 AM
User is offline

There is a excel addin install with Bloomberg client, I usually use that addin to test various parameters effect. The addin can be access via the menubar: "Bloomberg" -> "previous menu" -> "table wizard"
 
Reply
   
Quote
   
Top
   
Bottom
     

View thread in raw text format
FORUMS > Programming and Software Forum < refresh >

Forum Navigation:

© All material, including contents and design, copyright Wilmott Electronic Media Limited - FuseTalk 4.01 © 1999-2010 FuseTalk Inc.