summaryrefslogtreecommitdiffstats
path: root/gold/mtgox/mtgox.ticker
blob: 208d276434ee4e3bfce32f4b35a667796902c45f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /bin/sh
# 2012-06-07 ~tv@iiso:bin/mtgox.ticker
set -euf

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://data.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 "$@"