This repository has been archived by the owner on Feb 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow sending of start-up and trade advice to Kodi and derivatives#
- Loading branch information
1 parent
21961aa
commit 085af56
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Created by billymcintosh on 24/12/17. | ||
*/ | ||
|
||
var _ = require('lodash'); | ||
var request = require('request'); | ||
var log = require('../core/log.js'); | ||
var util = require('../core/util.js'); | ||
var config = util.getConfig(); | ||
var kodiConfig = config.kodi; | ||
|
||
var Kodi = function(done) { | ||
_.bindAll(this); | ||
|
||
this.exchange = config.watch.exchange.charAt().toUpperCase() + config.watch.exchange.slice(1) | ||
|
||
this.price = 'N/A'; | ||
this.done = done; | ||
this.setup(); | ||
}; | ||
|
||
Kodi.prototype.setup = function(done) { | ||
var setupKodi = function (err, result) { | ||
if(kodiConfig.sendMessageOnStart) { | ||
var currency = config.watch.currency; | ||
var asset = config.watch.asset; | ||
var title = "Gekko Started"; | ||
var message = `Watching ${this.exchange} - ${currency}/${asset}`; | ||
this.mail(title, message); | ||
} else { | ||
log.debug('Skipping Send message on startup') | ||
} | ||
} | ||
setupKodi.call(this) | ||
}; | ||
|
||
Kodi.prototype.processCandle = function(candle, done) { | ||
this.price = candle.close; | ||
|
||
done(); | ||
}; | ||
|
||
Kodi.prototype.processAdvice = function(advice) { | ||
var title = `Gekko: Going ${advice.recommendation} @ ${this.price}` | ||
var message = `${this.exchange} ${config.watch.currency}/${config.watch.asset}`; | ||
this.mail(title, message); | ||
}; | ||
|
||
Kodi.prototype.mail = function(title, message, done) { | ||
var options = { | ||
body: `{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"${title}","message":"${message}"},"id":1}`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
method: 'POST', | ||
url: kodiConfig.host | ||
} | ||
|
||
request(options, (error, response, body) => { | ||
if (!error) { | ||
log.info('Kodi message sent') | ||
} else { | ||
log.debug(`Kodi ${error}`) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = Kodi; |
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