Support ZEC
This commit is contained in:
parent
9b51565303
commit
45e6e2b82d
10 changed files with 105 additions and 47 deletions
|
|
@ -1,17 +1,27 @@
|
|||
var BigNumber = require('bignumber.js')
|
||||
const BigNumber = require('bignumber.js')
|
||||
|
||||
var TEN = new BigNumber(10)
|
||||
const coinUtils = require('../../coin-utils')
|
||||
|
||||
var UNIT_SCALES = {
|
||||
BTC: 8,
|
||||
ETH: 18
|
||||
const TEN = new BigNumber(10)
|
||||
|
||||
const PAIRS = {
|
||||
BTC: {
|
||||
USD: 'XXBTZUSD',
|
||||
EUR: 'XXBTZEUR'
|
||||
},
|
||||
ETH: {
|
||||
USD: 'XETHZUSD',
|
||||
EUR: 'XETHZEUR'
|
||||
},
|
||||
ZEC: {
|
||||
USD: 'XZECZUSD',
|
||||
EUR: 'XZECZEUR'
|
||||
}
|
||||
}
|
||||
|
||||
function unitScale (cryptoCoin) {
|
||||
return UNIT_SCALES[cryptoCoin]
|
||||
}
|
||||
module.exports = {PAIRS, toUnit}
|
||||
|
||||
exports.toUnit = function toUnit (cryptoAtoms, cryptoCoin) {
|
||||
var scale = TEN.pow(unitScale(cryptoCoin))
|
||||
function toUnit (cryptoAtoms, cryptoCoin) {
|
||||
var scale = TEN.pow(coinUtils.unitScale(cryptoCoin))
|
||||
return cryptoAtoms.div(scale)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
const Kraken = require('kraken-api')
|
||||
const coinmath = require('../common/kraken')
|
||||
const common = require('../common/kraken')
|
||||
|
||||
var PAIRS = {
|
||||
BTC: {
|
||||
USD: 'XXBTZUSD',
|
||||
EUR: 'XXBTZEUR'
|
||||
},
|
||||
ETH: {
|
||||
USD: 'XETHZUSD',
|
||||
EUR: 'XETHZEUR'
|
||||
}
|
||||
}
|
||||
var PAIRS = common.PAIRS
|
||||
|
||||
module.exports = {buy, sell}
|
||||
|
||||
|
|
@ -23,8 +14,8 @@ function sell (account, cryptoAtoms, fiatCode, cryptoCode) {
|
|||
}
|
||||
|
||||
function trade (account, type, cryptoAtoms, fiatCode, cryptoCode) {
|
||||
const kraken = new Kraken(account.key, account.secret)
|
||||
const amount = coinmath.toUnit(cryptoAtoms, cryptoCode)
|
||||
const kraken = new Kraken(account.apiKey, account.privateKey)
|
||||
const amount = common.toUnit(cryptoAtoms, cryptoCode)
|
||||
|
||||
if (amount.lte('0.01')) {
|
||||
const err = new Error('Order size too small')
|
||||
|
|
|
|||
|
|
@ -2,20 +2,12 @@ const axios = require('axios')
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
const common = require('../../common/kraken')
|
||||
|
||||
exports.NAME = 'Kraken'
|
||||
exports.SUPPORTED_MODULES = ['ticker']
|
||||
|
||||
const PAIRS = {
|
||||
BTC: {
|
||||
USD: 'XXBTZUSD',
|
||||
EUR: 'XXBTZEUR'
|
||||
},
|
||||
ETH: {
|
||||
USD: 'XETHZUSD',
|
||||
EUR: 'XETHZEUR'
|
||||
}
|
||||
}
|
||||
const PAIRS = common.PAIRS
|
||||
|
||||
function findCurrency (fxRates, fiatCode) {
|
||||
const rates = _.find(_.matchesProperty('code', fiatCode), fxRates)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ function balance (account, cryptoCode) {
|
|||
.then(() => {
|
||||
if (cryptoCode === 'BTC') return BN(1e8 * 10)
|
||||
if (cryptoCode === 'ETH') return BN(1e18 * 10)
|
||||
if (cryptoCode === 'ZEC') return BN(1e8 * 10)
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
})
|
||||
}
|
||||
|
|
@ -24,6 +25,7 @@ function pendingBalance (account, cryptoCode) {
|
|||
.then(() => {
|
||||
if (cryptoCode === 'BTC') return BN(1e8 * 10.1)
|
||||
if (cryptoCode === 'ETH') return BN(1e18 * 10.1)
|
||||
if (cryptoCode === 'ZEC') return BN(1e8 * 10.1)
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
})
|
||||
}
|
||||
|
|
@ -33,16 +35,18 @@ function confirmedBalance (account, cryptoCode) {
|
|||
.then(() => {
|
||||
if (cryptoCode === 'BTC') return BN(1e8 * 10)
|
||||
if (cryptoCode === 'ETH') return BN(1e18 * 10)
|
||||
if (cryptoCode === 'ZEC') return BN(1e8 * 10)
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
})
|
||||
}
|
||||
|
||||
// Note: This makes it easier to test insufficient funds errors
|
||||
let sendCount = 0
|
||||
let sendCount = 100
|
||||
|
||||
function isInsufficient (cryptoAtoms, cryptoCode) {
|
||||
if (cryptoCode === 'BTC') return cryptoAtoms.gt(1e5 * 10 * sendCount)
|
||||
if (cryptoCode === 'ETH') return cryptoAtoms.gt(1e18 * 0.25 * sendCount)
|
||||
if (cryptoCode === 'ZEC') return cryptoAtoms.gt(1e5 * 0.25 * sendCount)
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue