# 匯率 API 需要一個可以轉換虛擬貨幣匯率的 API,使用 Coinbase API,預設為虛擬貨幣/美金對。 > [教學文件](https://ithelp.ithome.com.tw/articles/10195455) BTC 轉換為台幣和美金 ``` var currency = "BTC"; var url = "https://api.coinbase.com/v2/exchange-rates?currency=" + currency; var usd = document.querySelector(".usd"); var twd = document.querySelector(".twd"); function makeRequest() { xhr = new XMLHttpRequest(); xhr.onload = function() { var response = JSON.parse(this.responseText); usd.innerHTML = response.data.rates.USD + " USD"; twd.innerHTML = response.data.rates.TWD + " TWD"; }; xhr.open("GET", url, true); xhr.setRequestHeader("CB-VERSION", "2018-01-01"); xhr.send(); } makeRequest(); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up