Get current Bitcoin price as an integer?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
slowcheetah
Posts: 2
Joined: Mon May 01, 2017 10:35 am

Get current Bitcoin price as an integer?

Post by slowcheetah » Thu May 25, 2017 3:06 pm

I want to try something out:

An ESP module that constantly checks the current bitcoin price and compares it to the previous value, whereafter it turns on either a red led if it's lower or a green one if it's higher. The logic for the script seems pretty easy for me, except for which option would be best for actually getting the current Bitcoin value in my own currency, which is ZAR (South African Rand).

First thing I can think of is with a GET request, but I'm a little unsure about how to go about getting that actual value into Micropython.

If I do a straightforward Google search with: 'bitcointozar' in my browser, I get the value I'm looking for. How does that translate to the microcontroller doing the search instead of me in a browser? I've been trying with the urequests module, but I'm a little lost. any nudge in the right direction would be awesome, thanks!

User avatar
pythoncoder
Posts: 5148
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Get current Bitcoin price as an integer?

Post by pythoncoder » Thu May 25, 2017 5:22 pm

You might find some useful hints here https://hackaday.com/2017/05/21/bitcoin-price-ticker/.
Peter Hinch

User avatar
mcauser
Posts: 493
Joined: Mon Jun 15, 2015 8:03 am

Re: Get current Bitcoin price as an integer?

Post by mcauser » Sun Jun 04, 2017 12:56 pm

I made this, which get requests the coinbase api, parses the json and outputs on a Nokia 5110 display.
https://github.com/mcauser/MicroPython- ... 10-Bitcoin

Connect to your wifi:

Code: Select all

import network
sta_if = network.WLAN(network.STA_IF);
sta_if.active(True)
sta_if.scan()
sta_if.connect("ssid","pass")
Install urequests with upip:

Code: Select all

import upip
upip.install('micropython-urequests')
Reboot and make a get request:

Code: Select all

import urequests

try:
	r = urequests.get("http://api.coindesk.com/v1/bpi/currentprice/AUD.json")
	rate = '%d' % r.json()['bpi']['AUD']['rate_float']
	r.close()
except KeyError:
	rate = "0"
print(rate)
Looking at the api, http://www.coindesk.com/api/ - ZAR is a supported country, so you can get a price by requesting: http://api.coindesk.com/v1/bpi/currentprice/ZAR.json

johnmeller
Posts: 1
Joined: Mon Nov 18, 2019 11:03 am

Re: Get current Bitcoin price as an integer?

Post by johnmeller » Sun Nov 24, 2019 11:11 am

You can try API from coinbase: https://developers.coinbase.com/api/v2. However, I haven't used it till now, so I can't say how safe or trustworthy it is. You may want to read about safety of coinbase here:
https://www.cryptopolitan.com/is-coinbase-safe/

User avatar
McMoe
Posts: 3
Joined: Tue Apr 13, 2021 9:57 am
Contact:

Re: Get current Bitcoin price as an integer?

Post by McMoe » Tue Apr 13, 2021 10:05 am

Hi slowcheetah,

i developed a micropython repository for tracking coinprices via api.mcmoe.de. That includes bitcoin as well as hundreds of altcoins. Check this repository https://github.com/McMoes/Crypto-Ticker. You can install it on your esp32 and display realtime prices on max7219 displays. Pecentage development is an option too. If you want to test something via the used API don't hesitate to contact support@mcmoe.de. The API ist live, but the homepage is still under development. Of course you can modify the code using another API if you want.

Post Reply