[C# Tutorial] How to use Splinterlands Market API

avatar

ecko-fresh.png

Hi Splinterlands Community,

beside of my art work I'm also developing software and also spent some time with the splinterlands API. Today I want to show you a way on reading marked prices of individual Splinterland cards. In my example I will use Visual Studio and C# as programming language. I will also upload the complet Visual Studio Project at the end of my post.

https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/deraaa/23t7DKQuDFz7igzrJksBrQkFBXPQhdwd4fDDYLJrKQHuEJCLU1hcJbC8VwQAYmBuFqnC2.webp

1. The Market API

Base API URL:
https://api.splinterlands.io/market/for_sale_by_card?card_detail_id

To use the API you also need to input 3 paramters:

    1. card_detail_id 
    2. gold 
    3. edition

As an example lets use the card "PLADO EMBERSTORM" in Normal (Non-Gold):

    1. card_detail_id=110 
    2. gold=false 
    3. edition=1

We finally fet this API URL:
https://api.splinterlands.io/market/for_sale_by_card?card_detail_id=110&gold=false&edition=1

[{"fee_percent":500,"uid":"C1-110-BKBV51MPDC","seller":"stokjockey","card_detail_id":110,"xp":0,"gold":false,"edition":1,"buy_price":"478.550","currency":"USD","desc":null,"type":"SELL","market_id":"9b4fedef0fe198d771246dceb6255e1f9d6c6ad1-0","last_transferred_block":null,"last_transferred_date":null,"last_used_block":55900685,"last_used_date":"2021-07-23T18:30:15.000Z","last_used_player":"trezor777"},{"fee_percent":500,"uid":"C1-110-F0QOAA38DS","seller":"comakid","card_detail_id":110,"xp":2250,"gold":false,"edition":1,"buy_price":"620","currency":"USD","desc":null,"type":"SELL","market_id":"44eb24a4dfc66a1e07529061ca24bd838100eb64-0","last_transferred_block":null,"last_transferred_date":null,"last_used_block":64369416,"last_used_date":...............

https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/deraaa/23t7DKQuDFz7igzrJksBrQkFBXPQhdwd4fDDYLJrKQHuEJCLU1hcJbC8VwQAYmBuFqnC2.webp

2. Let's programm

Goal of this tutorial is to show how you transform the API raw data in a suitable data format. To do so we will store all offers in a List of offers.

    class JSonDownloadFormat
    {
        public List<Root> offers { get; set; }
    }

To read out all data from the API into single variables we will create also the Root class in way to match wit the available date, this is requried to use the JSON Desirializer later on.

    public class Root
    {
        public int fee_percent { get; set; }
        public string uid { get; set; }
        public string seller { get; set; }
        public int card_detail_id { get; set; }
        public int xp { get; set; }
        public bool gold { get; set; }
        public int edition { get; set; }
        public string buy_price { get; set; }
        public string currency { get; set; }
        public object desc { get; set; }
        public string type { get; set; }
        public string market_id { get; set; }
        public int? last_transferred_block { get; set; }
        public DateTime? last_transferred_date { get; set; }
        public int? last_used_block { get; set; }
        public DateTime? last_used_date { get; set; }
        public string last_used_player { get; set; }
    }

We are now able to download and parse all data from the API into our customer list. To do saw we just need few lines of code:

        static void Main(string[] args)
        {
        string MyUrl = https://api.splinterlands.io/market/for_sale_by_card?card_detail_id=110&gold=false&edition=1";   
            string API_Response = new System.Net.WebClient().DownloadString(MyUrl);
            API_Response = "{\"offers\":" + API_Response + "}";
            JSonDownloadFormat JSonDownloadList = JsonConvert.DeserializeObject<JSonDownloadFormat>(API_Response);
            foreach (Root Offer in JSonDownloadList.offers)
            {
                Console.WriteLine(Offer.xp.ToString() + " : " + Offer.buy_price.ToString() + "$");
            }
            int Inpiut = Console.Read();
        } 

The code above will download the current offers, transfer it to our customer list, loop over all offers and output the offer XP* and price into the console. ( *XP is typically used to caluclate the BCX)

Let's have a look on the final output:

ecko-fresh2.png

https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/deraaa/23t7DKQuDFz7igzrJksBrQkFBXPQhdwd4fDDYLJrKQHuEJCLU1hcJbC8VwQAYmBuFqnC2.webp

3. Summary

Having this data available in your own tool opens you many possibilities. I currently use it to track my favority cards for special discounts, which looks like this:

ecko-fresh3.png

4. The Example Code

https://mediafire.com/file/i1jsbrbbjcq16rj/SplinterlandsMarketAPI.rar

https://images.hive.blog/0x0/https://files.peakd.com/file/peakd-hive/deraaa/23t7DKQuDFz7igzrJksBrQkFBXPQhdwd4fDDYLJrKQHuEJCLU1hcJbC8VwQAYmBuFqnC2.webp

Wish you a great day! Appriciate all comments, follower or other kind of support!
@ecko-fresh



0
0
0.000
1 comments
avatar

I just want to say thanks for the information in your post, it was a help to me. If you are still on HIVE and care to respond, I will give you a full vote on it. It's a damn shame nobody saw this due to you having so little exposure.

0
0
0.000