As the price of Bitcoin soars, the skin of greed is squeezed, and it tends to reload the price chart of the site. I made a simple script to display Bitcoin at regular intervals on the command line terminal.
Prices in USD are subtracted from Coindesk and prices in JPY are subtracted from CoinCheck. There is no particular reason for choosing these two sites. I think that the services of each site will be canceled over time, so I think that you should change to the one that can be used at that time.
The 8th line specifies the time interval for fetching price information, and the 11th line specifies the amount of Bitcoin you have.
loop_btc_price.py
btcuser01@ubuntu002:~/Price$ cat -n loop_btc_price.py
1 #!/usr/bin/python3
2
3 import requests
4 import time
5 import datetime
6
7 # Interval to check btc price in second
8 interval=60
9
10 # BTC which you have
11 btc_you_have=6.04
12
13 COINCHEK_API_URL = 'https://coincheck.com/api/ticker'
14 def get_price_jpy_coincheck():
15
16 response = requests.get(COINCHEK_API_URL)
17 response_json = response.json()
18 # print(response_json)
19 return(response_json["last"])
20
21
22 COINDESK_API_URL = 'https://api.coindesk.com/v1/bpi/currentprice.json'
23 def get_price_usd_coindesk():
24 response = requests.get(COINDESK_API_URL)
25 response_json = response.json()
26 # print(response_json)
27 return(float(response_json["bpi"]["USD"]["rate"].replace(',','')))
28
29
30 while True:
31 dt_now = datetime.datetime.now()
32 usd_a_btc=get_price_usd_coindesk()
33 jpy_a_btc=get_price_jpy_coincheck()
34 # print(dt_now.strftime("%y/%m/%d %H:%M:%S"),usd_a_btc,jpy_a_btc,jpy_a_btc * btc_you_have)
35 print("{:s}, {:.2f}, {:d}, {:d}".format(dt_now.strftime("%y/%m/%d %H:%M:%S"),
36 usd_a_btc,
37 int(jpy_a_btc),
38 int(jpy_a_btc * btc_you_have)))
39 time.sleep(interval)
40
btcuser01@ubuntu002:~/Price$
btcuser01@ubuntu002:~/Price$ python3 loop_btc_price.py
20/12/31 09:34:50, 29186.75, 2977781, 17985797
20/12/31 09:35:50, 29148.89, 2980000, 17999200
20/12/31 09:36:50, 29182.07, 2978434, 17989741
20/12/31 09:37:50, 29168.38, 2980612, 18002896
20/12/31 09:38:50, 29232.75, 2980116, 17999900
When executed, on each line Time, USD price, JPY price, Value of owned Bitcoin in JPY Is displayed. The display will continue until you stop with CTRL-C.
As of December 31, 2020, the price has risen significantly. 6.04 BTC is about 18 million yen. I wonder what will happen next year.
Recommended Posts