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-bot-zkmuzle #310

Open
wants to merge 4 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
58 changes: 58 additions & 0 deletions 0rbit-News-Feed.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
local json = require("json")

_0RBIT = "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s"
_0RBT_TOKEN = "BUhZLMwQ6yZHguLtJYA5lLUa9LQzLXMXRfaq9FVcPJc"

URL = "https://saurav.tech/NewsAPI/top-headlines/category/health/in.json"
FEE_AMOUNT = "1000000000000" -- 1 $0RBT
NEWS = NEWS or {}
function fetchNews()
Send({
Target = _0RBT_TOKEN,
Action = "Transfer",
Recipient = _0RBIT,
Quantity = FEE_AMOUNT,
["X-Url"] = URL,
["X-Action"] = "Get-Real-Data"
})
print(Colors.green .. "GET Request sent to the 0rbit process.")
end
function receiveData(msg)
local res = json.decode(msg.Data);
local articles;
local article;
if res.status == "ok" then
articles = res.articles;
for k, v in pairs(articles) do
article =
{
title = v.title,
description = v.description,
url = v.url
}
table.insert(NEWS, article)
end
print("News Updated")
else
print("Error in fetching news")
end
end
function getNews(msg)
local news = json.encode(NEWS)
Handlers.utils.reply(news)(msg)
end
Handlers.add(
"GetNews",
Handlers.utils.hasMatchingTag("Action", "Get-News"),
getNews
)
Handlers.add(
"CronTick",
Handlers.utils.hasMatchingTag("Action", "Cron"),
fetchNews
)
Handlers.add(
"ReceiveData",
Handlers.utils.hasMatchingTag("Action", "Receive-Data-Feed"),
receiveData
)
85 changes: 85 additions & 0 deletions News-Feed.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
local json = require("json")

-- processId of the 0rbit process.
_0RBIT = "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s"
_0RBT_TOKEN = "BUhZLMwQ6yZHguLtJYA5lLUa9LQzLXMXRfaq9FVcPJc"

-- Base URL for News API
URL = "https://saurav.tech/NewsAPI/top-headlines/category/health/in.json"
FEE_AMOUNT = "1000000000000" -- 1 $0RBT

NEWS = NEWS or {}

--[[
Function to send the latest news.
]]
function getNews(msg)
local news = json.encode(NEWS)
Handlers.utils.reply(news)(msg)
end

--[[
Function to fetch the news using the 0rbit.
]]
function fetchNews()
Send({
Target = _0RBT_TOKEN,
Action = "Transfer",
Recipient = _0RBIT,
Quantity = FEE_AMOUNT,
["X-Url"] = URL,
["X-Action"] = "Get-Real-Data"
})
print(Colors.green .. "GET Request sent to the 0rbit process.")
end

--[[
Function to update the news.
]]
function receiveData(msg)
local res = json.decode(msg.Data);
local articles;
local article;
if res.status == "ok" then
articles = res.articles;
for k, v in pairs(articles) do
article =
{
title = v.title,
description = v.description,
url = v.url
}
table.insert(NEWS, article)
end
print("News Updated")
else
print("Error in fetching news")
end
end

--[[
Handlers to get latest news.
]]
Handlers.add(
"GetNews",
Handlers.utils.hasMatchingTag("Action", "Get-News"),
getNews
)

--[[
CRON Handler to fetch the news using 0rbit in a defined interval.
]]
Handlers.add(
"CronTick",
Handlers.utils.hasMatchingTag("Action", "Cron"),
fetchNews
)

--[[
Handlers to receive data from the 0rbit process.
]]
Handlers.add(
"ReceiveData",
Handlers.utils.hasMatchingTag("Action", "Receive-Data-Feed"),
receiveData
)
Binary file added Proof Claim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions pricebot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- PID = wCHJyBbGT_H00nFX0rwL3HjLk71DKn3a5QKXcghk5yU

_0RBIT= "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s"


function handleError(msg, errorMessage)
ao.send({
Target = msg.From,
Tags = {
Action = "Error",
["Message-Id"] = msg.Id,
Error = errorMessage
}
})
end


Handlers.add("zkmuzle",
Handlers.utils.hasMatchingTag("Action", "zkmuzle"),
function(msg)
local token = msg.Tags.Token
local url = "https://api.coingecko.com/api/v3/simple/price" .. "?ids=" .. token .. "&vs_currencies=usd"
ao.send({
Target = _0RBIT,
Action = "Get-Real-Data",
Url = url
})
Handlers.utils.reply("PriceFetch")
(msg)
end
)