From 3fbddab447c141fe0501a6dfacffd2edb72da47a Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 22 Aug 2024 17:17:15 -0500 Subject: [PATCH] Change source of price info - older Bisq api for prices no longer exists, moved to mempool.space - converted logic to retrieve prices from https://mempool.space/api/v1/prices - reduce set of allowable currency exchange type to (AUD,CAD,CHF,EUR,GBP,JPY,USD) - updated logic in satsperfiatunit to use limited price info - updated logic in fiatprice to use limited price info - set sample config files to use new attribution color and price url. --- sample-config/fiatprice.json | 26 +++----------------------- sample-config/satsperfiatunit.json | 26 +++----------------------- scripts/fiatprice.py | 8 ++++---- scripts/satsperfiatunit.py | 12 ++++++------ scripts/vicariousnetwork.py | 16 ++++++++-------- 5 files changed, 24 insertions(+), 64 deletions(-) diff --git a/sample-config/fiatprice.json b/sample-config/fiatprice.json index b7f1700..a73bb1d 100644 --- a/sample-config/fiatprice.json +++ b/sample-config/fiatprice.json @@ -2,7 +2,7 @@ "attributionColor.comment": "The text color for the source attribution line expressed as a Hexadecimal color specifier", "attributionColor.fka": "colorBisq", "attributionColor.type": "color", - "attributionColor": "#40FF40", + "attributionColor": "#1bd8f4", "backgroundColor.comment": "The background color of the image expressed as a Hexadecimal color specifier", "backgroundColor.fka": "colorBackground", "backgroundColor.type": "color", @@ -18,33 +18,13 @@ "fiatUnit.comment": "The three letter fiat currency unit for value comparisons", "fiatUnit.type": "string", "fiatUnit.choices": { - "ARS": "Argentine Peso", "AUD": "Australian Dollar", - "BRL": "Brazilian Real", "GBP": "British Pound", "CAD": "Canadian Dollar", - "CLP": "Chilean Peso", - "CNY": "Chinese Yuan", - "CZK": "Czech Koruna", - "DKK": "Danish Krone", "EUR": "Euro", - "HKD": "Hong Kong Dollar", - "HUF": "Hungarian Forint", - "INR": "Indian Rupee", "JPY": "Japanese Yen", - "MXN": "Mexican Peso", - "NZD": "New Zealand Dollar", - "NGN": "Nigerian Naira", - "NOK": "Norwegian Kroner", - "PHP": "Philippine Peso", - "PLN": "Polish Zloty", - "RON": "Romanian Lei", - "RUB": "Russian Ruble", - "SGD": "Singapore Dollar", - "SEK": "Swedish Krona", "CHF": "Swiss Franc", - "USD": "United States Dollar", - "VUV": "Vanuatu Vatu" + "USD": "United States Dollar" }, "fiatUnit": "USD", "headerColor.comment": "The color of the text expressed as a Hexadecial color specifier", @@ -73,7 +53,7 @@ "priceUrl.comment": "The url that provides the pricing information from bisq marketplace", "priceUrl.fka": "priceurl", "priceUrl.type": "string", - "priceUrl": "https://bisq.markets/bisq/api/markets/ticker", + "priceUrl": "https://mempool.space/api/v1/prices", "useTor.comment": "Indicates whether remote calls should use tor socks proxy for privacy.", "useTor.type": "boolean", "useTor": true, diff --git a/sample-config/satsperfiatunit.json b/sample-config/satsperfiatunit.json index 2c10f1b..10ac169 100644 --- a/sample-config/satsperfiatunit.json +++ b/sample-config/satsperfiatunit.json @@ -2,7 +2,7 @@ "attributionColor.comment": "The text color for the source attribution line expressed as a Hexadecimal color specifier", "attributionColor.fka": "colorBisq", "attributionColor.type": "color", - "attributionColor": "#40FF40", + "attributionColor": "#1bd8f4", "backgroundColor.comment": "The background color of the image expressed as a Hexadecimal color specifier", "backgroundColor.fka": "colorBackground", "backgroundColor.type": "color", @@ -18,33 +18,13 @@ "fiatUnit.comment": "The three letter fiat currency unit for value comparisons", "fiatUnit.type": "string", "fiatUnit.choices": { - "ARS": "Argentine Peso", "AUD": "Australian Dollar", - "BRL": "Brazilian Real", "GBP": "British Pound", "CAD": "Canadian Dollar", - "CLP": "Chilean Peso", - "CNY": "Chinese Yuan", - "CZK": "Czech Koruna", - "DKK": "Danish Krone", "EUR": "Euro", - "HKD": "Hong Kong Dollar", - "HUF": "Hungarian Forint", - "INR": "Indian Rupee", "JPY": "Japanese Yen", - "MXN": "Mexican Peso", - "NZD": "New Zealand Dollar", - "NGN": "Nigerian Naira", - "NOK": "Norwegian Kroner", - "PHP": "Philippine Peso", - "PLN": "Polish Zloty", - "RON": "Romanian Lei", - "RUB": "Russian Ruble", - "SGD": "Singapore Dollar", - "SEK": "Swedish Krona", "CHF": "Swiss Franc", - "USD": "United States Dollar", - "VUV": "Vanuatu Vatu" + "USD": "United States Dollar" }, "fiatUnit": "USD", "headerColor.comment": "The color of the header text expressed as a Hexadecial color specifier", @@ -72,7 +52,7 @@ "priceUrl.comment": "The url that provides the pricing information from bisq marketplace", "priceUrl.fka": "priceurl", "priceUrl.type": "string", - "priceUrl": "https://bisq.markets/bisq/api/markets/ticker", + "priceUrl": "https://mempool.space/api/v1/prices", "satShape.comment": "The shape that each individual sat should be drawn.", "satShape.fka": "satshape", "satShape.type": "string", diff --git a/scripts/fiatprice.py b/scripts/fiatprice.py index 42e8cd7..a4a96f7 100644 --- a/scripts/fiatprice.py +++ b/scripts/fiatprice.py @@ -38,7 +38,7 @@ def __init__(self): } # Define our defaults (all panel specific key names should be listed) - self._defaultattr("attributionColor", "#40ff40") + self._defaultattr("attributionColor", "#1bd8f4") self._defaultattr("bigTextEnabled", True) self._defaultattr("bigTextOnTopEnabled", True) self._defaultattr("fiatUnit", "USD") @@ -51,7 +51,7 @@ def __init__(self): self._defaultattr("priceLow", 0) self._defaultattr("priceShadowColor", "#ffffff7f") self._defaultattr("priceUpColor", "#40ff40") - self._defaultattr("priceUrl", "https://bisq.markets/bisq/api/markets/ticker") + self._defaultattr("priceUrl", "https://mempool.space/api/v1/prices") self._defaultattr("useTor", True) self._defaultattr("watermarkAnchor", "bottom") @@ -89,7 +89,7 @@ def run(self): else: vicarioustext.drawcenteredtext(self.draw, f"Price: {priceText}", smallPriceSize, x, y, ImageColor.getrgb(self.priceColor)) # attribution - vicarioustext.drawbottomlefttext(self.draw, "Data from bisq", attributionSize, 0, self.height, ImageColor.getrgb(self.attributionColor)) + vicarioustext.drawbottomlefttext(self.draw, "Data from mempool", attributionSize, 0, self.height, ImageColor.getrgb(self.attributionColor)) self.canvas.alpha_composite(alphaLayer) alphaLayer.close() @@ -117,4 +117,4 @@ def run(self): exit(0) # Continuous run - p.runContinuous() \ No newline at end of file + p.runContinuous() diff --git a/scripts/satsperfiatunit.py b/scripts/satsperfiatunit.py index 97851f7..6b3054c 100644 --- a/scripts/satsperfiatunit.py +++ b/scripts/satsperfiatunit.py @@ -42,7 +42,7 @@ def __init__(self): } # Define our defaults (all panel specific key names should be listed) - self._defaultattr("attributionColor", "#40ff40") + self._defaultattr("attributionColor", "#1bd8f4") self._defaultattr("bigTextEnabled", True) self._defaultattr("bigTextOnTopEnabled", True) self._defaultattr("fiatUnit", "USD") @@ -55,7 +55,7 @@ def __init__(self): self._defaultattr("priceLow", 0) self._defaultattr("priceShadowColor", "#ffffff7f") self._defaultattr("priceUpColor", "#40ff407f") - self._defaultattr("priceUrl", "https://bisq.markets/bisq/api/markets/ticker") + self._defaultattr("priceUrl", "https://mempool.space/api/v1/prices") self._defaultattr("satShape", "square") # circle, square, symbol-s, triangle self._defaultattr("satShapeColor", "#ff7f00") self._defaultattr("useTor", True) @@ -74,15 +74,15 @@ def fetchData(self): self.priceColor = self.priceDownColor if self.priceChange > 0: self.priceColor = self.priceUpColor - if fiatkeyname != f"btc_{self.fiatUnit}".lower(): - self.fiatUnit = fiatkeyname.split("_")[1].upper() + if fiatkeyname != f"{self.fiatUnit}".upper(): + self.fiatUnit = fiatkeyname.upper() def getSatsPerFiatUnit(self): return int(round(100000000.0 / self.priceLast)) def renderAttribution(self): fontsize = int(self.height * 16/320) - vicarioustext.drawbottomlefttext(self.draw, "Data from bisq", fontsize, 0, self.height, ImageColor.getrgb(self.attributionColor)) + vicarioustext.drawbottomlefttext(self.draw, "Data from mempool", fontsize, 0, self.height, ImageColor.getrgb(self.attributionColor)) def renderBigTextOver(self): if not self.bigTextEnabled: return @@ -216,4 +216,4 @@ def setupSatSizing(self): exit(0) # Continuous run - p.runContinuous() \ No newline at end of file + p.runContinuous() diff --git a/scripts/vicariousnetwork.py b/scripts/vicariousnetwork.py index 2851402..fcf2941 100644 --- a/scripts/vicariousnetwork.py +++ b/scripts/vicariousnetwork.py @@ -295,19 +295,19 @@ def getnostrstats(useTor=True, url="https://stats.nostr.band/stats_api?method=st j = errresponse return j -def getpriceinfo(useTor=True, url="https://bisq.markets/bisq/api/markets/ticker", price_last=-1, price_high=-1, price_low=-1, fiatUnit="USD"): - newestfile = getfromurlifstale(useTor, url, "../data/bisq", 3600) +def getpriceinfo(useTor=True, url="https://mempool.space/api/v1/prices", price_last=-1, price_high=-1, price_low=-1, fiatUnit="USD"): + newestfile = getfromurlifstale(useTor, url, "../data/mempoolprices", 3600) if len(newestfile) > 0: with open(newestfile) as f: j = json.load(f) if "error" not in j: - keyname = f"btc_{fiatUnit}".lower() + keyname = f"{fiatUnit}".upper() if keyname not in j: - print(f"Price service does not have BTC to {fiatUnit} currency pair. Using btc_usd") - keyname = "btc_usd" - price_last = int(math.floor(float(j[keyname]["last"]))) - price_high = int(math.floor(float(j[keyname]["high"]))) - price_low = int(math.floor(float(j[keyname]["low"]))) + print(f"Price service does not have BTC to {fiatUnit} currency pair. Using USD") + keyname = "USD" + price_last = int(math.floor(float(j[keyname]))) + price_high = price_last + price_low = price_last return (price_last,price_high,price_low,keyname) def getraretoshiuserinfoFallback(useTor=True, raretoshiDataDirectory="../data/raretoshi/", raretoshiUser="rapidstart", userInfo=None, userInfoLast=0, userInfoInterval=3600):