这是他们的 API documentation 的链接
我想通过从头开始创建比特币价格代码来练习网络编程。我的计划是提供一个脚本,使 api 调用交换以显示数据。这意味着我只需要提供脚本,而不是处理服务器端的数据。
我知道编程的一部分是从文档中学习,但是 bitfinex 的文档非常稀少,我找不到教程。
我创建了一个 index.html 来测试我的 javascript。它返回控制台错误:
XMLHttpRequest cannot load https://api.bitfinex.com/v1/pubticker/:last_price.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'null' is therefore not allowed access.
这是完整的 index.html:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
</head>
<body>
<script>
$.getJSON("https://api.bitfinex.com/v1/pubticker/:last_price",
function(data, status){
alert("price: "+data +" status: " + status);
}
)
</script>
Thank you stack exchange
</body>
最佳答案
你不能——至少不能使用 Javascript。该 API 未配置为允许来自其他网站上运行的 Javascript 的调用。您需要从 Web 服务器上运行的脚本调用此 API。
(此外,对于它的值(value),URL 中的 :symbol
token 应该替换为您要查找的代码的符号,例如 /v1/pubticker/BTCUSD
用于 BTC/USD 兑换价格。)
关于javascript - 如何使用 JavaScript 从 Bitfinex Web API 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24975684/