Skip to content

Commit

Permalink
add candleUploader plugin (askmike#2700)
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike authored Jan 7, 2019
1 parent 6546d5d commit 5444502
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,18 @@ var plugins = [
async: false,
modes: ['realtime'],
greedy: true
}
},
{
name: 'Candle Uploader',
description: 'Upload realtime market candles to an external server',
slug: 'candleUploader',
async: true,
modes: ['realtime'],
dependencies: [{
module: 'axios',
version: '0.18.0'
}]
},
];

module.exports = plugins;
35 changes: 35 additions & 0 deletions plugins/candleUploader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const axios = require('axios');
const _ = require('lodash');
const log = require('../core/log.js');
const util = require('../core/util.js');
const config = util.getConfig();

const CandleUploader = function(done) {
_.bindAll(this);
done();
};

CandleUploader.prototype.processCandle = function(candle, done) {
console.log(new Date, 'uploading', candle);
axios({
url: config.candleUploader.url,
method: 'post',
data: {
apiKey: config.candleUploader.apiKey,
watch: config.watch,
candles: [ candle ]
}
})
.then(r => {
if(r.data.success === false) {
console.log('error uploading:', r.data);
}
})
.catch(e => {
console.log('error uploading:', e.message);
});

done();
};

module.exports = CandleUploader;

0 comments on commit 5444502

Please sign in to comment.