![code.jpg](https://images.hive.blog/768x0/https://files.peakd.com/file/peakd-hive/dbooster/AJkMcFGKBES6NEeGzGFLddkExXhgSn2pTWKJ1kDLKKcppp8GHruu3sZbGVcUHiu.jpg)
Like many of you, I'm sure, I have been keeping spreadsheets tracking my Hive holdings for many years. To get the prices for all the tokens I own, I use Keyboard Maestro, a very advanced macro application for the Mac, to essentially scrape the price data from Hive-Engine.com. It goes through page by page, capturing everything, then parses the data using Perl, a very powerful but incredibly cryptic scripting language that uses regular expressions, then calls some Applescripts that automatically insert all the captured prices into my spreadsheet. It's not really as complex as it seems—basically it is just a collection of scripts held together and managed by Keyboard Maestro—it's just hard to explain because there are quite a few steps there.
This works well, but there is one weak point to this system—the data scraping. As anyone who has even scraped data from the web before knows, it is very fragile! As soon as the webpage changes one line of formatting, it can ruin everything, requiring a rewrite of the scraping script. And over the years, that has happened to me many times. Not to mention, Hive-Engine.com often goes down, so I also have scraping scripts for tribaldex and beeswap.
I've lived with the system, because I really am not much of a coder and moving beyond the simple scripting languages I know has always seemed like it would require more effort than I can devote. It's not that I don't have the ability to learn—I studied computer science at university, intensively dealing with C++ and Java for all four years there as well as other languages like Assembler, which I wrote a C++ complier in for my graduation project—I assume I still have the mental capability to learn more languages, I just lack the time to pick up more than bits and pieces of scripting languages like AppleScript here and there as I need to do things. Part of aging is realizing we just don't have enough time to do everything, and I would much rather devote my limited time to my kids, writing, and haiku writing/research.
But then @raymondspeaks did something that inspired me to change this a bit.
![](https://images.hive.blog/768x0/https://images.ecency.com/DQmR3iwCn9yvwXDXfuNjmMX6FrjAvFfYQWgA4QRckpens1j/external_content.duckduckgo.png)
If you missed it, Ray decided to use ChatGPT to write a trading bot. You can read his post and watch his video about it here. I'm sure we have all seen the stories floating around about people with no coding experience using ChatGPT to write apps for the iPhone app store. There are no shortage of these stories. I've read a few of them. Basically they seem to boil down to kids who have unlimited time and can go back and forth with ChatGPT for hours and days, working with the prompt enough to get it to write them a workable app. Again, I don't really have that time.
But watching Ray work on his trading bot gave me the idea that maybe I can have ChatGPT work me up some simpler code, not quite an iPhone app, but something more complex than I know how to do.
Although I didn't know it was possible, after watching Ray's video, I got the idea that I could use Javascript and two libraries to grab the token prices: sscjs and @hiveio/dhive.
To make a long story short, I opened ChatGPT and used a much simpler prompt than Ray used in his video. I just wrote: "I want you to write me a script using sscjs and @hiveio/dhive javascript libraries to grab a specific token price from hive-engine. The token symbol will be given as the first argument when I run this script, and it will simply return the price only."
That's it. And it returned a working script that I later used without modification to get the data I need.
It took more time to tell ChatGPT to back up and tell me how to install a javascript environment (1. Use a curl command to download and install nvm, 2. install the latest lts version of node.js, 3. download and install the libraries I want, then 4. set up a new project. Fairly simple, just a lot of waiting for things to download and install.).
Next I pointed keyboard maestro at this javascript, and instructed it to run it multiple times with different token symbols, sticking each price in a variable.
Boom, within an hour I had a much more reliable system to get the token prices for my spreadsheets. As a bonus, it's much much faster as well than my old process of scraping Hive-Engine.com.
![](https://images.hive.blog/768x0/https://images.ecency.com/DQmR3iwCn9yvwXDXfuNjmMX6FrjAvFfYQWgA4QRckpens1j/external_content.duckduckgo.png)
If you are curious, by the way, here's the code:
const SSC = require('sscjs');
// Initialize SSC
const ssc = new SSC('https://api.hive-engine.com/rpc/');
// Function to fetch the latest price of a token
const fetchTokenPrice = async (symbol) => {
const limit = 1; // We only want the latest trade
const query = { symbol: symbol };
const sort = { timestamp: -1 };
try {
const result = await ssc.find('market', 'tradesHistory', query, limit, 0, sort);
if (result.length > 0) {
console.log(`${result[0].price}`);
} else {
console.log(`No trades found for ${symbol}`);
}
} catch (error) {
console.error('Error fetching token price:', error);
}
};
// Check if a token symbol is provided
if (process.argv.length < 3) {
console.log('Usage: node fetchPrice.js <TOKEN_SYMBOL>');
} else {
const tokenSymbol = process.argv[2]; // Get token symbol from command-line argument
fetchTokenPrice(tokenSymbol);
}
I'd be surprised if it is well written. You Hive coders can tell me if it's good or not. I don't know javascript at all, so I can't tell. As time goes on I may pick that apart and try to figure out what is going on, and if things break I may be forced to learn faster, but for now I just know it works!
So yeah, there we go, ChatGPT coding for the win. I'm going to have to turn to this more often. Thanks for the inspiration to do so, @raymondspeaks!
❦
![]() |
David LaSpina is an American photographer and translator lost in Japan, trying to capture the beauty of this country one photo at a time and searching for the perfect haiku. He blogs here and at laspina.org. Write him on Twitter or Mastodon. |