node.js curl
Last year I started dabbling in bitcoin. Of course I was immediately cocky as bitcoin value went up 20% as soon as I bought it, then was humbled as bitcoin's value tumbled down 50%. From boathouse to outhouse. From caviar to ramen noodles. It was brutal.
去年,我开始涉足比特币。 当然,当我买进比特币后,我立刻就感到骄傲自大,因为比特币的价值一度上涨了20%,然后随着比特币的价值下跌了50%而谦虚。 从船屋到外屋。 从鱼子酱到拉面。 太残酷了。
Anyways, I was often checking the price of bitcoin because it would move up and down quite quickly. I was going to Coinbase to check but as a developer I prefer to do something nerdy to get the value. I've taken a few moments to get the value of bitcoin in a few programmatic ways.
无论如何,我经常检查比特币的价格,因为它会Swift上升或下降。 我本来要去Coinbase进行检查,但是作为一名开发人员,我喜欢做些书呆子以获取价值。 我花了一些时间以一些编程方式来获取比特币的价值。
If I want to be low-level "nerd alert" mode, I'll use this command:
如果我想成为低级的“书呆子警报”模式,我将使用以下命令:
curl -s http://api.coindesk.com/v1/bpi/currentprice.json | python -c "import json, sys; print(json.load(sys.stdin)['bpi']['USD']['rate'])"That command will provide the USD value of a single bitcoin. You can use GBP or EUR if you prefer those currencies. Services other than CoinDesk's main feed may provide another currency value.
该命令将提供单个比特币的USD价值。 如果您喜欢这些货币,则可以使用GBP或EUR 。 CoinDesk的主要供稿以外的服务可能会提供其他货币值。
The lowest level server-side JavaScript would look like this:
最低级别的服务器端JavaScript如下所示:
var http = require('http'); http.get({ host: 'api.coindesk.com', path: '/v1/bpi/currentprice.json' }, function(response) { // Continuously update stream with data var body = ''; response.on('data', function(d) { body += d; }); response.on('end', function() { // Data reception is done, do whatever with it! var parsed = JSON.parse(body); console.log(parsed.bpi.USD.rate); }); } );As you probably know, this post is less about the code and more about working with the CoinDesk API endpoint. CoinDesk does provide other endpoints to get historical bitcoin data, but I'm more concerned about my money now.
您可能知道,这篇文章较少涉及代码,而是有关使用CoinDesk API端点的更多信息。 CoinDesk确实提供了其他端点来获取历史比特币数据 ,但是我现在更加担心自己的钱。
翻译自: https://davidwalsh.name/bitcoin
node.js curl
相关资源:25个经典网站源代码