diff options
author | tv <tv@nomic.retiolum> | 2013-01-30 15:33:02 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-01-30 15:33:02 +0100 |
commit | 9461f6ece9f674588327c6dc3199fc0d7618ac48 (patch) | |
tree | a05fa4ab25cfd21d67c38356477a589f01be6880 | |
parent | ed52b2a311e2ed2a61f382de217c2fee95a51fc5 (diff) |
//gold mtgox.ticker: import tv@iiso's legacy
-rwxr-xr-x | gold/mtgox/mtgox.ticker | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/gold/mtgox/mtgox.ticker b/gold/mtgox/mtgox.ticker index b24dfb35..32ee53bf 100755 --- a/gold/mtgox/mtgox.ticker +++ b/gold/mtgox/mtgox.ticker @@ -1,4 +1,53 @@ #! /bin/sh -# get mtgox ticker data +# 2012-06-07 ~tv@iiso:bin/mtgox.ticker set -euf -curl -ksS https://mtgox.com/code/data/ticker.php + +Currency=${Currency-EUR} + +# continuous ticker +## usage: mtgox.ticker -f [time] [json-path...] +if test $# -ge 1 && test "$1" = -f; then + shift + time=`echo "$1" | grep '^[1-9][0-9]*[h]\?$'` && shift || time=60 + echo -n "# sleep time: $time" + while echo -n " +`date --rfc-3339=s` `"$0" "$@"`"; do + sleep $time + done + exit +fi + +# 2012-11-17 tv /krebs/gold/mtgox/mtgox.ticker +ticker() { + curl -ksS https://mtgox.com/code/data/ticker.php?Currency=$Currency +} +# 2012-11-17 tv ~mw*@iiso:Espresso-phonegap/package/bin/json-print +print() { + node -e " +// 2012-11-17 tv +//filename = process.argv[2] +filename = process.argv[1] +jsonpath = [] +value = JSON.parse(require('fs').readFileSync(filename)) +// 2012-11-17 tv +//process.argv.slice(3).forEach(function (key) { +process.argv.slice(2).forEach(function (key) { + value = value[key] + jsonpath.push(key) + if (typeof value === 'undefined') { + console.error(filename + ':', jsonpath.join('.'), 'is', value) + process.exit(23) + } +}) + +console.log(JSON.stringify(value, null, 2)) +" "$@" +} + +# ticker +## usage: mtgox.ticker [json-path...] -> json +# 2012-11-17 tv +#/krebs/gold/mtgox/mtgox.ticker | +# ~mw*@iiso:Espresso-phonegap/package/bin/json-print /dev/stdin ticker "$@" +ticker | + print /dev/stdin ticker "$@" |