diff --git a/price-feed-bot-just1lovewrl.lua b/price-feed-bot-just1lovewrl.lua new file mode 100644 index 00000000..9252afdb --- /dev/null +++ b/price-feed-bot-just1lovewrl.lua @@ -0,0 +1,57 @@ +-- ao.id _ZUedzqmP-q9kqJHkGu2B1QTKcNwQGI6YJ-S6ZvO6zY + +local json = require("json") + +_ORBIT = "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s" + +function handleError(msg, errorMessage) + ao.send({ + Target = msg.From, + Tags = { + Action = "Error", + ["Message-Id"] = msg.Id, + Error = errorMessage + } + }) +end + +Handlers.add("just1love", + Handlers.utils.hasMatchingTag("Action", "Sponsored-Get-Request"), + function(msg) + local token = msg.Tags.Token + if not token then + handleError(msg, "Token not provided") + return + end + + local url = "https://api.coingecko.com/api/v3/simple/price?ids=" .. token .. "&vs_currencies=usd" + ao.send({ + Target = _ORBIT, + Action = "Get-Real-Data", + Url = url + }) + print("Pricefetch request sent for " .. token) + end +) + +Handlers.add("ReceiveData", + Handlers.utils.hasMatchingTag("Action", "Receive-Response"), + function(msg) + print("Received data: " .. msg.Data) + local res = json.decode(msg.Data) + local token = msg.Tags.Token + if res[token] and res[token].usd then + ao.send({ + Target = msg.From, + Tags = { + Action = "Price-Response", + ["Message-Id"] = msg.Id, + Price = res[token].usd + } + }) + print("Price of " .. token .. " is " .. res[token].usd) + else + handleError(msg, "Failed to fetch price") + end + end +) diff --git a/price-feed-bot-just1lovewrl.png b/price-feed-bot-just1lovewrl.png new file mode 100644 index 00000000..3e145893 Binary files /dev/null and b/price-feed-bot-just1lovewrl.png differ