The attach patch allow to fetch multiple stock info with one query.

You would call the function with the following format:

$result = stockapi_fetch('STOCK_A+STOCK_B');

Keeps backwards compatibility.

Comments

flaviovs’s picture

StatusFileSize
new1.88 KB

I've just found the attached patch which is in use on my production site for many years. It takes a different approach: a new API stockapi_fetch_many() allows one to fetch many symbol passing a array of symbols. Of course, it' s also backward compatible because it doesn't change the existing API. The function do just one HTTP request to the Yahoo! finance service to fetch all symbols, so it' s pretty efficient.

The patch also change stockapi_cron() to use the new API. One cron run, one Yahoo! request, no matter how many symbols you need to fetch.

TODO: use drupal_http_request() instead of using "fopen()" to to the HTTP request, as many users run with "allow_url_fopen" disabled.

melissamwong’s picture

Hello, can you explain how to apply this patch successfully? Thank-you for providing this.

flaviovs’s picture

melissamwong’s picture

Thanks Flaviovs!!!!!

izmeez’s picture

Can anyone comment on their experience with these two patches? Thanks.

izmeez’s picture

I have applied the patch in comment #1. It applies with -p0

Is there anything more that is needed or is the module now doing fetch multiple as single request to yahoo?

fp’s picture

@izmeez: have you tried it?

izmeez’s picture

Yes. I applied the patch to the module and am using the module.

Everything looks fine and seems to be working. I just don't know if there is an easy way to tell if the patch is active and only a single call to yahoo is being made. Maybe the server logs will need to be examined?

fp’s picture

Is the code you are using to fetch the stocks making use of this new stockapi_fetch_many() function? If so, it should work (check the output) if not then, it won't! :)

izmeez’s picture

Looking at the code, it appears to be using the stockapi_fetch_many() function. The output of the stock module is correct. I just wasn't sure if there is someway to examine the calls to yahoo. I think I will have to look at server logs, unless there is another way. Maybe with devel module?

fp’s picture

You can add something like this to the code:

$data = stockapi_fetch_many($x, $y);
var_dump($data); 

This will allow you to see what is returned by the stockapi_fetch_many() function.

joseph.olstad’s picture

Issue summary: View changes

Please upgrade to 7.x-2.x

joseph.olstad’s picture

Status: Needs review » Closed (outdated)