NAV Navbar
shell javascript java python php ruby
  • 概述
  • REST API
  • WebSocket API 概述
  • 交易所收录
  • 概述

    简介

    Block.cc是专业的区块链产业信息服务平台,提供数字货币行情、数据、资讯等一站式区块链产业服务,追求更及时、更全面、更专业、更准确的行情数据,致力为区块链爱好者和数字货币投资者提供最权威最流畅的产品和服务。

    第三方应用开发者可以借助该服务,快速构建稳定高效的数字货币行情系统,为实时业务需求和产品运营提供技术支持。

    当前版本

    API Endpoint: https://data.block.cc/api/v3
    

    认证

    获取API密钥

    针对Block.cc API发出的所有HTTP请求都必须使用API密钥进行验证。 如果您还没有API密钥,请访问 开放API首页 注册一个。

    使用您的密钥

    Api Key请求示例:

    curl -X GET \
      'https://data.block.cc/api/v3/markets?api_key=SDE8DEW889A0DE5D4CC67C7DCD34S2F5'
    

    您可以通过以下方式在REST API调用中提供API密钥:

    1.首选方法:通过名为X-API-KEY的请求头

    2.便捷方法:通过名为API_KEY 的查询字符串参数

    请求限制

    API限制响应内容:

    {
      "code": 429,
      "message": "Rate Limited",
    }
    

    为了提供更高服务质量,一般限制每分钟请求次数为60次,最高300次。如果某个IP地址每分钟请求次数超过60次,则该请求的IP地址将在该端点上被阻止1-60秒,并且返回HTTP状态码429。

    错误码

    错误码响应内容示例:

    {
      "code": 1004,
      "message": "Param Required",
    }
    
    HTTP 状态码 错误码 错误信息
    400 10001 This API Key is invalid
    400 10002 API key missing
    400 10003 Duration Limited
    400 10004 Resource Exist
    400 10005 Empty Resource
    400 10006 Param Required
    400 10007 Unavailable Resource
    429 429 Rate Limited
    500 500 Internal Server Error
    404 404 Not Found

    分页

    Link →<http://data.block.cc/api/v3/tickers?page=1&size=20>; rel="next",
    <http://data.block.cc/api/v3/tickers?page=1185&size=20>; rel="last",
    <http://data.block.cc/api/v3/tickers?page=0&size=20>; rel="first"
    

    Block.cc接口的具体分页信息显示在响应头的link标签,这样调用者可以直接得到诸如下一页、最后一页、上一页等内容的 url 地址,而不是自己手动去计算和拼接。

    可能的rel值为:

    名字 描述
    next 直接链接到结果的下一页
    last 直接链接到结果的最后一页
    first 第一页结果的链接关系
    prev 直接链接到结果的上一页

    变量规则

    变量命名

    所有接口返回字段都使用驼峰约定命名。这意味着单词由首字母大写分隔,不使用空格。

    所有参数,路径都使用蛇形命名法(snake_case)约定命名。这意味着单词由一个下划线_字符分隔,不使用空格,字母为小写。

    交易货币 Symbol

    Symbol 为交易货币,由符号(symbol)与名称(symbolName)组成。

    如 bitcoin(BTC), ethereum(ETH)。

    通过 Symbols API 可以获取币种列表。

    交易所 Market

    交易所(Market) 命名根据实际交易所域名。

    如果域名为 *.com , 那么该交易所名字为二级域名.

    如果域名不为 *.com , 那么该交易所名字为 二级域名-顶级域名.

    交易所均为小写

    如: bitfinex(bitfinex.com), gate-io(gate.io)

    通过 Markets API 可以获取所有支持的交易所列表。

    交易所-交易对 MarketPair

    交易所-交易对(MarketPair) 由交易所(Market)和交易对(SymbolPair)组成,由下划线分割。

    字符串大小写按照交易所和交易对的规定。

    如: bitfinex_BTC_USD, gate-io_BTC_USDT,

    通过 MarketPairs API 可以所有支持的交易所以及交易对的列表。

    REST API

    元数据

    元数据为基础数据,一般作为请求行情数据的参数.

    Markets

    curl -X GET \
      'https://data.block.cc/api/v3/markets'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/markets',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/markets")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/markets"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/markets');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/markets")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    Response

    {
      "code": 0,
      "message": "success",
      "data": [
        {
          "name": "binance",
          "displayName": "Binance",
          "homeUrl": "https://www.binance.com/",
          "volume": 2490122366.2343,
          "reportedVolume":2490122366.2343,
          "expectedVolume": 2490122366.2343,
          "monthlyVisits":19386372.159024935,
          "status": "enable",
          "has_kline": true,
          "isSpot":true,
          "isFutures":false,
          "isTransFeeMining":true,
          "purity":1
        },
        {
          "name": "okex",
          "displayName": "OKEX",
          "homeUrl": "https://www.okex.com",
          "volume": 2490122366.2343,
          "reportedVolume":2490122366.2343,
          "expectedVolume": 2490122366.2343,
          "monthlyVisits":19386372.159024935,
          "status": "enable",
          "has_kline": true,
          "isSpot":true,
          "isFutures":false,
          "isTransFeeMining":true,
          "purity":1
        }
      ]
    }
    

    获取所有支持的交易所列表

    请求URL

    GET https://data.block.cc/api/v3/markets

    请求参数

    None

    返回参数说明

    参数 说明
    name 交易所名称(ID)
    displayName 交易所显示名称
    homeUrl 交易所链接
    volume 根据加权计算出的交易量(USD)
    reportedVolume 未经加权计算出的交易量(USD)
    expectedVolume 经加权计算出的交易量(USD)
    status 状态: [enable, disable]. disable为停止更新数据
    has_kline 是否接入K线数据
    isSpot 是否支持现货
    isFutures 是否支持期货
    isTransFeeMining 是否支持挖矿
    purity 纯度

    Symbols

    curl -X GET \
      'https://data.block.cc/api/v3/symbols'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/symbols',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/symbols")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/symbols"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/symbols');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/symbols")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    Response:

    {
      "code": 0,
      "message": "success",
      "data": [
        {
          "name": "bitcoin",
          "symbolStr": "BTC",
          "volumeUsd": 4463819005.1846,
          "status": "enable",
          "marketCapUsd":157081834083.0375,
          "availableSupply":18039125,
          "totalSupply":18039125,
          "maxSupply":21000000,
          "website":"https://bitcoin.org/en/",
          "websiteDomain": "bitcoin.org",
          "explorerUrls": "https://live.blockcypher.com/btc/,http://blockchain.info,https://blockchair.com/bitcoin/,https://explorer.viabtc.com/btc,https://blockexplorer.com/,https://btc.com/",
          "whitePaperUrls":"https://bitcoin.org/bitcoin.pdf",
          "githubId": "bitcoin",
          "twitterId": "btc",
          "facebookId": "bitcoins",
          "telegramId": "www_bitcoin_com",
          "redditId": "bitcoin",
          "algorithm": "SHA256",
          "proof": "POW",
          "issueDate": "2008-10-31T16:00:00Z"
        }
      ]
    }
    
    

    获取所有支持的币种列表

    请求URL

    GET https://data.block.cc/api/v3/symbols

    请求参数

    None

    返回参数说明

    参数 说明
    name 币种名称(ID)
    symbolStr 币种符号
    volumeUsd 交易量(USD)
    status 状态: [enable, disable]. disable为停止更新数据
    marketCapUsd 币种市值
    availableSupply 流通量
    totalSupply 总量
    maxSupply 最大量
    website 官网
    websiteDomain 域名
    explorerUrls 区块浏览器
    whitePaperUrls 白皮书
    githubId Github
    twitterId Twitter
    facebookId FaceBook
    telegramId Telegram
    algorithm 核心算法
    proof 激励机制
    issueDate 上市时间

    MarketPairs

    curl -X GET \
      'https://data.block.cc/api/v3/market_pairs'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/market_pairs',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/market_pairs")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/market_pairs"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/market_pairs');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/market_pairs")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data": [
        {
          "marketName": "binance-future",
          "symbolName": "bitcoin",
          "symbol": "BTC-PERPETUAL",
          "currency": "USDT",
          "volumeUsd": 1200434842.74,
          "expectedVolumeUsd": 819708529.32,
          "klineEnable": false,
          "status": "enable",
          "decimals": 2,
          "askPendingVolumeP1": 0,
          "bidPendingVolumeP1": 0,
          "depthSpread": 0,
          "marketPairDesc": "binance-future_BTC-PERPETUAL_USDT"
          },
        {
          "marketName": "bitmex",
          "symbolName": "bitcoin",
          "symbol": "XBT-PERPETUAL",
          "currency": "USD",
          "volumeUsd": 2717020832,
          "expectedVolumeUsd": 467349319.27,
          "klineEnable": false,
          "status": "enable",
          "askPendingVolumeP1": 0,
          "bidPendingVolumeP1": 0,
          "depthSpread": 0,
          "marketPairDesc": "bitmex_XBT-PERPETUAL_USD"
        }
      ]
    }
    
    

    获取所有支持的交易所以及支持的交易对列表

    Request URL

    GET https://data.block.cc/api/v3/market_pairs

    Request parameter

    None

    返回参数说明

    参数 说明
    marketName 交易所名称(ID)
    symbolName 币种名称(ID)
    symbol 币种简称
    currency 基础币种
    volumeUsd 交易量(USD)
    expectedVolumeUsd 推测交易量(USD)
    klineEnable 是否支持k线
    status 状态: [enable, disable]. disable为停止更新数据
    askPendingVolumeP1 盘口卖单挂单量
    bidPendingVolumeP1 盘口买单挂单量
    depthSpread 点差
    marketPairDesc 交易所的交易对名称

    Market

    curl -X GET \
      'https://data.block.cc/api/v3/market/bitfinex'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/market/bitfinex',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/market/bitfinex")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/market/bitfinex"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/market/bitfinex');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/market/bitfinex")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data": {
        "name": "gate-io",
        "displayName": "Gate.io",
        "homeUrl": "https://www.gate.io/",
        "domains": "gate.io,gateio.news,gateio.co",
        "rank": 11,
        "volume": 50631104.33,
        "reportedVolume": 50631104.33,
        "expectedVolume": 50631104.33,
        "monthlyVisits": 1865745.74409867,
        "hasKline": true,
        "status": "enable",
        "isSpot": true,
        "isFutures": false,
        "isTransFeeMining": false,
        "purity": 1
      }
    }
    
    

    获取制定交易所信息

    Request URL

    GET https://data.block.cc/api/v3/market/{market_name}

    Request parameter

    参数 传输方式 必选 说明
    market_name URL Params 交易所名称(ID)

    返回参数说明

    参数 说明
    name 交易所名称(ID)
    displayName 交易所显示名称
    homeUrl 交易所链接
    domains 域名
    volume 根据加权计算出的交易量(USD)
    reportedVolume 未经加权计算出的交易量(USD)
    expectedVolume 根据加权计算出的交易量(USD)
    monthlyVisits 月访问量
    hasKline 是否支持k线
    status 状态: [enable, disable]. disable为停止更新数据
    isSpot 是否支持现货
    isFutures 是否支持期货
    isTransFeeMining 是否支持挖矿
    purity 纯度

    行情数据

    ExchangeRate

    curl -X GET \
      'https://data.block.cc/api/v3/exchange_rate'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/exchange_rate',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/exchange_rate")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/exchange_rate"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/exchange_rate');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/exchange_rate")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data": [
       {
        "currency": "USD",
        "rate": 1
        },
        {
        "currency": "AED",
        "rate": 3.6729
        },
        {
        "currency": "AFN",
        "rate": 78.31899
        },
        {
        "currency": "ALL",
        "rate": 111.601841
        },
        {
        "currency": "AMD",
        "rate": 477.853793
        }
      ]
    }
    
    

    获取汇率

    Request URL

    GET https://data.block.cc/api/v3/exchange_rate

    Request parameter

    None

    返回参数说明

    参数 说明
    currency 基础货币名称
    rate 基于基础货币的汇率

    Price

    curl -X GET \
      'https://data.block.cc/api/v3/price?symbol_name=bitcoin,filecoin'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/price?symbol_name=bitcoin,filecoin',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/price?symbol_name=bitcoin,filecoin")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/price?symbol_name=bitcoin,filecoin"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/price?symbol_name=bitcoin,filecoin');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/price?symbol_name=bitcoin,filecoin")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data":
       [
          {
            "symbolName": "bitcoin",
            "symbol": "BTC",
            "timestamp": 1564201016247,
            "priceUsd": 10254.613,
            "priceBtc": 1,
            "volume": 66180.407,
            "volumeUsd": 663551832.77,
            "reportedVolume": 68260.277,
            "reportedVolumeUsd": 684890110,
            "marketCapUsd": 182193710000
          },
          {
            "symbolName": "ethereum",
            "symbol": "ETH",
            "timestamp": 1564201016249,
            "priceUsd": 224.72639,
            "priceBtc": 0.021914663,
            "volume": 1123748.2,
            "volumeUsd": 250398262.42,
            "reportedVolume": 1123748.2,
            "reportedVolumeUsd": 250398260,
            "marketCapUsd": 23944294000
          }
      ]
    }
    
    

    获取币种价格

    Request URL

    GET https://data.block.cc/api/v3/price

    Request parameter

    参数名称 传输方式 必选 说明
    symbol_name QueryString 币种名称,可传多个币种,逗号分割。
    symbol QueryString 币种符号,可传多个币种,逗号分割。一个符号可能对应多个币种。
    page QueryString 当前页数,默认 1, (>=1)。注意:只有symbol_name和symbol两者皆不存在,该值才有效
    size QueryString 每页数据量,默认 20 (100>=size>=1)。 注意:只有symbol_name和symbol两者皆不存在,该值才有效

    注意:若symbol_name和symbol两者皆存在,优先级 symbol_name > symbol, 按照交易量大小降序返回。

    返回参数说明

    参数 说明
    symbolName 币种名称
    symbol 币种符号
    priceUsd 价格(USD)
    priceBtc 价格(BTC)
    volumeUsd 交易量(USD)
    timestamps 时间戳(毫秒)
    volume 交易量(单位为当前币种)
    reportedVolume 报告交易量(单位为当前币种)
    reportedVolumeUsd 报告交易量(USD)
    marketCapUsd 市值(USD)

    Tickers

    curl -X GET \
      'https://data.block.cc/api/v3/tickers?market=bitfinex'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/tickers?market=bitfinex',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/tickers?market=bitfinex")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/tickers?market=bitfinex"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/tickers?market=bitfinex');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/tickers?market=bitfinex")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data": 
        [
          {
            "T": 1566546506486,
            "m": "bitmex_XBT-PERPETUAL_USD",
            "o": 9991.19,
            "c": 10206,
            "l": 9860,
            "h": 10250,
            "a": 10206,
            "A": 0,
            "b": 10205.5,
            "B": 0,
            "C": 0.0215,
            "bv": 252242,
            "qv": 2574378787,
            "r": 1,
            "p": 0,
            "ap1": 0,
            "bp1": 0,
            "s": 0
          }
        ]
      }
    }
    
    

    批量获取交易对Tickers

    Request URL

    GET https://data.block.cc/api/v3/tickers

    Request parameter

    参数名称 传输方式 必选 说明
    market QueryString 交易所名称,可传多个,逗号分割
    symbol QueryString 币种符号,可传多个,逗号分割
    symbol_name QueryString 币种名称,可传多个,逗号分割
    currency QueryString 基础货币,可传多个,逗号分割
    market_pair QueryString 交易所的交易对名称,可传多个,逗号分割
    page QueryString 当前页数,默认 1, (>=1)
    size QueryString 每页数据量,默认 20 (>=1)

    例如:

    返回参数说明

    参数 说明
    T 数据更新时间
    c 最新价格(单位:基础货币)
    b 买一价(单位:基础货币)
    a 卖一价(单位:基础货币)
    o 开盘价(单位:基础货币)
    h 24小时最高价(单位:基础货币)
    l 24小时最低价(单位:基础货币)
    bv 24小时交易货币交易量
    qv 24小时基础货币交易量
    C(大写) 24小时涨幅
    m 交易所的交易对名称
    p 纯度
    r 基础转货币转美元的汇率
    ap1 盘口卖单挂单量
    bp1 盘口买单挂单量
    s 点差

    Orderbook

    curl -X GET \
      'https://data.block.cc/api/v3/orderbook?market=bitfinex&symbol_pair=BTC_USD'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/orderbook?market=bitfinex&symbol_pair=BTC_USD',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/orderbook?market=bitfinex&symbol_pair=BTC_USD")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/orderbook?market=bitfinex&symbol_pair=BTC_USD"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/orderbook?market=bitfinex&symbol_pair=BTC_USD');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/orderbook?market=bitfinex&symbol_pair=BTC_USD")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data": {
        "timestamps": 1526706175469,
        "marketPair": "bitfinex_BTC_USD",
        "bids": [
          [
            8221.6,
            4.99792
          ],
          [
            8221.2,
            1.212
          ],
          [
            8220.6,
            0.04144752
          ]
        ],
        "asks": [
          [
            8221.7,
            1.10182386
          ],
          [
            8222.1,
            2.78535112
          ],
          [
            8223.2,
            4.21445703
          ]
        ]
      }
    }
    
    

    获取交易对深度

    Request URL

    GET https://data.block.cc/api/v3/orderbook

    Request parameter

    参数名称 传输方式 必选 说明
    market QueryString 交易所名称。
    symbol_pair QueryString 交易对。
    limit QueryString 深度档位,默认25。

    返回参数说明

    参数 说明
    timestamps 更新时间戳
    marketPair 交易所的交易对名称
    bids 买单列表
    asks 卖单列表
    bids/asks参数 说明
    0 价格
    1 挂单量

    Trades

    curl -X GET \
      'https://data.block.cc/api/v3/trades?market=bitfinex&symbol_pair=BTC_USD'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/trades?market=bitfinex&symbol_pair=BTC_USD',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/trades?market=bitfinex&symbol_pair=BTC_USD")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/trades?market=bitfinex&symbol_pair=BTC_USD"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/trades?market=bitfinex&symbol_pair=BTC_USD');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/trades?market=bitfinex&symbol_pair=BTC_USD")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data": [
        {
          "T": 1573721951113,
          "p": 8634,
          "v": 5,
          "s": "buy"
        },
        {
          "T": 1573721944964,
          "p": 8634,
          "v": 0.001519,
          "s": "sell"
        }
      ]
    }
    
    

    获取交易对成交记录

    Request URL

    GET https://data.block.cc/api/v3/trades

    Request parameter

    参数名称 传输方式 必选 说明
    market QueryString 交易所名称
    symbol_pair QueryString 交易对
    limit QueryString 返回数据量,默认50

    返回参数说明

    参数 说明
    T 交易成交时间戳
    p 成交价格
    v 成交量
    s 成交类型[buy,sell,none],为taker操作方向

    Kline

    curl -X GET \
      'https://data.block.cc/api/v3/kline?market=bitfinex&symbol_pair=BTC_USD&type=15m&start=1573637497000'
    
    const request = require("request");
    
    const options = { 
      method: 'GET',
      url: 'https://data.block.cc/api/v3/kline?market=bitfinex&symbol_pair=BTC_USD&type=15m&start=1573637497000',
    };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
      console.log(body);
    });
    
    OkHttpClient client = new OkHttpClient();
    
    Request request = new Request.Builder()
      .url("https://data.block.cc/api/v3/kline?market=bitfinex&symbol_pair=BTC_USD&type=15m&start=1573637497000")
      .get()
      .build();
    
    Response response = client.newCall(request).execute();
    
    import requests
    
    url = "https://data.block.cc/api/v3/kline?market=bitfinex&symbol_pair=BTC_USD&type=15m&start=1573637497000"
    
    response = requests.request("GET", url)
    
    print(response.text)
    
    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    
    $request->setRequestUrl('https://data.block.cc/api/v3/kline?market=bitfinex&symbol_pair=BTC_USD&type=15m&start=1573637497000');
    $request->setRequestMethod('GET');
    
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    
    echo $response->getBody();
    
    require 'uri'
    require 'net/http'
    
    url = URI("https://data.block.cc/api/v3/kline?market=bitfinex&symbol_pair=BTC_USD&type=15m&start=1573637497000")
    
    http = Net::HTTP.new(url.host, url.port)
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_body
    

    将会返回以下内容:

    {
      "code": 0,
      "message": "success",
      "data": [
        {
          "T": 1573680600000,
          "o": 8789,
          "h": 8795.3,
          "l": 8778.4,
          "c": 8791.2,
          "v": 14.16106481
        },
        {
          "T": 1573676100000,
          "o": 8806.3,
          "h": 8818.6,
          "l": 8802.8,
          "c": 8817.7,
          "v": 11.33948342
        }
      ]
    }
    
    

    获取交易对K线数据(OHLCV)

    Request URL

    GET https://data.block.cc/api/v3/kline

    Request parameter

    参数名称 传输方式 必选 说明
    market QueryString 交易所名称
    symbol_pair QueryString 交易对
    type QueryString K线类型[5m,15m,30m,1h,6h,1d,7d],默认5m
    start QueryString 起始时间,单位:毫秒
    end QueryString 截止时间,单位:毫秒,默认最新时间

    返回参数说明

    参数 说明
    T 时间戳
    o 开盘价
    c 收盘价
    l 最低价
    h 最高价
    v 交易量

    WebSocket API 概述

    行情数据

    概述

    WebSocket是HTML5一种新的协议(Protocol)。它实现了客户端与服务器全双工通信, 使得数据可以快速地双向传播。通过一次简单的握手就可以建立客户端和服务器连接, 服务器根据业务规则可以主动推送信息给客户端。其优点如下:

    地址:wss://data.block.cc/ws/v3?api_key=XXX

    访问时需要网络

    连接说明: 连接时需要将用户对应的API_KEY作为参数传入

    连接上ws后,系统会每隔30秒主动向客户端发送时间戳

    指令格式

    成功响应格式:

    {
        "event": "info",
        "version": 1
    }
    
    {
        "code": 0,
        "message": "Topic subscription successfully"
    }
    
    {
        "data": < value > ,
        "message": "success",
        "code": 0
    }
    

    失败响应格式(code不为0则为失败):

    {
      "message":"<error_message>",
      "code":<errorCode>
      }
    

    {"op": "<value>", "args": ["<value1>","<value2>"]}

    其中 op 的取值为 1--subscribe 订阅; 2-- unsubscribe 取消订阅

    args: 取值为频道名,可以定义一个或者多个频道(单个用户最多不能超过200个频道)

    订阅

            var token = "XXXX";
            var websocket = new WebSocket("wss://data.block.cc/ws/v3?api_key="+token);
            var reqMsg = "{\"op\": \"subscribe\", \"args\": [\"price:bitcoin\"]}";
            websocket.onerror = function(){
                setMessageInHtml("send error!");
            }
            websocket.onopen = function(){
                setMessageInHtml("connection success!")
            }
            websocket.onmessage  = function(event){
                setMessageInHtml(event.data);
            }
            websocket.onclose = function(){
                setMessageInHtml("closed websocket!")
            }
            window.onbeforeunload = function(){
                 websocket.close(3000,"强制关闭");
            }
            websocket.send(reqMsg);
    
            String token = "XXXX";
            String url = "wss://data.block.cc/ws/v3?api_key="+ token;
            WebSocketClient client =  new WebSocketClient(new URI(url)){
                  @Override
                  public void onOpen(ServerHandshake handshakedata) {
                    log.info("onOpen");
                  }
                  @Override
                  public void onMessage(String message) {
                    log.info("onMessage msg:{}",message);
                  }
                  @Override
                  public void onClose(int code, String reason, boolean remote) {
                    log.info("onClose");
                  }
    
                  @Override
                  public void onError(Exception ex) {
                    log.info("onError");
                  }
              };
              client.connect();
              Thread.sleep(1000);
              client.send("{\"op\": \"subscribe\", \"args\": [\"price:bitcoin\"]}");
    
    from websocket import create_connection
    token="XXXX"
    ws=create_connection("wss://data.block.cc/ws/v3?api_key="+token)
    ws.send("{\"op\": \"subscribe\", \"args\": [\"price:bitcoin\"]}");
    
    result=ws.recv()
    print("Received '%s'" % result)
    ws.close()
    

    将会返回以下内容:

    {
        "message": "success",
        "code": 0,
        "data": {
            "symbolName": "bitcoin",
            "symbol": "BTC",
            "timestamp": 1564201016247,
            "priceUsd": 10254.613,
            "priceBtc": 1.0,
            "volume": 66180.407,
            "volumeUsd": 6.6355183277E8,
            "reportedVolume": 68260.277,
            "reportedVolumeUsd": 6.8489011E8,
            "marketCapUsd": 1.8219371E11
        }
    }
    

    用户可以选择订阅一个或者多个频道,多个频道总个数不能超过200个

    {"op": "subscribe", "args": ["<SubscriptionTopic>"]}

    args 数组内容为频道名称 :<channelname>:<filter>

    其中`channelname 是由ticker、price两种类型组成组成

    例:

    {"op": "subscribe", "args": ["price:bitcoin"]}

    {"op": "subscribe", "args": ["ticker:gate-io:BTC_USDT"]}

    filter 是可筛选数据,具体参考每个频道说明

    取消订阅

            var token = "XXXX";
            var websocket = new WebSocket("wss://data.block.cc/ws/v3?api_key="+token);
            var reqMsg = "{\"op\": \"unsubscribe\", \"args\": [\"price:bitcoin\"]}";
            websocket.onerror = function(){
                setMessageInHtml("send error!");
            }
            websocket.onopen = function(){
                setMessageInHtml("connection success!")
            }
            websocket.onmessage  = function(event){
                setMessageInHtml(event.data);
            }
            websocket.onclose = function(){
                setMessageInHtml("closed websocket!")
            }
            window.onbeforeunload = function(){
                 websocket.close(3000,"强制关闭");
            }
            websocket.send(reqMsg);
    
            String token = "XXXX";
            String url = "wss://data.block.cc/ws/v3?api_key="+ token;
            WebSocketClient client =  new WebSocketClient(new URI(url)){
                  @Override
                  public void onOpen(ServerHandshake handshakedata) {
                    log.info("onOpen");
                  }
                  @Override
                  public void onMessage(String message) {
                    log.info("onMessage msg:{}",message);
                  }
                  @Override
                  public void onClose(int code, String reason, boolean remote) {
                    log.info("onClose");
                  }
    
                  @Override
                  public void onError(Exception ex) {
                    log.info("onError");
                  }
              };
              client.connect();
              Thread.sleep(1000);
              client.send("{\"op\": \"unsubscribe\", \"args\": [\"price:bitcoin\"]}");
    
    from websocket import create_connection
    token="XXXX"
    ws=create_connection("wss://data.block.cc/ws/v3?api_key="+token)
    ws.send("{\"op\": \"unsubscribe\", \"args\": [\"price:bitcoin\"]}");
    
    result=ws.recv()
    print("Received '%s'" % result)
    ws.close()
    
    

    将会返回以下内容

    {
        "message": "Topic unsubscribed successfully",
        "code": 0
    }
    
    

    可以取消一个或者多个频道

    {"op": "unsubscribe", "args": [<SubscriptionTopic>]}

    例如:

    请求:

    {"op": "unsubscribe", "args": ["price:bitcoin"]}

    返回:

    {"message":"Topic unsubscribed successfully","code":0}

    连接限制

    订阅限制:单个连接的订阅主题数不能超过200个

    连接上ws后会主动推送时间戳数据, 建议用户进行以下操作:

    1,每次接收到消息后,用户设置一个定时器 ,定时N秒。

    2,如果定时器被触发(N 秒内没有收到新消息),发送字符串 'ping'。

    3,期待一个文字字符串'pong'作为回应。如果在 N秒内未收到,请发出错误或重新连接。

    出现网络问题会自动断开连接

    price

            var token = "XXXX";
            var websocket = new WebSocket("wss://data.block.cc/ws/v3?api_key="+token);
            var reqMsg = "{\"op\": \"subscribe\", \"args\": [\"price:bitcoin\"]}";
            websocket.onerror = function(){
                setMessageInHtml("send error!");
            }
            websocket.onopen = function(){
                setMessageInHtml("connection success!")
            }
            websocket.onmessage  = function(event){
                setMessageInHtml(event.data);
            }
            websocket.onclose = function(){
                setMessageInHtml("closed websocket!")
            }
            window.onbeforeunload = function(){
                 websocket.close(3000,"强制关闭");
            }
            websocket.send(reqMsg);
    
            String token = "XXXX";
            String url = "wss://data.block.cc/ws/v3?api_key="+ token;
            WebSocketClient client =  new WebSocketClient(new URI(url)){
                  @Override
                  public void onOpen(ServerHandshake handshakedata) {
                    log.info("onOpen");
                  }
                  @Override
                  public void onMessage(String message) {
                    log.info("onMessage msg:{}",message);
                  }
                  @Override
                  public void onClose(int code, String reason, boolean remote) {
                    log.info("onClose");
                  }
    
                  @Override
                  public void onError(Exception ex) {
                    log.info("onError");
                  }
              };
              client.connect();
              Thread.sleep(1000);
              client.send("{\"op\": \"subscribe\", \"args\": [\"price:bitcoin\"]}");
    
    from websocket import create_connection
    token="XXXX"
    ws=create_connection("wss://data.block.cc/ws/v3?api_key="+token)
    ws.send("{\"op\": \"subscribe\", \"args\": [\"price:bitcoin\"]}");
    
    result=ws.recv()
    print("Received '%s'" % result)
    ws.close()
    
    

    将会返回以下内容:

    {
        "message": "Topic subscription successfully",
        "code": 0
    }
    
    {
        "message": "success",
        "code": 0,
        "data": {
            "symbolName": "bitcoin",
            "symbol": "BTC",
            "timestamp": 1564201016247,
            "priceUsd": 10254.613,
            "priceBtc": 1.0,
            "volume": 66180.407,
            "volumeUsd": 6.6355183277E8,
            "reportedVolume": 68260.277,
            "reportedVolumeUsd": 6.8489011E8,
            "marketCapUsd": 1.8219371E11
        }
    }
    

    获取币种价格

    send示例

    {"op": "subscribe", "args": ["price:bitcoin"]}

    其中price为频道名,bitcoin为币种名称

    返回参数

    参数名称 描述
    symbolName 币种名称
    symbol 币种符号
    timestamp 时间戳
    priceUsd 美元价格
    priceBtc 比特币价格
    volume 交易量(单位为当前币种)
    volumeUsd 美元交易量
    reportedVolume 报告量
    reportedVolumeUsd 美元报告量
    marketCapUsd 美元市值

    ticker

            var token = "XXXX";
            var websocket = new WebSocket("wss://data.block.cc/ws/v3?api_key="+token);
            var reqMsg = "{\"op\": \"subscribe\", \"args\": [\"ticker:gate-io:BTC_USDT\"]}";
            websocket.onerror = function(){
                setMessageInHtml("send error!");
            }
            websocket.onopen = function(){
                setMessageInHtml("connection success!")
            }
            websocket.onmessage  = function(event){
                setMessageInHtml(event.data);
            }
            websocket.onclose = function(){
                setMessageInHtml("closed websocket!")
            }
            window.onbeforeunload = function(){
                 websocket.close(3000,"强制关闭");
            }
            websocket.send(reqMsg);
    
            String token = "XXXX";
            String url = "wss://data.block.cc/ws/v3?api_key="+ token;
            WebSocketClient client =  new WebSocketClient(new URI(url)){
                  @Override
                  public void onOpen(ServerHandshake handshakedata) {
                    log.info("onOpen");
                  }
                  @Override
                  public void onMessage(String message) {
                    log.info("onMessage msg:{}",message);
                  }
                  @Override
                  public void onClose(int code, String reason, boolean remote) {
                    log.info("onClose");
                  }
    
                  @Override
                  public void onError(Exception ex) {
                    log.info("onError");
                  }
              };
              client.connect();
              Thread.sleep(1000);
              client.send("{\"op\": \"subscribe\", \"args\": [\"ticker:gate-io:BTC_USDT\"]}");
    
    from websocket import create_connection
    token="XXXX"
    ws=create_connection("wss://data.block.cc/ws/v3?api_key="+token)
    ws.send("{\"op\": \"subscribe\", \"args\": [\"ticker:gate-io:BTC_USDT\"]}");
    
    result=ws.recv()
    print("Received '%s'" % result)
    ws.close()
    
    

    将会返回以下内容:

    {
        "message": "Topic subscription successfully",
        "code": 0
    }
    {
        "message": "success",
        "code": 0,
        "data": {
            "T": 1559203047168,
            "m": "gate-io:BTC_USDT",
            "o": 3.59961E-4,
            "c": 3.8415E-4,
            "l": 1.6394E-4,
            "h": 3.8582E-4,
            "a": 3.8419E-4,
            "A": 0.0,
            "b": 1.6394E-4,
            "B": 0.0,
            "C": 0.0672,
            "bv": 0.0,
            "qv": 0.0,
            "r": 3642.4481,
            "p": null,
            "ap1": 0.0,
            "bp1": 0.0,
            "s": 0.0
        }
    }
    
    

    获取交易对Ticker

    send示例

    {"op": "subscribe", "args": ["ticker:gate-io:BTC_USDT"]}

    其中ticker为频道名,livecoin为交易所名称,TKN_BTC为交易对名称

    返回参数

    参数名称 描述
    T 数据更新时间
    m 交易所名称
    o 开盘价
    c 收盘价
    l 24小时最低价
    h 24小时最高价
    a 卖一价
    A 询问金额
    b 买一价
    B 投标金额
    C 24小时涨幅
    bv 基本量
    qv 报价量
    r 基础转货币转美元的汇率
    p 纯度
    ap1 询问待处理量
    bp1 投标待处理量
    s 传播

    交易所收录

    API 建议

    1. 请使用QueryString或者URLParams方式传参。
    2. 请提供批量获取ticker的接口,以便批量更新价格和交易对。
    3. 如果暂时不能提供批量获取ticker的接口, 请提供获取所有交易对的接口。(不推荐,请求频率高,更新速度慢)
    4. 交易对请尽量使用符号分割或者固定长度。
    5. 正常情况下每分钟请求次数为10次左右。
    6. 接口数据保证稳定真实。

    点此连接 进入交易所收录表单