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结合两个Date实例使用Joda创建datetime   带有POI和FileOutputStream的java Swing应用程序性能问题   Java中是否存在类似于Python的异常?   Java中有界通配符的泛型   使用字符和子字符串的java不同输出   在Java中获取LDAP模式   java自定义类在自身上生成ClassNotFoundException   java连接到从internet到通过LAN连接到internet的系统的serversocket   java如何通过maven在jaxws中使用jaxb插件?   java Kerberos如何获取主体或客户端名称?   java应用服务器中是否有JDBC的单点登录解决方案?   java是存储矩阵值以便以后访问的更好方法   Java等级计算器。开始这门课我需要一些帮助   未找到Android“libc++\u shared.so”中的java OpenCV实现   当我使用web配置部署描述符时使用java。xml。它显示了错误   java为什么我的ArrayList的add方法冲突,如何编辑我的自定义add方法   java创建一个以集合为键的映射?   java如何将用户输入到数字三角形中   为什么Java在读取LinkedHashMap时会自动从字符串转换为整数   类动态创建和读取java类