SIGN IN SIGN UP
askmike / gekko UNCLAIMED

A bitcoin trading bot written in node - https://gekko.wizb.it/

0 0 1 JavaScript
2017-07-05 00:19:53 +01:00
const fs = require('fs');
const _ = require('lodash');
const cache = require('./state/cache');
const broadcast = cache.get('broadcast');
2017-07-05 00:19:53 +01:00
2017-07-23 21:41:24 +01:00
const apiKeysFile = __dirname + '/../SECRET-api-keys.json';
2017-07-05 00:19:53 +01:00
// on init:
const noApiKeysFile = !fs.existsSync(apiKeysFile);
2017-07-23 21:41:24 +01:00
if(noApiKeysFile)
fs.writeFileSync(
apiKeysFile,
JSON.stringify({})
);
2017-07-05 00:19:53 +01:00
2017-07-23 21:41:24 +01:00
const apiKeys = JSON.parse( fs.readFileSync(apiKeysFile, 'utf8') );
2017-07-05 00:19:53 +01:00
module.exports = {
get: () => _.keys(apiKeys),
// note: overwrites if exists
add: (exchange, props) => {
apiKeys[exchange] = props;
2017-07-23 21:41:24 +01:00
fs.writeFileSync(apiKeysFile, JSON.stringify(apiKeys));
broadcast({
2017-07-05 19:19:23 +01:00
type: 'apiKeys',
exchanges: _.keys(apiKeys)
});
},
2017-07-06 18:47:35 +01:00
remove: exchange => {
if(!apiKeys[exchange])
return;
2017-07-06 18:47:35 +01:00
delete apiKeys[exchange];
2017-07-23 21:41:24 +01:00
fs.writeFileSync(apiKeysFile, JSON.stringify(apiKeys));
2017-07-06 18:47:35 +01:00
broadcast({
type: 'apiKeys',
exchanges: _.keys(apiKeys)
});
},
// retrieve api keys
// this cannot touch the frontend for security reaons.
_getApiKeyPair: key => apiKeys[key]
}