Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cryptopia integration #42

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions src/model/integrations/CryptopiaWallet.js
Original file line number Diff line number Diff line change
@@ -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)
})
}
)
}
}