简介:Coinbase,相信大家都不陌生,世界顶级数字货币交易所。Coinbase 有非常完备的 API 服务,包括允许开发人员使用 OAuth2 协议允许 Coinbase 用户授予第三方应用程序对其帐户的完全或部分访问权限,而无需共享帐户的 API 密钥或登录凭据。本篇文章介绍开发者如何使用 Coinbase 公共数据 API 获取交易对订单记录。
Coinbase,相信大家都不陌生,世界顶级数字货币交易所。Coinbase 有非常完备的 API 服务,包括允许开发人员使用 OAuth2 协议允许 Coinbase 用户授予第三方应用程序对其帐户的完全或部分访问权限,而无需共享帐户的 API 密钥或登录凭据。
Coinbase, which I believe everyone knows, is the world's top digital currency exchange. Coinbase's API services are very comprehensive, it allows developers to use the OAuth2 protocol to allow a Coinbase user to grant a 3rd party application full or partial access to his/her account, without sharing the account’s API key or login credentials.
本篇文章,我们展示如何利用 Coinbase 的 Market Data API 获取交易对交易记录。
In this article, we show how to use Coinbase's Market Data API to list the latest trades for a product.
Market Data API 是 Coinbase Pro API 中不需要身份验证的公共信息端口,用于检索市场数据。它提供市场数据的快照。
The Market Data API is an unauthenticated set of endpoints for retrieving market data. These endpoints provide snapshots of market data.
Market Data API 官方文档:https://docs.pro.coinbase.com/#market-data
Market Data API official documentation: https://docs.pro.coinbase.com/#market-data
获取交易对交易记录:
List the latest trades for a product:
https://api-public.sandbox.pro.coinbase.com/products/<product-id>/trades
比如查询 ETH-BTC 交易对:
For example, query ETH-BTC:
https://api-public.sandbox.pro.coinbase.com/products/ETH-BTC/trades
Node.js 代码示例:
Code example (Node.js):
const fetch = require('node-fetch');
fetch('https://api-public.sandbox.pro.coinbase.com/products/<product-id>/trades', {
method: 'get',
}).then(response => response.json()
.then(data => console.log(data)));
返回的 JSON 示例:
Return JSON example:
[
{
"time": "2019-03-13T00:45:43.461Z",
"trade_id": 98016,
"price": "0.04000000",
"size": "0.01000000",
"side": "sell"
},
{
"time": "2019-03-13T00:45:42.571Z",
"trade_id": 98015,
"price": "0.04000000",
"size": "0.01000000",
"side": "sell"
},
{
"time": "2019-03-12T19:31:50.423Z",
"trade_id": 98014,
"price": "0.98999000",
"size": "0.01000000",
"side": "sell"
},
{
"time": "2019-03-12T19:31:49.324Z",
"trade_id": 98013,
"price": "0.98999000",
"size": "0.01000000",
"side": "sell"
},
{
"time": "2019-03-12T18:23:38.11Z",
"trade_id": 98012,
"price": "0.05000000",
"size": "1.10000000",
"side": "buy"
},
{
"time": "2019-03-12T16:57:57.807Z",
"trade_id": 98011,
"price": "0.05000000",
"size": "0.40004000",
"side": "sell"
},
{
"time": "2019-03-12T16:57:57.807Z",
"trade_id": 98010,
"price": "0.04003000",
"size": "0.69996000",
"side": "sell"
},
{
"time": "2019-03-12T16:57:45.283Z",
"trade_id": 98009,
"price": "0.04003000",
"size": "0.30003000",
"side": "sell"
},
{
"time": "2019-03-12T16:57:45.283Z",
"trade_id": 98008,
"price": "0.04002000",
"size": "0.79997000",
"side": "sell"
},
{
"time": "2019-03-12T16:56:34.464Z",
"trade_id": 98007,
"price": "0.04002000",
"size": "0.20002000",
"side": "sell"
},
{
"time": "2019-03-12T16:56:34.464Z",
"trade_id": 98006,
"price": "0.04001000",
"size": "0.89998000",
"side": "sell"
},
{
"time": "2019-03-12T16:26:24.285Z",
"trade_id": 98005,
"price": "0.04001000",
"size": "0.10001000",
"side": "sell"
}
]
Market Data API 思维导图:
Mind map of the Market Data API:
我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我: