diff --git a/price-feed-bot-flechemano/Orbit-Price-Feed.lua b/price-feed-bot-flechemano/Orbit-Price-Feed.lua new file mode 100644 index 00000000..4b35c8bc --- /dev/null +++ b/price-feed-bot-flechemano/Orbit-Price-Feed.lua @@ -0,0 +1,51 @@ +-- PID 3yCuVz9VC5qL7X8p_uIMzgUoPiwfdt08CLI_KqI6X_w +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("flechemano", + 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-flechemano/Screenshot_20240523-080205.jpg b/price-feed-bot-flechemano/Screenshot_20240523-080205.jpg new file mode 100644 index 00000000..1d4384d2 Binary files /dev/null and b/price-feed-bot-flechemano/Screenshot_20240523-080205.jpg differ