CoinMarketCap v1 API中的fetching数据模块

CoinMarketCapA的Python项目详细描述


CoveragePythonVersionLicense

共同市场

coinmarketcap的v1 api的python实现。

您需要coinmarketcap中的api密钥才能利用此模块,您可以从here中获取密钥。由于请求率较低,我建议您在沙盒环境中测试应用程序。在使用它们的沙盒环境时,您需要一个不同的api密钥,您可以从here中获取该密钥。

安装

python3 -m pip install CoinMarketCapAPI

身份验证

如果在init期间没有提供键,模块将在$HOME/.coinmarketcap.json中查找json文件,语法如下。

{"sandbox":"API_KEY","production":"API_KEY"}

或者,可以将密钥设置为os环境变量。使用.bashrc,添加以下两行。

export COINMARKETCAP_SANDBOX="API_KEY"
export COINMARKETCAP_PRODUCTION="API_KEY"

示例

带有api密钥的init客户端。

fromcoinmarketcapimportClientkey="API_KEY"client=Client(apikey=key)```requestlimitThefollowingexampleshowshowyoucanaccessandsendarequesttoeachofCoinMarketCap's endpoint (cryptocurrency, exchange, global_metrics, tools). Notice plural and singular method endings. Plurals allow a list of `id`, `symbol` or `slug`, singular allows only a single value.```pythonfromcoinmarketcapimportClientfromdatetimeimportdatetime# Init sandbox client.client=Client(sandbox=True)# fetch cryptocurrency infoclient.cryptocurrency.info.symbols(["BTC","ETH"])client.cryptocurrency.info.ids(1)# fetch exchange infoclient.exchange.info.slugs("binance")client.exchange.info.ids([1,4])# fetch global market datatime=datetime.strptime("2018-12-21","%Y-%m-%d")client.global_metrics.quotes.latest()client.global_metrics.quotes.historical(time_start=time)amount_1=100.4amount_2="901.23"id=4# convert price historic priceclient.tools.price.convert_id(amount_1,id,time=time)client.tools.price.convert_symbol(amount_2,"BTC",convert=["USD","ETH"])

由于coinmarketcap的信用和利率限制系统,实现一个适当的请求节流器是复杂的。无论如何,我尝试了三种不同级别的节流。”分、日、月。每一级都要确保你没有超过给定计划的请求限制。不同层次的人对coinmarketcap的信用体系没有认识…

fromcoinmarketcapimportClient# By default throttling of requests are off.# Ignore the Client's keyword arguments "throttle", "plan", and "block" if# you don't want the client to throttle requests.  # client_1 will not exceed the number of request each minute with the basic plan.client_1=Client(throttle="minute",plan="basic")# client_2 will not exceed the daily request limit.client_2=Client(throttle="daily",block=True,plan="hobbyist")# client_3 will never exceeded CoinMarketCap monthly request rate.client_3=Client(throttle="monthly",block=False,plan="professional")

每个请求都被缓存,数据的过期时间可以用关键字参数expire调整。如果不需要任何缓存数据,请设置expire=0

fromcoinmarketcapimportClient# cached request will be removed after 1 secondclient=Client(expire=1)# cacherd request will be removed after 1 hclient=Client(expire=3600)# To remove all data from the cache, use the method clear_cacheclient.clear_cache()

待办事项

  • 启用请求的适当限制。
  • 测试不同的python版本。

这是我的第一个python模块。因此,我非常感谢您的反馈:)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将UDP消息从桌面发送到移动设备?   java DefaultMessageListenerContainer使用JMX+ActiveMQ在单个队列上管理多个使用者   java CMU Sphinx:Voxforge德国型号不精确   java生成一个定制的lastIndexOf方法   java生成pdf PDFBox无头docker容器失败   java实例化HashMap中存储的类的实例   java将JAAS表单身份验证传递给REST服务   爪哇:Tomcat。伊奥。IOException:无法创建目标“xxx”目录“   java GoogleTokenResponse未执行。。!   java Lastmodified标头在第二次刷新后不工作   java Android onClickListener没有注册点击(我想)   当引导调用远程模式时,不会加载java Google reCaptcha   java将二进制字符串转换为字节数组   java为JPA本机查询的结果分配ID的最简单方法是什么?   java上的数组参数行为   组织中的java字段数据源。O7计划。关于公司。MainController需要“javax”类型的bean。sql。找不到“数据源”   java如何使用selenium在excel文件中查找字符串的位置   java Hibernate注释。如何注释?   在Java中反转字符串时出错