add coinbase ticker
This commit is contained in:
parent
d28b21a6d7
commit
97bab49e15
5 changed files with 177 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
|||
const common = require('../common/bitstamp')
|
||||
const common = require('../../common/bitstamp')
|
||||
|
||||
const SATOSHI_SHIFT = 8
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const BN = require('../../../bn')
|
||||
const common = require('../common/bitstamp')
|
||||
const common = require('../../common/bitstamp')
|
||||
|
||||
function ticker (account, fiatCode, cryptoCode) {
|
||||
return Promise.resolve()
|
||||
|
|
|
|||
55
lib/plugins/ticker/coinbase/coinbase.js
Normal file
55
lib/plugins/ticker/coinbase/coinbase.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
const _ = require('lodash/fp')
|
||||
const axios = require('axios')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
|
||||
function getBuyPrice (obj) {
|
||||
const currencyPair = obj.currencyPair
|
||||
|
||||
return axios({
|
||||
method: 'get',
|
||||
url: `https://api.coinbase.com/v2/prices/${currencyPair}/buy`,
|
||||
headers: {'CB-Version': '2017-07-10'}
|
||||
})
|
||||
.then(r => r.data)
|
||||
}
|
||||
|
||||
function getSellPrice (obj) {
|
||||
const currencyPair = obj.currencyPair
|
||||
|
||||
return axios({
|
||||
method: 'get',
|
||||
url: `https://api.coinbase.com/v2/prices/${currencyPair}/sell`,
|
||||
headers: {'CB-Version': '2017-07-10'}
|
||||
})
|
||||
.then(r => r.data)
|
||||
}
|
||||
|
||||
function ticker (account, fiatCode, cryptoCode) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
if (!_.includes(cryptoCode, ['BTC', 'ETH', 'LTC'])) {
|
||||
throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
const currencyPair = `${cryptoCode}-${fiatCode}`
|
||||
const promises = [
|
||||
getBuyPrice({currencyPair}),
|
||||
getSellPrice({currencyPair})
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
})
|
||||
.then(([buyPrice, sellPrice]) => ({
|
||||
rates: {
|
||||
ask: BN(buyPrice.data.amount),
|
||||
bid: BN(sellPrice.data.amount)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ticker
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue