Price of Ground Items?



  • Hello,

    I'm trying to figure out how to find the price of all items currently on the ground within an area, I can't find any 'price' function in the JavaDocs or in any source codes.

    Essentially, I would just like my script to find all items above 'x' price and go loot it quickly.

    Thank you for any help!



  • RSPeer doesn't support grabbing any prices as far as I know, what I would do is pull all the data from a website and store it locally where you can interact and pull stuff immediately.

    Here's a link to what RSBuddy uses for all of its exchange data.

    https://rsbuddy.com/exchange/summary.json

    However, JSONs are dynamic and you can't just have a method that assumes the position of elements (Assuming you are parsing this as a String and not a JSON).

    If you plan on following my advice I recommend using JSON Minimal: https://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/

    It's a more simple and lightweight version that is more efficient than most others in terms of memory reads and writes.



  • Cool, thank you! That should work, just trying to get rough numbers of what prices for items are so this should do the trick, thanks again.


  • Script Developer Sponsor Staff Director

    Gson is bundled with rspeer already, you can use that to parse it



  • [code]
    package com.dynamic.scripts.farmer.api.grandexchange;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URL;

    /**

    • GrandExchange Price Class
    • @author Reid

    */
    public class GrandExchangePriceAPI {

    private static final String BASE = "https://api.rsbuddy.com/grandExchange?a=guidePrice&i=";
    
    /**
     * Default Constructor
     * 
     */
    public GrandExchangePriceAPI() {
    
    }
    
    /**
     * Gets the overall price of an item.
     * 
     * @param itemID
     * @return itemPrice
     * @throws IOException
     */
    public int getOverallPrice(final int itemID) throws IOException {
    	return parse(itemID,"overall");
    }
    
    
    /**
     * Gets the buying price of an item.
     * 
     * @param itemID
     * @return itemPrice
     * @throws IOException
     */
    public int getBuyingPrice(final int itemID) throws IOException {
    	return parse(itemID,"buying");
    }
    
    /**
     * Gets the selling price of an item.
     * 
     * @param itemID
     * @return itemPrice
     * @throws IOException
     */
    public int getSellingPrice(final int itemID) throws IOException {
    	return parse(itemID,"selling");
    }
    
    
    /**
     * Retrieves the price of an item.
     * 
     * @param itemID
     * @return itemPrice
     * @throws IOException
     */
    private int parse(final int itemID, String choice) throws IOException {
    	final URL url = new URL(BASE + itemID);
    	BufferedReader file = new BufferedReader(new InputStreamReader(url.openStream()));
    	String line;
    	String price = null;
    	while ((line = file.readLine()) != null) {
    		if (line.contains("{")) {
    			price = (line).trim();
    		}
    	}
    	if (choice.equals("buying")){
    		price = price.substring(price.indexOf(",") + 10, nthOccurrence(price, ',', 1)).trim();
    	} else if(choice.equals("selling")) {
    		price = price.substring(nthOccurrence(price, ',', 2)  + 11 , price.indexOf("sellingQuantity") - 2).trim();
    	} else {
    		price = price.substring(price.indexOf(":") + 1, price.indexOf(",")).trim();
    	}
    	file.close();
    	return Integer.parseInt(price);
    }
    
    private int nthOccurrence(String str, char c, int n) {
    	int pos = str.indexOf(c, 0);
    	while (n-- > 0 && pos != -1)
    		pos = str.indexOf(c, pos + 1);
    	return pos;
    }
    

    }
    [/code]


 

79
Online

8.6k
Users

905
Topics

11.7k
Posts