stockapi.api.php is one of the root file of the stockapi module. By the documentation in the code, I understand that, this file provide a custom hook that can be used by other modules which require this module as a dependency. I want to ensure that my understanding is correct and if its correct, could anyone please tell what kind of data is transmitted through this hook and how this can be used with other module and for what use ?
Code for stockapi.api.php file is :
<?php
/**
* @file
* Stock API module API file.
*/
/**
* Alter Google Finance query.
*
* @param string $path
* Google finance host URL, i.e. 'https://finance.google.com/' or
* 'https://finance.google.ca/'.
*
* You may want to change it sometimes since Finance may return different data
* for different domains.
* @param array $options
* Array or URL options, as passed to url().
* @param string $stock_market
* Stock market name, i.e. 'NASDAQ' or 'TSE'.
* @param string $stock_symbol
* Stock symbol.
*
* @see stockapi_google_finance_url()
* @see url()
*/
function hook_stockapi_google_finance_query_alter(&$path, &$options, $stock_market, $stock_symbol) {
if ($stock_symbol == 'GOOG') {
$path = 'https://finance.google.com/';
// Omit stock market because why not, that's why.
$options['q'] = $stock_symbol;
}
}
/**
* React on Stock API data update.
*
* Third-party modules may utilize this hook to clear own caches or process
* own data.
* Example usages: 1) Use in a custom module to store stocks data in a JSON
* file so that you can load with JavaScript code on a fully cached site.
* 2) Comparing and logging values.
*
* @param array $symbols
* Stock symbols, as returned by stockapi_fetch().
*
* @see stockapi_fetch()
*/
function hook_stockapi_post_update(array $symbols) {
foreach ($symbols as $key => $stock) {
// Process own data here.
}
}
Comments
Comment #2
mohit1604 commentedComment #3
mohit1604 commentedComment #4
mohit1604 commentedComment #5
mohit1604 commentedComment #6
joseph.olstadLook at the git blame for that, check who is the author.
Btw, we may want to revert most of the work I did since 2017, I discovered that the yahoo finance still provides this service for free but the api interface changed, just have to refactor that.
Previously the data from yahoo came in csv format but now I am not sure exactly the api format , probably json like everyone else.
Yahoo finance has much more detail and better quality than the other api I switched to.
Comment #7
joseph.olstadThese are custom hooks which do not work anymore unless we revert to 2016 code and refactor stockapi for the new yahoo finance api.
Comment #8
joseph.olstadPlease google on "defining custom hooks in a drupal module site:drupal.org"
Should give you some good information