fetch google finance data - stocks

can anyone provide me an example on how I can fetch the real-time stocks of google finance

Came across this (and your post) trying to figure this out myself...
This currently retrieves some XML:
http://www.google.com/ig/api?stock=F
Of course they may close this down as well soon...
I think 'last data=' will give current quote
EDIT:
The api is now completely shutdown and no longer works. An alternative to 'api' for a 'realtime' quote would be:
http://finance.google.com/finance/info?client=ig&q=NYSE:F

As for now (2015), the google finance api is deprecated. If you are comfortable with python, you may use the pypi module googlefinance.
Install googlefinance
$pip install googlefinance
It is easy to get current stock price:
>>> from googlefinance import getQuotes
>>> import json
>>> print json.dumps(getQuotes('AAPL'), indent=2)
[
{
"Index": "NASDAQ",
"LastTradeWithCurrency": "129.09",
"LastTradeDateTime": "2015-03-02T16:04:29Z",
"LastTradePrice": "129.09",
"Yield": "1.46",
"LastTradeTime": "4:04PM EST",
"LastTradeDateTimeLong": "Mar 2, 4:04PM EST",
"Dividend": "0.47",
"StockSymbol": "AAPL",
"ID": "22144"
}
]
Google finance is a source that provides real-time stock data. There are also other APIs from yahoo, such as yahoo-finance, but they are delayed by 15min for NYSE and NASDAQ stocks.

I've been struggling with trying to find a lifetime free access for this data for some time as well, but today I came across Alpha Vantage (https://www.alphavantage.co) and used their data to build an Annotated Timeline from Google Charts.
All you need is to request an API Key (which you get at the moment you fill in their form) and follow their Documentation.
An example of getting a JSON output in PHP:
$url = file_get_contents('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&outputsize=full&symbol=AAPL&apikey='.$apiKey);
$decoded = json_decode($url, true);

Here's a very simple example: http://googlified.com/files/finance-api.html

The link in the earlier answer was broken when I tried it, so here is another example. You have to do a bit of processing but otherwise it's pretty easy.
http://www.google.com/finance/info?client=ig&q=goog,msft

Related

Where do I enter moment.js code so a DataTables column appears in my chosen format?

I want to make data like 2022/12/15 (imported from Google Sheets at the moment of page load) display as "Dec 15" in one column, and as "Thu" in another column.
I found the format codes:
moment().format("MMM d"); // "Dec 15" and
moment().format("ddd"); // "Thu".
I read https://momentjs.com/docs/ and https://momentjs.com/guides/, but could not find:
Where do I enter that code?
Can I skip entering that code, and instead just enter this?:
$(document).ready(function () {
$('#example').DataTable({
columnDefs: [
{
targets: 4,
render: DataTable.render.datetime('MMM d'),
},
],
});
});
Perhaps I should separate my questions into different posted questions, but I imagine it will be more helpful for future readers to find the combined challenges asked and answered in a single thread.
I'm using the WordPress plugin "Inline Google Spreadsheet Viewer", which is built on DataTables.
[Edit: I realized I should not paste that code into inline_gdocs_viewer.php, and intended to paste it into igsv-datatables.js. I could not however figure out where to paste within that file. What should I look for to know where to insert it? (The author of that plugin publicly announced that no more support will be given.) Should I post the contents of the js file somewhere so you can see it?]
[Edit 2: Would entering that code make column 5 always displayed in MMM d format, even if I want column 5 to be displayed in a different format? Shouldn't specifying what format to apply to which column happen when I create a page / post and use the shortcode to embed the spreadsheet?]
(I read the plugin's documentation and I read DataTables documentation.)
If my table doesn't have a name, what do I use instead of #example? Do I need to name my table? If so, how? (I tried to find the answer at, for example, https://www.w3schools.com/html/html_tables.asp.)
The source for the longer code came from a live example where the dates were in column 5, but the code says "targets:4". To apply the code to column 3 (for example), should I enter targets:2? I read https://datatables.net/reference/option/columns.render, but bizarrely that didn't address this basic question.
If you're wondering if I upgraded DataTables from the old version that comes with Inline Google Spreadsheet Viewer, yes I did.
If you're wondering if I got the script array to call moment.js, I might have. Into the scripts array I added
,
'moment' => array(
'src' => plugins_url('moment.min.js', __FIL__),
'deps' => array( 'moment' )
)
I'm not sure about the "deps" part. Does it mean dependencies? Was I right to use "moment" twice in that code?
If you only know a possible answer to one of these questions, that's better than nothing, so please do share what you can.
I know the Moment team recommends you choose a different library than Moment for new projects, but DataTables to this day recommends Moment for sorting by Day of the week or sorting by Date.
Thanks
Using moment.js 2.29.2 and DataTables 1.13.1.
What I tried, and what I expected:
I read the documentation for all the programs, and I read forum discussions for all the programs, and I studied examples, expecting to find where to enter the code, but nowhere could I find what to do with it. It was always assumed that that part was already known.

How to listen to Tweets that only contains geo-info from Twitter stream

I'm trying to use version 2 of the Twitter API to achieve the goal described in the title. Here's what I have tried so far:
Listening to sample stream (1% of Twitter's stream): Almost all the returned Tweets don't have geo-info when following this approach. And it makes sense, since only 0.85% of all Tweets have geo-info.
Listening to a filtered stream with only one rule setup, namely the has:geo rule. But it's returning the following 2 errors:
"Reference to invalid operator 'has:geo'. Operator is not available in current product or product packaging. Please refer to complete available operator list at https://developer.twitter.com/en/docs/twitter-api/enterprise/rules-and-filtering/operators-by-product. (at position 5)".
"has/is/lang/sample cannot be used as a standalone operator (at position 1)".
Here's the rule I'm adding to the stream:
[
{
"value": "has:geo",
"tag": "contains geo-info",
},
]
I need help in solving both shown errors, or a suggestion describing a third different approach.
I see this question has been discussed on the Twitter Community forum: https://twittercommunity.com/t/how-to-listen-to-tweets-that-only-contains-geo-info-from-twitter-stream/162905/2
Short answer:
The has:geois one of several query operators that can not be used in a standalone fashion, and must be paired with keywords and other non-boolean operators.
The has:geo operator is only available in academic and paid packages.

#BFxForward() in the Bloomberg python api

I've used https://github.com/691175002/BLPInterface as a wrapper to the terribly-documented (and non-supported by Bloomberg Help) Bloomberg python API. I use it to pull price histories, etc.
Lately I've needed to pull specific FX date values. In excel I do that as =#BFxForward("usdjpy",J10, "BidOutright") where J10 is a date.
I would like to pull this information via the Bloomberg Python API (or even better, with the BLPInterace wrapper) but it's not clear how to do it. I've seen someone ask a similar question for a .Net implementation, but the only answer cited page 207 of a developers guide. Every developer guide I can find on bloomberg is well less than 200 pages, and none of it mentions pulling fx values.
Wondering if anyone can point me at some examples or resources to build on to get this ?
It does take some finding, to be sure, but I tracked it down via the Bloomi Terminal. The way I found the information is as follows (for future reference):
Type DAPI in the Bloomberg Terminal
Choose 'Additional Resources' in the left hand panel
Choose 'Help Page for DAPI' in the right hand panel, and a window pops up
Choose 'Constructing Formulas' in the left hand panel
Choose 'FX Broken Dates Forwards Syntax' in the right hand panel
Or paste this link into Bloomi:
{LPHP DAPI:0:1 2277846 }
There are a lot of different examples and options (FX fwds are not my area of expertise), but simply using this format for the ticker seems to work:
ccy1/ccy2 mm/dd/yy Curncy
and then the field PX_BID. You can try this in a BDP call in Excel, for example:
=BDP("EUR/GBP 08/08/22 Curncy","PX_BID")
When it comes to Python, perhaps try using the xbbg python package (other wrappers are available): it does a good job of hiding all the intricacies of the low-level API.
Here's a code sample using xbbg, that pulls back the forward fx rate in the example:
from xbbg import blp
from datetime import datetime
ccy1 = 'EUR'
ccy2 = 'GBP'
fwdDate = datetime(2022,8,8)
ticker = '{0:}/{1:} {2:} Curncy'.format(ccy1,ccy2,fwdDate.strftime('%m/%d/%y'))
df = blp.bdp(ticker,'PX_BID')
print(df)
Output:
px_bid
EUR/GBP 08/08/22 Curncy 0.85344
EDIT: Looking at the OP's choice of Bloomi wrapper, the xbbg call could possibly be replaced by:
blp.referenceRequest(ticker, 'PX_BID')

How to store data from Google Ngram API?

I need to store the data presented in the graphs on the Google Ngram website. For example, I want to store the occurences of "it's" as a percentage from 1800-2008, as presented in the following link: https://books.google.com/ngrams/graph?content=it%27s&year_start=1800&year_end=2008&corpus=0&smoothing=3&share=&direct_url=t1%3B%2Cit%27s%3B%2Cc0.
The data I want is the data you're able to scroll over on the graph. How can I extract this for about 140 different terms (e.g. "it's", "they're", "she's", etc.)?
econpy wrote a nice little module in Python that you can use through a command-line interface.
For your "it's" example, you would need to type this command in a terminal / windows console:
python getngrams.py it's -startYear=1800 -endYear=2008 -corpus=eng_2009 -smoothing=3
This will automatically save the query result in a CSV file named after your query parameters.
econpy's package, in #HugoMailhot's answer, no longer works (2021) and seems not maintained.
Here's a updated version, with some improvements for easier integration into Python code:
https://gitlab.com/cpbl/google-ngrams
You can call this from the command line (as in econpy's) to create a CSV file, e.g.
getngrams.py it's -startYear=1800 -endYear=2008 -corpus=eng_2009 -smoothing=3
or call it from python to get (and plot) data directly in python, e.g.:
from getngrams import ngrams
df = ngrams('bells and whistles -startYear=1900 -endYear=2018 -smoothing=2')
df.plot()
The xkcd functionality is still there too.
(Issues / bug fix pull requests /etc welcome there)

REST API modeling

I got two models, a Notebook and a Note one.
I got two routes than can achieve the same (post a note for a specific notebook)
POST /api/note , need to pass notebook ref (id) in the submited datas
POST /api/notebook/[ID]/note , with now now only the note data
Note that I don't need "notes that would not be attached to a notebook".
I read many docs about REST APIs, but I can figured out what's the "best" way.
Does anybody here have some good docs for me?
I assume that a note can only exist in one and only one notebook. Then a note is a subresoure of a notebook. A note is identifed by
/api/notebook/{notebookId}/note/{noteId}
A new note inside a notebook is created by
POST /api/notebook/1234/note
Content-Type: application/json
{
// details of the note without reference to the notebook
}
The server returns
201 Created
Location: /api/notebook/1234/note/B175A7F2-1434-11E5-AFD4-82854B860EDE
with B175A7F2-1434-11E5-AFD4-82854B860EDE being a unique ID assigned to the new note by the server.