Skip to content

Commit

Permalink
Switch to v2 API of Coinbase
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Dec 4, 2018
1 parent 189e0f4 commit a26be45
Show file tree
Hide file tree
Showing 4 changed files with 323 additions and 10 deletions.
4 changes: 4 additions & 0 deletions changelog.md
@@ -1,5 +1,9 @@
# edge-exchange-plugins

## 0.2.1

* Switch to v2 of Coinbase API

## 0.2.0

* Add CoinCap support
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "edge-exchange-plugins",
"version": "0.2.0",
"version": "0.2.1",
"description": "Exchange-rate sources for the Edge core",
"license": "SEE LICENSE IN LICENSE",
"author": "Edge",
Expand Down
19 changes: 10 additions & 9 deletions src/coinbase.js
Expand Up @@ -23,21 +23,22 @@ export const coinbasePlugin = {

async fetchExchangeRates (pairsHint) {
const reply = await io.fetch(
'https://coinbase.com/api/v1/currencies/exchange_rates'
'https://api.coinbase.com/v2/exchange-rates'
)
const json = await reply.json()

// Grab all the BTC pairs:
if (!json || !json.data || !json.data.rates) return []

// Grab all the USD pairs:
const pairs = []
const keys = Object.keys(json)
const keys = Object.keys(json.data.rates)
for (const key of keys) {
const currency = key.replace(/btc_to_/, '')
if (currency === key) continue

const rate = Number(json.data.rates[key])
const toCurrency = fixCurrency(key)
pairs.push({
fromCurrency: 'BTC',
toCurrency: fixCurrency(currency),
rate: json[key]
fromCurrency: 'iso:USD',
toCurrency,
rate
})
}

Expand Down

0 comments on commit a26be45

Please sign in to comment.