Recipies

The following is a number of interesting / useful solutions to problems, or recipes, written in Moya code.

Get the price of Bitcoin

The following one liner will retrieve the current price of Bitcoin (in USD) from https://www.bitstamp.net:

<echo>${(fromjson:get:"https://www.bitstamp.net/api/ticker/")['ask']}</echo>

How does this work? Well, the URL https://www.bitstamp.net/api/ticker/ contains a JSON object with the current Bitcoin prices. The get: modifier reads that request from the internet, and the fromjson: modifier converts the text in to a dictionary with a number of values. Finally the index operator ['ask'] looks up the value of 'ask' which is the current asking price.

NOTE This recipe depends on the the bitstamp api. We can't guarantee that will still be working, but we would be surprised if isn't.