Skip to content

Instantly share code, notes, and snippets.

@stianeikeland
Last active December 29, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stianeikeland/7667441 to your computer and use it in GitHub Desktop.
Save stianeikeland/7667441 to your computer and use it in GitHub Desktop.
Gox = require 'goxstream'
JSONStream = require 'json-stream'
Boxcar = require 'boxcar'
osxnotify = require 'osx-notifier'
log = require 'npmlog'
argv = (require 'optimist')
.usage('Usage: $0')
.alias('h', 'high')
.alias('l', 'low')
.alias('s', 'step')
.describe('l', 'low value')
.describe('h', 'high value')
.describe('s', 'step up/down')
.default('s', 10)
.demand(['h','l'])
.argv
boxcar = new Boxcar.Provider 'xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy'
jsonstream = new JSONStream()
gox = Gox.createStream()
high = parseFloat(argv.high)
low = parseFloat(argv.low)
step = parseInt(argv.step)
log.info "Watching for high: #{high}, low: #{low}."
gox.pipe jsonstream
notify = (message) ->
osxnotify {
type: 'info'
title: 'MtGox bitcoin'
message: message
group: 'bitcoin'
}
boxcar.broadcast message
log.info 'notify', message
jsonstream.on 'data', (data) ->
log.info 'ticker', data.ticker.last.value
btcvalue = parseFloat(data.ticker.last.value)
shutdown = false
if btcvalue > high
notify "Bitcoin > $#{high} => $#{btcvalue}"
high = high + step
if btcvalue < low
notify "Bitcoin < $#{low} => $#{btcvalue}"
low = low - step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment