-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
244 additions
and
13 deletions.
There are no files selected for viewing
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
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
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,39 @@ | ||
import PromiseUtils from '../../PromiseUtils' | ||
import Coin from '../Coin' | ||
// noinspection NpmUsedModulesInstalled | ||
import Bitfinex from 'bitfinex' | ||
|
||
const settings = require('../../../settings.json') | ||
|
||
export default class BitfinexWallet { | ||
static getBalance() { | ||
return PromiseUtils.forEachPromise(settings.accounts.bitfinex, this._getBalanceForCredential) | ||
} | ||
|
||
/** | ||
* Returns the balances for a Bitfinex account. | ||
* @param credential The Bitfinex api credentials. | ||
* @return {Promise} The account balances. | ||
* @prop account The accounts for given credentials. | ||
* @prop account.balance The balance of the account. | ||
* @prop data.asset The currency. | ||
* @prop data.free The amount. | ||
*/ | ||
static _getBalanceForCredential(credential) { | ||
return new Promise((resolve, reject) => { | ||
const {apiKey, apiSecret} = credential | ||
const bitfinex = new Bitfinex(apiKey, apiSecret) | ||
|
||
bitfinex.wallet_balances((err, balances) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
|
||
const result = balances.map(({currency, amount}) => new Coin(currency.toUpperCase(), amount, 'Bitfinex')) | ||
|
||
resolve(result) | ||
}) | ||
} | ||
) | ||
} | ||
} |
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,9 @@ | ||
import BitfinexWallet from '../../../src/model/integrations/BitfinexWallet' | ||
import assert from 'assert' | ||
|
||
describe('Testing Bitfinex integration', () => { | ||
it('Testing initial connection and balances', async () => { | ||
let wallet = await BitfinexWallet.getBalance() | ||
assert(wallet.length > 0) | ||
}) | ||
}) |