Discord.js Bot Hypixel Bazaar Price Checker – Behind the Scenes

Over the past few weeks, I’ve been working on coding a Discord Bot with both fun commands, and moderation commands. As I’m playing around with the Discord.js library, I learned a ton of neat things about working with it.

Here it is, in case you want to see it.

I wanted to get my bot to get Hypixel Skyblock Bazaar data. However, accessing the Hypixel API can be quite obscure and confusing if you’ve never done it before. So, to save you the trouble, I’ll share with you how my bot pulls bazaar data from the Hypixel API.

Note: We’ll be using JavaScript for this, as we are using Discord.js.

Installing Dependencies

I’m going to assume you’re using using npm, and that you’ve already set up your project file using npm.

To fetch things from a website, we’ll be using the node-fetch package.

Go ahead and install node-fetch. Navigate to your project folder and
npm install node-fetch. You’ll know that it installed correctly when it appears as a dependency in your package.json file.

Next, you’ll want to make sure that you actually use node-fetch in your code:
const fetch = require(‘node-fetch’);

Getting the Response

Now that you have that set up, make sure that you have an API key from Hypixel. You can obtain one by logging into the server and typing in /api new.

In your code, you’ll want to set up something similar to the following:

let api_key = "YOUR_API_KEY";
let product_id = "PRODUCT_NAME_HERE";

fetch(`https://api.hypixel.net/skyblock/bazaar/product?key=${api_key}&productId=${product_id}`)
    .then(response => response.json())
    .then(data => {
        // Do something with the data here.
        console.log(data);
    });

Your API key should be kept private. Make sure that wherever you decide to store your API key, that it doesn’t accidentally get uploaded onto github if you decide to publicly share your code.

An example of what you could do with the data is to compute the “flipping profit” or how much you’d make by setting up a buy order, then setting up the item as a sell order.

You can access the buy order prices with data.product_info.quck_status.buyPrice.
You can access the sell order prices with data.product_info.quck_status.sellPrice.
Now, just subtract the sell price from the buy price and you’ve got profit. You’ll have to take the 1% selling tax into account, but hey, you created a basic bot to tell you the profits of the items.

You can see my usage of this here.

Unofficial Documentation

data is basically the parsed json object returned whenever you send the request. The official documentation for it can be found here. Note all of this data is read-only, so you can’t change any of the data.

I really liked the Discord.js-style of documentation, so I’m going to attempt to mimic it here, to make it easier to read.

Data

Properties Methods
success
product_info
None

Properties

.success

True if the fetch request was successful.
Type: ?boolean

.product_info

True if the fetch request was successful.
Type: product_info

 

product_info

Properties Methods
buy_summary
sell_summary
quick_status
None

Properties

.buy_summary

The current top 30 buy orders.
Type: BazaarTransaction[]

.sell_summary

The current top 30 sell orders.
Type: BazaarTransaction[]

.quick_status

The stats that most users care about.
Type: quick_status

BazaarTransaction

Properties Methods
amount
pricePerUnit
orders
None
.amount

The number of items in the transaction order.
Type: ?number

.pricePerUnit

The price per item in the transaction order.
Type: ?number

.orders

The number of transaction orders offered at this price.
Type: ?number

quick_status

Properties Methods
productId
sellPrice
sellVolume
sellMovingWeek
sellOrders
buyPrice
buyVolume
buyMovingWeek
buyOrders
None
.productId

The name of this product.
Type: string
Examples: “ENCHANTED_SAND” or “RAW_FISH”

.sellPrice

The weighted average of the top 2% of sell orders, by volume.
Type: ?number
Usage: This is the instant-buy price you see in the Hypixel Bazaar.

.sellVolume

The current number of items offered in all sell orders combined.
Type: ?number

.sellMovingWeek

The number of transactions from the last 7 days.
Type: ?number

.sellOrders

The count of active sell orders.
Type: ?number

.buyPrice

The weighted average of the top 2% of buy orders, by volume.
Type: ?number
Usage: This is the instant-sell price you see in the Hypixel Bazaar.

.buyVolume

The current number of items offered in all buy orders combined.
Type: ?number

.buyMovingWeek

The number of transactions from the last 7 days.
Type: ?number

.buyOrders

The count of active sell orders.
Type: ?number

Leave a Comment