vittominacori/coinmarketcap-php

CoinMarketCap API的PHP封装器

v1.1.0 2019-12-08 16:57 UTC

This package is auto-updated.

Last update: 2024-09-09 03:11:28 UTC


README

用于CoinMarketCap 专业API的PHP封装器

注意:仅限免费API。请在此查看功能列表。

安装

composer require vittominacori/coinmarketcap-php

用法

创建客户端

$cmc = new CoinMarketCap\Api('yourApiClient');

调用加密货币API

map

返回所有加密货币到唯一的CoinMarketCap id的映射。根据我们的最佳实践,我们建议使用CMC ID而不是加密货币符号,以安全地识别我们的其他端点和您的应用程序逻辑中的加密货币。每个返回的加密货币都包括典型的标识符,如namesymboltoken_address,以便灵活地映射到id

默认情况下,此端点返回在支持的交易所上有活跃跟踪市场的加密货币。通过传递listing_status=inactive,您可能会收到所有非活跃加密货币的映射。您还可以通过传递listing_status=untracked来接收已列出但尚未满足通过listing_status=untracked跟踪市场的必要方法的注册加密货币项目的映射。

返回的加密货币包括first_historical_datalast_historical_data时间戳,以便方便地引用可用查询的历史时间序列数据端点的历史日期范围。您还可以使用aux参数仅包括您需要的属性,以在频繁调用此端点时精简有效负载。

参数

  • (string) listing_status - 默认 "active" - 默认情况下返回所有活跃的加密货币。传递 "inactive" 以获取不再活跃的加密货币列表。传递 "untracked" 以获取尚未满足通过 "untracked" 跟踪市场的必要方法的已列出加密货币列表。您可以传递一个或多个逗号分隔的值。
  • (integer >= 1) start - 默认 1 - 可选地偏移要返回的分页项目列表的起始位置(基于1的索引)。
  • (integer [1 .. 5000]) limit - 默认 100 - 可选地指定要返回的结果数量。使用此参数和“start”参数以确定自己的分页大小。
  • (string) sort - 默认 "id" - 有效值:“cmc_rank”,“id” - 要按什么字段对加密货币列表进行排序。
  • (string) symbol - 可选地传递逗号分隔的加密货币符号列表,以返回CoinMarketCap ID。如果传递此选项,则忽略其他选项。
  • (string) aux - 默认 "platform,first_historical_data,last_historical_data,is_active" - 可选地指定要返回的补充数据字段列表。传递 “platform,first_historical_data,last_historical_data,is_active,status” 以包含所有辅助字段。
$response = $cmc->cryptocurrency()->map(['limit' => 3]);
{
  "status": {
    "timestamp": "2019-12-08T16:29:05.373Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 11,
    "credit_count": 1,
    "notice": null
  },
  "data": [
    {
      "id": 1,
      "name": "Bitcoin",
      "symbol": "BTC",
      "slug": "bitcoin",
      "is_active": 1,
      "rank": 1,
      "first_historical_data": "2013-04-28T18:47:21.000Z",
      "last_historical_data": "2019-12-08T16:24:00.000Z",
      "platform": null
    },
    {
      "id": 2,
      "name": "Litecoin",
      "symbol": "LTC",
      "slug": "litecoin",
      "is_active": 1,
      "rank": 6,
      "first_historical_data": "2013-04-28T18:47:22.000Z",
      "last_historical_data": "2019-12-08T16:24:00.000Z",
      "platform": null
    },
    {
      "id": 3,
      "name": "Namecoin",
      "symbol": "NMC",
      "slug": "namecoin",
      "is_active": 1,
      "rank": 384,
      "first_historical_data": "2013-04-28T18:47:22.000Z",
      "last_historical_data": "2019-12-08T16:24:00.000Z",
      "platform": null
    }
  ]
}

info

返回一个或多个加密货币的所有静态元数据。这些信息包括如标志、描述、官方网站URL、社交媒体链接以及指向加密货币技术文档的链接。

参数

  • (string) id - 一个或多个逗号分隔的CoinMarketCap加密货币ID。
  • (string) slug - 或者传递逗号分隔的加密货币slugs列表。
  • (string) symbol - 或者传递一个或多个逗号分隔的加密货币符号。对于此请求至少需要一个 "id" 或 "slug" 或 "symbol"。
  • (string) aux - 默认 "urls,logo,description,tags,platform,date_added,notice" - 可选地指定要返回的补充数据字段列表。传递 “urls,logo,description,tags,platform,date_added,notice,status” 以包含所有辅助字段。
$response = $cmc->cryptocurrency()->info(['symbol' => 'BTC']);
{
  "status": {
    "timestamp": "2019-12-08T16:32:46.310Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 8,
    "credit_count": 1,
    "notice": null
  },
  "data": {
    "BTC": {
      "urls": {
        "website": [
          "https://bitcoin.org/"
        ],
        "technical_doc": [
          "https://bitcoin.org/bitcoin.pdf"
        ],
        "twitter": [
          
        ],
        "reddit": [
          "https://reddit.com/r/bitcoin"
        ],
        "message_board": [
          "https://bitcointalk.org"
        ],
        "announcement": [
          
        ],
        "chat": [
          
        ],
        "explorer": [
          "https://blockchain.coinmarketcap.com/chain/bitcoin",
          "https://blockchain.info/",
          "https://live.blockcypher.com/btc/",
          "https://blockchair.com/bitcoin",
          "https://explorer.viabtc.com/btc"
        ],
        "source_code": [
          "https://github.com/bitcoin/"
        ]
      },
      "logo": "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png",
      "id": 1,
      "name": "Bitcoin",
      "symbol": "BTC",
      "slug": "bitcoin",
      "description": "Bitcoin (BTC) is a consensus network that enables a new payment system and a completely digital currency. Powered by its users, it is a peer to peer payment network that requires no central authority to operate. On October 31st, 2008, an individual or group of individuals operating under the pseudonym \"Satoshi Nakamoto\" published the Bitcoin Whitepaper and described it as: \"a purely peer-to-peer version of electronic cash, which would allow online payments to be sent directly from one party to another without going through a financial institution.\"",
      "notice": null,
      "date_added": "2013-04-28T00:00:00.000Z",
      "tags": [
        "mineable"
      ],
      "platform": null,
      "category": "coin"
    }
  }
}

listings/latest

返回所有活跃加密货币的最新市场数据的分页列表。默认的 "market_cap" 排序按 CoinMarketCap 的市值排名顺序排列加密货币,但您可以通过配置此调用按其他市场排名字段排序。使用 "convert" 选项在单个调用中返回多种法定货币和加密货币的市值转换。

参数

  • (integer >= 1) start - 默认 1 - 可选地偏移要返回的分页项目列表的起始位置(基于1的索引)。
  • (integer [1 .. 5000]) limit - 默认 100 - 可选地指定要返回的结果数量。使用此参数和“start”参数以确定自己的分页大小。
  • (整数 [1 .. 100000000000]) volume_24h_min - 可选指定一个最低24小时美元交易量的阈值来筛选结果。
  • (字符串) convert - 可选一次性计算最多120种货币的市场报价,通过传递逗号分隔的加密货币或法定货币符号列表。除第一个转换选项之外,每个额外的转换选项都需要额外的调用信用。支持的法定货币选项列表可以在 这里 找到。每个转换都返回自己的 "quote" 对象。
  • (字符串) convert_id - 可选通过 CoinMarketCap ID 而不是符号来计算市场报价。此选项在 ID 格式外与 convert 选项相同。例如,convert_id=1,2781 将替换查询中的 convert=BTC,USD。此参数在使用 convert 时不能使用。
  • (字符串) sort - 默认 "market_cap" - 有效值:"name"、"symbol"、"date_added"、"market_cap"、"market_cap_strict"、"price"、"circulating_supply"、"total_supply"、"max_supply"、"num_market_pairs"、"volume_24h"、"percent_change_1h"、"percent_change_24h"、"percent_change_7d"、"market_cap_by_total_supply_strict"、"volume_7d"、"volume_30d" - 排序加密货币列表的字段。
  • (字符串) sort_dir - 有效值:"asc"、"desc" - 按指定排序对加密货币进行排序的方向。
  • (字符串) cryptocurrency_type - 默认 "all" - 有效值:"all"、"coins"、"tokens" - 要包含的加密货币类型。
  • (字符串) aux - 默认 "num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply" - 可选指定要返回的补充数据字段的逗号分隔列表。传递 num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply,market_cap_by_total_supply,volume_24h_reported,volume_7d,volume_7d_reported,volume_30d,volume_30d_reported 以包含所有辅助字段。
$response = $cmc->cryptocurrency()->listingsLatest(['limit' => 3, 'convert' => 'EUR']);
{
  "status": {
    "timestamp": "2019-12-08T16:45:07.024Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 13,
    "credit_count": 1,
    "notice": null
  },
  "data": [
    {
      "id": 1,
      "name": "Bitcoin",
      "symbol": "BTC",
      "slug": "bitcoin",
      "num_market_pairs": 7761,
      "date_added": "2013-04-28T00:00:00.000Z",
      "tags": [
        "mineable"
      ],
      "max_supply": 21000000,
      "circulating_supply": 18090537,
      "total_supply": 18090537,
      "platform": null,
      "cmc_rank": 1,
      "last_updated": "2019-12-08T16:44:34.000Z",
      "quote": {
        "EUR": {
          "price": 6847.517756176467,
          "volume_24h": 13737233429.06731,
          "percent_change_1h": -0.581249,
          "percent_change_24h": 0.0896832,
          "percent_change_7d": 2.3688917,
          "market_cap": 123875273326.26735,
          "last_updated": "2019-12-08T16:44:01.000Z"
        }
      }
    },
    {
      "id": 1027,
      "name": "Ethereum",
      "symbol": "ETH",
      "slug": "ethereum",
      "num_market_pairs": 5360,
      "date_added": "2015-08-07T00:00:00.000Z",
      "tags": [
        "mineable"
      ],
      "max_supply": null,
      "circulating_supply": 108843495.0615,
      "total_supply": 108843495.0615,
      "platform": null,
      "cmc_rank": 2,
      "last_updated": "2019-12-08T16:44:24.000Z",
      "quote": {
        "EUR": {
          "price": 136.75609521817026,
          "volume_24h": 5620634248.804599,
          "percent_change_1h": -0.336326,
          "percent_change_24h": 1.29639,
          "percent_change_7d": 0.4907828,
          "market_cap": 14885011374.50894,
          "last_updated": "2019-12-08T16:44:01.000Z"
        }
      }
    },
    {
      "id": 52,
      "name": "XRP",
      "symbol": "XRP",
      "slug": "xrp",
      "num_market_pairs": 513,
      "date_added": "2013-08-04T00:00:00.000Z",
      "tags": [
        
      ],
      "max_supply": 100000000000,
      "circulating_supply": 43285660917,
      "total_supply": 99991237614,
      "platform": null,
      "cmc_rank": 3,
      "last_updated": "2019-12-08T16:44:05.000Z",
      "quote": {
        "EUR": {
          "price": 0.20916204859139653,
          "volume_24h": 969887537.110283,
          "percent_change_1h": -0.804959,
          "percent_change_24h": 1.95611,
          "percent_change_7d": 3.58259604,
          "market_cap": 9053717512.032267,
          "last_updated": "2019-12-08T16:44:01.000Z"
        }
      }
    }
  ]
}

quotes/latest

返回1个或多个加密货币的最新市场报价。使用 "convert" 选项在单个调用中返回多种法定货币和加密货币的市值转换。

参数

  • (string) id - 一个或多个逗号分隔的CoinMarketCap加密货币ID。
  • (string) slug - 或者传递逗号分隔的加密货币slugs列表。
  • (string) symbol - 或者传递一个或多个逗号分隔的加密货币符号。对于此请求至少需要一个 "id" 或 "slug" 或 "symbol"。
  • (字符串) convert - 可选一次性计算最多120种货币的市场报价,通过传递逗号分隔的加密货币或法定货币符号列表。除第一个转换选项之外,每个额外的转换选项都需要额外的调用信用。支持的法定货币选项列表可以在 这里 找到。每个转换都返回自己的 "quote" 对象。
  • (字符串) convert_id - 可选通过 CoinMarketCap ID 而不是符号来计算市场报价。此选项在 ID 格式外与 convert 选项相同。例如,convert_id=1,2781 将替换查询中的 convert=BTC,USD。此参数在使用 convert 时不能使用。
  • (字符串) aux - 默认 "num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply" - 可选指定要返回的补充数据字段的逗号分隔列表。传递 num_market_pairs,cmc_rank,date_added,tags,platform,max_supply,circulating_supply,total_supply,market_cap_by_total_supply,volume_24h_reported,volume_7d,volume_7d_reported,volume_30d,volume_30d_reported 以包含所有辅助字段。
  • (布尔值) skip_invalid - 默认 false - 传递 true 以放宽请求验证规则。当请求多个加密货币的记录时,如果没有找到1个或多个请求的加密货币,则返回错误。如果设置为 true,则将跳过无效查找,同时仍返回有效的加密货币。
$response = $cmc->cryptocurrency()->quotesLatest(['id' => 1, 'convert' => 'EUR']);
{
  "status": {
    "timestamp": "2019-12-08T16:50:02.600Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 17,
    "credit_count": 1,
    "notice": null
  },
  "data": {
    "1": {
      "id": 1,
      "name": "Bitcoin",
      "symbol": "BTC",
      "slug": "bitcoin",
      "num_market_pairs": 7761,
      "date_added": "2013-04-28T00:00:00.000Z",
      "tags": [
        "mineable"
      ],
      "max_supply": 21000000,
      "circulating_supply": 18090537,
      "total_supply": 18090537,
      "platform": null,
      "cmc_rank": 1,
      "last_updated": "2019-12-08T16:49:31.000Z",
      "quote": {
        "EUR": {
          "price": 6846.048756240301,
          "volume_24h": 13780116049.701561,
          "percent_change_1h": -0.573398,
          "percent_change_24h": 0.0698591,
          "percent_change_7d": 2.34665175,
          "market_cap": 123848698328.56917,
          "last_updated": "2019-12-08T16:49:01.000Z"
        }
      }
    }
  }
}

调用 GlobalMetrics API

quotes/latest

返回最新的全球加密货币市场指标。使用 "convert" 选项在单个调用中返回多种法定货币和加密货币的市值转换。

参数

  • (字符串) convert - 可选一次性计算最多120种货币的市场报价,通过传递逗号分隔的加密货币或法定货币符号列表。除第一个转换选项之外,每个额外的转换选项都需要额外的调用信用。支持的法定货币选项列表可以在 这里 找到。每个转换都返回自己的 "quote" 对象。
  • (字符串) convert_id - 可选通过 CoinMarketCap ID 而不是符号来计算市场报价。此选项在 ID 格式外与 convert 选项相同。例如,convert_id=1,2781 将替换查询中的 convert=BTC,USD。此参数在使用 convert 时不能使用。
$response = $cmc->globalMetrics()->quotesLatest(['convert' => 'EUR']);
{
  "status": {
    "timestamp": "2019-12-08T16:52:15.834Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 14,
    "credit_count": 1,
    "notice": null
  },
  "data": {
    "active_cryptocurrencies": 3202,
    "total_cryptocurrencies": 4904,
    "active_market_pairs": 20818,
    "active_exchanges": 614,
    "total_exchanges": 844,
    "eth_dominance": 8.01647,
    "btc_dominance": 66.7296,
    "quote": {
      "EUR": {
        "total_market_cap": 185597924909.75104,
        "total_volume_24h": 45763346301.02166,
        "total_volume_24h_reported": 50288735661.71643,
        "altcoin_volume_24h": 31983230251.320095,
        "altcoin_volume_24h_reported": 35040992890.64553,
        "altcoin_market_cap": 61749226581.18235,
        "last_updated": "2019-12-08T16:51:01.000Z"
      }
    },
    "last_updated": "2019-12-08T16:50:00.000Z"
  }
}

调用 Tools API

price-conversion

使用每种货币的最新市场汇率将一种加密货币或法定货币的金额转换为一种或多种不同的货币。您可以选择传递历史时间戳作为时间,以便根据历史汇率转换值(根据您的API计划支持)。

参数

  • (数字 [1e-8 .. 1000000000]) amount - 要转换的货币金额。
  • (字符串) id - 要转换的基础加密货币或法定货币的 CoinMarketCap 货币ID。
  • (字符串) symbol - 或者是基础加密货币或法定货币的货币符号。
  • (字符串) time - 可选的时间戳(Unix或ISO 8601),在转换时参考历史定价。如果不传递,将使用当前时间。如果传递,我们将参考此转换可用的最接近的历史值。
  • (字符串) convert - 传递最多120个逗号分隔的法定货币或加密货币符号,将源金额转换为这些货币。
$response = $cmc->tools()->priceConversion(['amount' => 1, 'symbol' => 'BTC']);
{
  "status": {
    "timestamp": "2019-12-08T15:41:33.518Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 8,
    "credit_count": 1,
    "notice": null
  },
  "data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2019-12-08T15:40:32.000Z",
    "quote": {
      "USD": {
        "price": 7616.58696412,
        "last_updated": "2019-12-08T15:40:32.000Z"
      }
    }
  }
}

调用 Partners API

flipside-crypto/fcas/listings/latest

返回所有目前由FCAS支持的加密货币的FCAS评分分页列表。FCAS评分在0-1000分的范围内,对应相应的字母等级,并在UTC午夜时分更新一次。

参数

  • (integer >= 1) start - 默认 1 - 可选地偏移要返回的分页项目列表的起始位置(基于1的索引)。
  • (整数 [1 .. 5000]) limit - 默认100 - 可选指定返回结果的数量。使用此参数和“start”参数来决定自己的分页大小。
  • (字符串) aux - 默认 "point_change_24h,percent_change_24h" - 可选指定要返回的补充数据字段的逗号分隔列表。传递 point_change_24h,percent_change_24h 以包括所有辅助字段。
$response = $cmc->partners()->flipsideFCASListingLatest(['limit' => 3]);
{
  "status": {
    "timestamp": "2019-12-08T16:04:04.084Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 5,
    "credit_count": 1,
    "notice": null
  },
  "data": [
    {
      "id": 1027,
      "name": "Ethereum",
      "symbol": "ETH",
      "slug": "ethereum",
      "score": 936,
      "grade": "S",
      "last_updated": "2019-12-08T00:00:00Z"
    },
    {
      "id": 1765,
      "name": "EOS",
      "symbol": "EOS",
      "slug": "eos",
      "score": 929,
      "grade": "S",
      "last_updated": "2019-12-08T00:00:00Z"
    },
    {
      "id": 1,
      "name": "Bitcoin",
      "symbol": "BTC",
      "slug": "bitcoin",
      "score": 907,
      "grade": "S",
      "last_updated": "2019-12-08T00:00:00Z"
    }
  ]
}

flipside-crypto/fcas/quotes/latest

返回1个或多个加密货币的最新FCAS评分。FCAS评分在0-1000分的范围内,对应相应的字母等级,并在UTC午夜时分更新一次。

参数

  • (字符串) id - 一个或多个用逗号分隔的加密货币CoinMarketCap ID。
  • (string) slug - 或者传递逗号分隔的加密货币slugs列表。
  • (字符串) symbol - 或者传递一个或多个用逗号分隔的加密货币符号。例如:"BTC,ETH"。此请求至少需要一个 "id" 或 "slug" 或 "symbol"。
  • (字符串) aux - 默认 "point_change_24h,percent_change_24h" - 可选指定要返回的补充数据字段的逗号分隔列表。传递 point_change_24h,percent_change_24h 以包括所有辅助字段。
$response = $cmc->partners()->flipsideFCASQuotesLatest(['symbol' => 'BTC']);
{
  "status": {
    "timestamp": "2019-12-08T16:16:15.082Z",
    "error_code": 0,
    "error_message": null,
    "elapsed": 6,
    "credit_count": 1,
    "notice": null
  },
  "data": {
    "BTC": {
      "id": 1,
      "name": "Bitcoin",
      "symbol": "BTC",
      "slug": "bitcoin",
      "score": 907,
      "grade": "S",
      "last_updated": "2019-12-08T00:00:00Z",
      "percent_change_24h": 0.11,
      "point_change_24h": 1
    }
  }
}

许可证

代码在MIT许可证下发布。