Several Updates to the JSON API

Fri 17 July 2009

I made a few changes to the card price JSON API today and wanted to outline them here. I added all statistics that are available from Magic Trader's pricelists to the interface, which include price, high, low, change, average, and volume (which is called "raw number" in Magic Trader's lists). I calculate the percent change, so I have also made that available.

[{"volume":13,"percent_change":"0.00","name":"Lightning Bolt","url":"","price":"8.66","high":"15.00","low":"0.01","set_code":"LEB","average":"8.40","change":"0.00"}]

The up attribute, which was a convenience value I added for the price ticker, is gone. I found strings can easily be coerced to numbers in JavaScript by simply multiplying by 1. "15.99" * 1 = 15.99

The volume attribute is a number, but all other number values will remain strings. Rather than dealing with rounding issues, the numbers will remain stringified. Just multiply by 1 if you want to compare any of the values as a number. prices[0]["change"] * 1 >= 0 will tell you whether the card went up in price today.

Price Ticker Updates

After learning how jQuery handles JSONP, I fixed the API so it can safely create as many price tickers on a single page as you like. Previously, tickers were using the same global method named jsonp, which essentially caused a race condition when putting multiple tickers on a single page. Like jQuery, each ticker now uses a unique identifier to insure tickers don't clash on their JSONP function names.