簡(jiǎn)介:Coinbase吕喘,相信大家都不陌生漂辐,世界頂級(jí)數(shù)字貨幣交易所显拳。Coinbase 有非常完備的 API 服務(wù),包括允許開(kāi)發(fā)人員使用 OAuth2 協(xié)議允許 Coinbase 用戶(hù)授予第三方應(yīng)用程序?qū)ζ鋷?hù)的完全或部分訪問(wèn)權(quán)限伪很,而無(wú)需共享帳戶(hù)的 API 密鑰或登錄憑據(jù)岔激。本篇文章介紹開(kāi)發(fā)者如何使用 Coinbase 公共數(shù)據(jù) API 獲取交易對(duì)歷史價(jià)格。
Coinbase是掰,相信大家都不陌生虑鼎,世界頂級(jí)數(shù)字貨幣交易所。Coinbase 有非常完備的 API 服務(wù)键痛,包括允許開(kāi)發(fā)人員使用 OAuth2 協(xié)議允許 Coinbase 用戶(hù)授予第三方應(yīng)用程序?qū)ζ鋷?hù)的完全或部分訪問(wèn)權(quán)限炫彩,而無(wú)需共享帳戶(hù)的 API 密鑰或登錄憑據(jù)。
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 獲取交易對(duì)歷史價(jià)格江兢。
In this article, we show how to use Coinbase's Market Data API to get the historic rates for a product.
Market Data API 是 Coinbase Pro API 中不需要身份驗(yàn)證的公共信息端口,用于檢索市場(chǎng)數(shù)據(jù)丁频。它提供市場(chǎng)數(shù)據(jù)的快照杉允。
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
獲取交易對(duì)歷史價(jià)格:
Get the historic rates for a product.:
使用沙箱測(cè)試端口:
Use sandbox URL:
https://api-public.sandbox.pro.coinbase.com/products/<product-id>/candles
使用生產(chǎn)端口:
Use rest API endpoint URL:
https://api.pro.coinbase.com/products/<product-id>/candles
比如查詢(xún) ETH-BTC 交易對(duì):
For example, query ETH-BTC:
使用沙箱測(cè)試端口:
Use sandbox URL:
https://api-public.sandbox.pro.coinbase.com/products/ETH-BTC/candles
使用生產(chǎn)端口:
Use rest API endpoint URL:
Node.js 代碼示例:
Code example (Node.js):
const fetch = require('node-fetch');
fetch('https://api-public.sandbox.pro.coinbase.com/products/<product-id>/candles', {
method: 'get',
}).then(response => response.json()
.then(data => console.log(data)));
端口接受三個(gè)可選參數(shù):
Parameters:
start: ISO 8601規(guī)則的開(kāi)始時(shí)間
end: ISO 8601規(guī)則的結(jié)束時(shí)間
granularity: 時(shí)間段大小(輸入秒數(shù))
start: Start time in ISO 8601
end: End time in ISO 8601
granularity: Desired timeslice in seconds
granularity 參數(shù)只能是這些值:{60, 300, 900, 3600, 21600, 86400}席里。否則請(qǐng)求將被拒絕叔磷。這些值都是秒數(shù),分別代表一分鐘奖磁,五分鐘改基,十五分鐘,一小時(shí)咖为,六小時(shí)和一天秕狰。
The granularity field must be one of the following values: {60, 300, 900, 3600, 21600, 86400}. Otherwise, your request will be rejected. These values correspond to timeslices representing one minute, five minutes, fifteen minutes, one hour, six hours, and one day, respectively.
返回的 JSON 示例:
Return JSON example:
[
[ time, low, high, open, close, volume ],
[ 1415398768, 0.32, 4.2, 0.35, 4.2, 12.3 ],
...
]
返回 JSON 釋義:
Each bucket is an array of the following information:
time: 時(shí)間段開(kāi)始的時(shí)間;
low: 時(shí)間段中的最低價(jià)格躁染;
high: 時(shí)間段中的最高價(jià)格鸣哀;
open: 時(shí)間段中第一筆交易的開(kāi)盤(pán)價(jià);
close: 時(shí)間段中最后一筆交易的收盤(pán)價(jià)吞彤;
volume: 時(shí)間段中的交易活動(dòng)量我衬。
time: bucket start time
low: lowest price during the bucket interval
high: highest price during the bucket interval
open: opening price (first trade) in the bucket interval
close: closing price (last trade) in the bucket interval
volume: volume of trading activity during the bucket interval
Market Data API 思維導(dǎo)圖:
Mind map of the Market Data API:
我們有一個(gè)區(qū)塊鏈知識(shí)星球,做區(qū)塊鏈前沿資料的歸納整理以方便大家檢索查詢(xún)使用备畦,也是國(guó)內(nèi)頂尖區(qū)塊鏈技術(shù)社區(qū)低飒,歡迎感興趣的朋友加入。如果你對(duì)上面內(nèi)容有疑問(wèn)懂盐,也可以加入知識(shí)星球提問(wèn)我: