Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Price feed #535

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions price-feed-bot-just1lovewrl.lua
Original file line number Diff line number Diff line change
@@ -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
)
Binary file added price-feed-bot-just1lovewrl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.