From 33cbcbff407db8d5306c07bb0b79387c9bb44a03 Mon Sep 17 00:00:00 2001 From: Guillaume Nomine Date: Fri, 19 Jan 2018 17:52:31 +0100 Subject: [PATCH 1/2] Adding cryptopia integration --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c13c2b..675f29a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "poloniex-api-node": "^1.6.5", "request-promise": "^4.2.2", "requestretry": "^1.12.2", - "table": "^4.0.2" + "table": "^4.0.2", + "cryptopia": "^0.0.1" }, "devDependencies": { "babel": "^6.23.0", From 1eecfd2a886a11309debba58b074b8b3d9105d2d Mon Sep 17 00:00:00 2001 From: Guillaume Nomine Date: Fri, 19 Jan 2018 17:52:55 +0100 Subject: [PATCH 2/2] Adding cryptopia integration --- src/model/integrations/CryptopiaWallet.js | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/model/integrations/CryptopiaWallet.js diff --git a/src/model/integrations/CryptopiaWallet.js b/src/model/integrations/CryptopiaWallet.js new file mode 100644 index 0000000..389ce1f --- /dev/null +++ b/src/model/integrations/CryptopiaWallet.js @@ -0,0 +1,38 @@ +import PromiseUtils from '../../PromiseUtils' +import Coin from '../Coin' +// noinspection NpmUsedModulesInstalled +import Cryptopia from 'cryptopia' + +const settings = require('../../../settings.json') + +export default class CryptopiaWallet { + static getBalance() { + return PromiseUtils.forEachPromise(settings.accounts.cryptopia, this._getBalanceForCredential) + } + + /** + * Returns the balances for a Cryptopia account. + * @param credential The Cryptopia api credentials. + * @return {Promise} The account balances. + */ + static _getBalanceForCredential(credential) { + return new Promise((resolve, reject) => { + const cryptopia = new Cryptopia(credential.apiKey, credential.apiSecret, null, 10000) + cryptopia.getBalance(function(err, response) { + if (err) { + return reject(err) + } + let result = [] + let balances = response.Data + for (let index in balances) { + let data = balances[index] + let symbol = data.Symbol + let amount = data.Available + result.push(new Coin(symbol, amount, 'Cryptopia')) + } + resolve(result) + }) + } + ) + } +} \ No newline at end of file