adriantimofti / coinmarketcap-php-api
CoinMarketCap API 的 PHP 封装器
Requires
- php: >=7.0.0
- ext-curl: *
- ext-json: *
- mashape/unirest-php: ^3.0
This package is not auto-updated.
Last update: 2024-09-28 07:56:57 UTC
README
PHP 封装 CoinMarketCap Professional API
注意:仅限免费 API。请在此处查看功能列表 此处。
安装
composer require AdrianTimofti/coinmarketcap-php-api
使用方法
创建客户端
$cmc = new CoinMarketCapPhpApi\Api('yourApiClient');
调用加密货币 API
map
返回所有加密货币到唯一的 CoinMarketCap id
的映射。根据我们的最佳实践,我们建议使用 CMC ID 而不是加密货币符号,以确保使用我们的其他端点和您自己的应用程序逻辑安全地识别加密货币。每个返回的加密货币都包含典型的标识符,例如 name
、symbol
和 token_address
,以便灵活地将它们映射到 id
。
默认情况下,此端点返回在支持的交易所上活跃跟踪市场的加密货币。您可以通过传递 listing_status=inactive
来接收所有不活跃的加密货币的映射。您也可以通过传递 listing_status=untracked
来接收已列出但尚未满足方法论要求以通过 listing_status=untracked
跟踪市场的注册加密货币项目的映射。
返回的加密货币包括 first_historical_data
和 last_historical_data
时间戳,以便方便地引用可查询的历史日期范围。您还可以使用 aux
参数仅包含您需要的属性,以在频繁调用此端点时减小有效负载。
参数
- (string)
listing_status
- 默认 "active" - 默认情况下仅返回活跃的加密货币。传递inactive
获取不再活跃的加密货币列表。传递untracked
获取已列出但尚未满足方法论要求以通过listing_status=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
- 或者传递逗号分隔的加密货币 slug 列表。 - (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种货币的市场报价。超出第一个convert选项的额外convert选项需要额外的调用信用。支持的各种法定货币选项列表可以在此找到这里。每个转换都返回其自己的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
- 或者传递逗号分隔的加密货币 slug 列表。 - (string)
symbol
- 或者传递一个或多个逗号分隔的加密货币符号。对于此请求至少需要一个 "id"、"slug" 或 "symbol"。 - (字符串)
convert
- 可选:通过传递以逗号分隔的加密货币或法定货币符号列表,一次计算最多120种货币的市场报价。超出第一个convert选项的额外convert选项需要额外的调用信用。支持的各种法定货币选项列表可以在此找到这里。每个转换都返回其自己的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种货币的市场报价。超出第一个convert选项的额外convert选项需要额外的调用信用。支持的各种法定货币选项列表可以在此找到这里。每个转换都返回其自己的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
- 或者传递逗号分隔的加密货币 slug 列表。 - (字符串)
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许可协议下发布。