Created
May 18, 2017 04:00
-
-
Save yappo/3837191390aadf22ba6d47f66e1fcf59 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
#!/usr/bin/env node | |
'use strict' | |
const NOTIFY_TOKEN = 'YOUR LINE NOTIFY TOKEN'; | |
const PubNub = require('pubnub'); | |
const pubnub = new PubNub({ | |
subscribeKey: 'sub-c-52a9ab50-291b-11e5-baaa-0619f8945a4f' | |
}); | |
const exec = require('child_process'); | |
let price_low = 1000000; | |
let price_high = 0; | |
const price_range = 1000; | |
let price_current_low = 1000000; | |
let price_current_high = 0; | |
const price_current_range = 5000; | |
let price_current = 0; | |
function send_log(log, price){ | |
console.log(log); | |
exec.exec("/usr/bin/curl -XPOST -H 'Authorization: Bearer " + NOTIFY_TOKEN + "' -F 'message=" + log + "' https://notify-api.line.me/api/notify", function(){}); | |
console.log([price_current, price, price_low, price_high, price_current_low, price_current_high].join(" ")); | |
} | |
pubnub.addListener({ | |
message: function (message) { | |
message.message.forEach(function(row){ | |
let price = row.price; | |
if (price < price_low - price_range) { | |
const log = 'Down BTC (recorded) ' + price + '(-' + (price_low - price) + ')'; | |
price_current = price; | |
price_low = price; | |
send_log(log, price); | |
} else if (price_high + price_range < price) { | |
const log = 'Up BTC (recorded) ' + price + '(+' + (price - price_high) + ')'; | |
price_current = price; | |
price_high = price; | |
send_log(log, price); | |
} | |
if (price < price_current_low) { | |
const log = 'Down BTC (current range) ' + price + '(-' + (price_current - price) + ')'; | |
price_current = price; | |
price_current_low = price - price_range; | |
price_current_high = price + price_range; | |
send_log(log, price); | |
} else if (price_current_high < price) { | |
const log = 'Up BTC (current range) ' + price + '(+' + (price - price_current) + ')'; | |
price_current = price; | |
price_current_low = price - price_range; | |
price_current_high = price + price_range; | |
send_log(log, price); | |
} | |
}); | |
} | |
}); | |
pubnub.subscribe({ | |
channels: [ | |
'lightning_executions_FX_BTC_JPY' | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment