【原创】Coinbase 公共数据 API 探索(3):获取交易对基本信息


#1

简介: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 获取交易对基本信息(包括最后交易价格,24小时交易量等)。

In this article, we show how to use Coinbase’s Market Data API to get the snapshot information about the last trade (tick), best bid/ask and 24h volume.

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

获取交易对基本信息:

Get the snapshot information about the last trade (tick), best bid/ask and 24h volume:

https://api-public.sandbox.pro.coinbase.com/products//ticker

比如查询 ETH-BTC 交易对:

For example, query ETH-BTC:

https://api-public.sandbox.pro.coinbase.com/products/ETH-BTC/ticker

Node.js 代码示例:

Code example (Node.js):

const fetch = require('node-fetch');

fetch('https://api-public.sandbox.pro.coinbase.com/products/<product-id>/ticker', {
    method: 'get',
}).then(response => response.json()
    .then(data => console.log(data)));

返回的 JSON 示例:

Return JSON example:

{
  "trade_id": 97517,
  "price": ".98999",
  "size": "1.00000000",
  "time": "2019-03-11T13:20:29.151000Z",
  "bid": "0.03999",
  "ask": "0.98999",
  "volume": "6.51999000"
}

Market Data API 思维导图:

Mind map of the Market Data API:

Coinbase Market Data API