Last active
December 29, 2015 11:59
-
-
Save stianeikeland/7667441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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