Ask Your Question
0

Importing BTC price to spreadsheet

asked 2018-10-08 20:18:18 +0200

SkyHead gravatar image

Hi, I'm trying to have a live(60sec) updated BTC price on my spreadsheet, I have googled abit but still cant find out what to do, I came over this thread https://ask.libreoffice.org/en/questi...

But I either get #VALUE or all the values from https://www.bitstamp.net/api/ticker/ in text format like they are displayed in the API. I want them to show as numbers i.e. A1: BTC\USD Current B2: The current price of BTC

Please take time to explain in great detail as I only installed it yesterday

Thank you, SkyHead

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2018-10-08 20:37:35 +0200

Ratslinger gravatar image

updated 2018-10-10 07:25:56 +0200

Hello,

This type of question has been asked a number of times. Explanation in detail is not typical as this deals with creating macros specific to your needs and best done in Python. For further information, please see my answer in this post -> link libre base to API on a website,. In the answer are links to other answers some containing code.

Edit 2018-10-09:

Have carried this one step further. Attached is a sample Calc file with the python macro embedded in the document. It utilizes the API in your question. It is executed by a push button on the sheet. This recalls the data and the results are placed in column B. I did not format any results. In some cases I don't even know or care what they are.

Sample --- BTCpython.ods

The python code is overly simplified so as to be somewhat readable for those unknowing. It accesses the data, converts it to a string which is then read in JSON format into data fields. The active sheet in Calc is used and one-by-one the data is moved into cells.

The actual Python code is just a text file named JsonBTC3.py. The macro the push button is connected to is json_btc. It was inserted into the document using APSO; see this post -> Did you know that you could also use APSO to Organize your Python scripts within LibreOffice?. I have created a small manual for embedding the script in a document using APSO; it is in my answer here -> Can I embed python script and integrate with basic? (solved)

Going beyond this creates too many ifs ands and where by's.

edit flag offensive delete link more

Comments

I have made the python.py script Tried "python pyhton.py CoinCalc.ods" and get returned Bitcoin 6613.76231894

How do I load that macro into LO? Should it be *.py extension when I load it? I use manjaro linux\mate DE

This is the code I stole from you, as I have no python skills.

import json
from urllib.request import urlopen

url = urlopen('https://api.coinmarketcap.com/v1/ticker/')
obj = json.load(url)
if int(obj[0]['rank']) == 1:
coin_name = obj[0]['name']

SkyHead gravatar imageSkyHead ( 2018-10-09 18:58:50 +0200 )edit

Thank you for this :)

SkyHead gravatar imageSkyHead ( 2018-10-10 18:11:53 +0200 )edit

As you have been helped, please help others to know the question has been answered by clicking on the ✔ in upper left area of answer which satisfied the question.

Ratslinger gravatar imageRatslinger ( 2018-10-10 18:15:53 +0200 )edit
0

answered 2018-10-09 18:55:25 +0200

SkyHead gravatar image

updated 2018-10-09 18:57:57 +0200

I have made the python.py script Tried "python pyhton.py CoinCalc.ods" and get returned Bitcoin 6613.76231894

How do I load that macro into LO? Should it be *.py extension when I load it? I use manjaro linux\mate DE

This is the code I stole from you, as I have no python skills.

import json
from urllib.request import urlopen

url = urlopen('https://api.coinmarketcap.com/v1/ticker/')
obj = json.load(url)
if int(obj[0]['rank']) == 1:
coin_name = obj[0]['name']
coin_price = obj[0]['price_usd']
print(coin_name)
print(coin_price)

edit flag offensive delete link more

Comments

Please do not respond using an answer. Either add a comment or if more room is needed edit original question and add there noting the edited information.

Since you have no Python skills, how are you going to maintain this when the API changes? There is much more to this than what you may picture. Once the info is obtained, code is needed to put in the spreadsheet. Also more code is needed for you to automatically retrieve the info on a repeated basis automatically. Much more to consider.

Ratslinger gravatar imageRatslinger ( 2018-10-09 19:34:02 +0200 )edit

There is no easier way?

SkyHead gravatar imageSkyHead ( 2018-10-09 19:59:58 +0200 )edit

It is the easiest way I know currently.

Ratslinger gravatar imageRatslinger ( 2018-10-09 20:02:34 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-10-08 20:18:18 +0200

Seen: 201 times

Last updated: Oct 10 '18