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: 5956
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
Index to my micropython libraries.

User avatar
mcauser
Posts: 507
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: 4
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.

brittany
Posts: 2
Joined: Mon Jun 28, 2021 11:53 am

Re: Get current Bitcoin price as an integer?

Post by brittany » Tue Jun 29, 2021 9:28 am

McMoe wrote:
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.
I used the API from blockchain.info for getting Bitcoin price data. From a quick glance at their site, it looks like they also offer Ethereum and BCH data.
Updated: I just came across a crypto bot . It is a bot that will trade for you on binance. I suck pretty bad at trading - so, I thought I could find something that could work for me. Tried to research it for some reviews about it . - I think it has a low internet profile right now but it has some good feature any one heard of it.?
Last edited by brittany on Fri Jul 02, 2021 8:46 am, edited 2 times in total.

katesimon123
Posts: 15
Joined: Mon Jun 14, 2021 12:49 am

Re: Get current Bitcoin price as an integer?

Post by katesimon123 » Tue Jun 29, 2021 12:12 pm

brittany wrote:
Tue Jun 29, 2021 9:28 am
I used the API from blockchain.info for getting Bitcoin price data. From a quick glance at their site, it looks like they also offer Ethereum and BCH data.
There must be some data limit on it as on all Blockchain Technology related stuff, how many queries you can make per month for free?
Last edited by katesimon123 on Sun Jul 11, 2021 2:24 am, edited 1 time in total.

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

Re: Get current Bitcoin price as an integer?

Post by McMoe » Thu Jul 01, 2021 8:06 am

Hi katesimon123,

at www.mcmoe.de you can contact them via the contact form at the page (https://www.mcmoe.de/en/contact/), explaining what your needs are and that you would like to test their api. They will reply with a free plan to you having up to 50 - 100 calls a day for free. Altcoin data included, of course, not Bitcoin only.


Hope that helps.

Post Reply