Member-only story

Binance & Coingecko API With Python — Getting Crypto Prices Easily

Liu Zuo Lin
4 min readDec 4, 2021

--

If you just want to get cryptocurrency prices using Python without having to read through pages and pages of documentation, this article is for you.

Some Prior Setup

We need to first install the Python requests library if you haven’t already

pip install requests # for Windowspip3 install requests # for MacOS

Note: this is supposed to be typed inside command prompt or terminal, not Python code.

Getting Price of 1 Coin/Token With Binance API

Note that this API is public API, and we don’t need an API key

Input → Symbol of the coin/token

Output → Price of the coin/token

What we need

  • The symbol of the coin/token we want the price of

The Code

import requestsbase_url = "https://api.binance.com/api/v3"
symbol = "BTC"
url = base_url + f"/avgPrice?symbol={symbol}USDT"r = requests.get(url)
print(r.json())

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

No responses yet