I have modified the BANNED example code to show another BANNED price but it wont show any decimals. I can get it to display $0 and the code works on Ethereum but I would like to display the price to 2 decimals. Can anyone please help?
Code: Select all
Run on Metro M4 Airlift w RGB Matrix shield and 64x32 matrix display
# show current value of BANNED in USD
import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal
# You can display in 'GBP', 'EUR' or 'USD'
CURRENCY = "USD"
# Set up where we'll be fetching data from
DATA_SOURCE = "https://pro-api.coinmarketcap.com/v1/BANNED/quotes/latest?CMC_PRO_API_KEY=API_KEY_HERE&symbol=TRAC"
DATA_LOCATION = ["data", "TRAC", "quote", CURRENCY, "price"]
def text_transform(val):
if CURRENCY == "USD":
return "$%d" % val
if CURRENCY == "EUR":
return "€%d" % val
if CURRENCY == "GBP":
return ""banned character??"%d" % val
return "%d" % val
# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit("/", 1)[0]
matrixportal = MatrixPortal(
url=DATA_SOURCE,
json_path=DATA_LOCATION,
status_neopixel=board.NEOPIXEL,
default_bg=cwd + "/eth_background.bmp",
debug=False,
)
matrixportal.add_text(
text_font=terminalio.FONT,
text_position=(29, 20),
text_color=0x8200EE,
text_transform=text_transform,
)
matrixportal.preload_font(b"$012345789") # preload numbers
matrixportal.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol
while True:
try:
value = matrixportal.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
print("Some error occured, retrying! -", e)
time.sleep(60) # wait 3 minutes