The Chicken Coop Development, with chickens. Because chickens are cool. (aka Nic Wise's blog)

Google App Engine – used in anger (finally)

I’ve been keeping an eye on the Google App Engine (GAE) for quite a while now. I love the idea of it – easy to develop on, all of most of the API is provided for you, and it runs on rather well-proven hardware. They have changed the terms a few times, and as a result, a lot of the initial issues with it – eg if you load it up too much – are gone or being delt with.

I’ve finally had a reason to use it in anger – well, mostly in happiness, but hey, I didn’t invent the term.

My application is a small one. A very small one, it turned out. I’ve been doing some options trading over the past 3 months, and even tho I shouldn’t, I like to keep an eye on both the stock indexes (S&P 500, NASDAQ, DOW) and any stocks I have options on. Ok, I admit it, I’m a data whore :). But getting that information while I’m out and about it tricky.

Most of the iPhone apps use delayed stock information – Bloomberg is a good example, as is the built in Stocks app, which feeds from Yahoo!. All of them are delayed at least 10 minutes, usually 20, which isn’t a lot of use to me.

Google is one of the few companies out there which provide real-time (or close to it) stock data to the public for free, but up until recently, they didn’t have an API to allow anyone to consume this information – it was only for use on Google Finance. I used Google Finance for a while, but the load time on the iPhone, over GRPS usually, was just too slow.

android_ss_portfolios

No, this is NOT my app. Did I mention I can’t do layout as good as this?

With the launch of the Google Finance Android app, Google have released (tho I’m guessing not officially) some of the API. You can now (officially) get to your portfolio and other information from Google Finance, and with a little searching around, there is a nice end point to get the actual stock price in JSON format (unofficially I guess).

http://finance.google.com/finance/info?q=GOOG

[ {
"id": "694653" ,
"t" : "GOOG" ,
"e" : "NASDAQ" ,
"l" : "324.42" ,
"l_cur" : "324.42" ,
"ltt":"4:00PM EDT" ,
"lt" : "Mar 13, 4:00PM EDT" ,
"c" : "+0.89" ,
"cp" : "0.28" ,
"ccol" : "chg" ,
"el": "325.50" ,
"el_cur": "325.50" ,
"elt" : "Mar 13, 7:32PM EDT" ,
"ec" : "+1.08" ,
"ecp" : "0.33" ,
"eccol" : "chg"
} ]

This is more than enough data for what I need – I can get the stock ticker (GOOG), the last price (323.42), when it happened, the change and change as a percentage and any after hours trading info (ec, ecp, el etc). Perfect.

So here’s the little app I made using this. It doesn’t do a lot, but I don’t need it to, and due to me screwing up the initial setup, some of the features are only available if you have a @fastchicken.co.nz address (ie, Leonie and I), but it:

If you are not logged in, you just get the DOW, S&P and NASDAQ.

The code is pretty simple. I have three “controllers” – one for the index, and one each for adding and removing a set of stocks. All the user management is handled by Google App Engine, so I dont need to do any of the usual stuff like:

Getting the url to do the whole login workflow:

login_url = users.create_login_url(self.request.uri)
login_url_text = ‘Login’

Working out if a user is logged in, and getting the user’s object:

if users.get_current_user():
stocks_list = db.GqlQuery(“SELECT * FROM StockList WHERE owner = :1 order by category, ticker”, users.get_current_user())

All very simple. The add and remove ones are not much code. There is a small external class – StockModel – which when given a ticker, name and category, goes off and calls the Google Finance endpoint and populates it’s fields with the (real time) data it gets. All the calls are done with the built in urlfetch api and a python JSON library. Aside from the portfolio – which ones to show – there is no data kept, and even that is just a reference to the user, the ticker (MSFT etc) and and category (Call, Put, Index).

All up, while this is a very (very, very….) simple application, it does show some of the power of GAE if you play inside their sandbox, which I’m more than happy to do. Once they add some more things to it – scheduled background tasks come to mind – it’s definitely going to be a very viable platform for quick-to-develop, short-term applications. The integration into google accounts – especially into google apps for domains – is very nice. Not being able to change the security model from “my domain only” to “anyone with a google account” after I create the app is frustrating, but it’s easy to work around – I could just create a new app on GAE, but it’d be nice to just switch it, even if the database was trashed in the process.

The biggest issue I’ve had it finding the basic functions of the Python language. I have a copy of Learning Python (the Rat book), which is good, but not organised in a way I’d want – it has very little OO focus, and a lot on how the language works, and I’m just far enough beyond that for it to be a pain in the arse. Of course, there is good and the python docs, but a lot of the terms are different to other languages I’ve used lately – PHP and C# – so it gets a little confusing. Oh, well. It’ll come with time. Either that, or they will support Java (or C#, but I’d suspect Java comes first, as it’s an official Google language, along with C++)

The other issue is my total lack of CSS skills. I can do HTML and Javascript with a problem, but the nuances of CSS kick me, and I usually end up frustrated. Oh, well – that’ll come with time and some help from Gilles and the other CSS ninjas at work. It’s not something I’ve needed to learn, so I haven’t. It may be about time to start. Now’s good.

Next GAE project is in the works. I need to do something for Leonie to manage any properties which she is looking at, and the whole workflow and external links which go with that. Not sure when I’m going to get time – the app itself is trivial from a backend point of view, but as usual, the front end bits are painful….


4 Comments

Noice,

Yep CSS is definitely a must have in your toolkit nowadays. As is PHP ;).

Looking forward to the next one :D.

Posted by Andrew Baird on 15 March 2009 @ 9pm

great!

now when are you going to write that property analysis app you’ve been promising me for years?!

;)

Posted by leonie on 16 March 2009 @ 10pm

Yes dear :)

Posted by Nic on 17 March 2009 @ 6am

I thought that api was only available to google gadgets? I least that what it says in the group?

http://groups.google.com/group/google-finance-apis/browse_thread/thread/6ab861b5558e1890/f0a9be99deb1f66e#f0a9be99deb1f66e

Posted by John Turner on 18 March 2009 @ 8pm