Script to Check Splinterlands Pack Openings ValuesteemCreated with Sketch.

in spt •  5 years ago 

carbon.png

As Splinterlands Beta packs are running out, many players are buying and opening beta packs. I am one of them too. In recent times I have bought 300 beta packs to open them. I was keeping track of my openings value by checking the change of my deck value in Peakmonsters.

While talking to @joshman in SFR discord about his recent beta packs openings value, I though why not create a script that can check our recent pack openings and show us the total value, so why can get a clearer picture.

So, I coded it, tested against my openings. I was not impressed what pulled using 100% legendary and gold potions. Realized you have to very lucky or be @zaku to pull something very awesome. 😉

Here is the script:

/* eslint-disable no-loop-func */
/* eslint-disable no-await-in-loop */
const axios = require('axios');

const callApi = async (endpoint) => {
  let result = [];

  try {
    const { data } = await axios.get(`https://steemmonsters.com/${endpoint}`);
    result = data;
  } catch (e) {
    console.log(e);
  }

  return result;
};

const callHistoryApi = async (player, fromBlock = -1, beforeBlock = null, limit = 250) => {
  let result = [];
  try {
    const params = {
      username: player,
      from_block: fromBlock,
      limit,
      types: 'sm_open_pack,open_pack,sm_open_all,open_all',
    };

    if (beforeBlock) params.before_block = beforeBlock;

    const query = await axios.get('https://api.steemmonsters.io/players/history', { params });

    result = query.data;
  } catch (e) {
    console.log(e.message);
  }

  return result;
};

(async () => {
  const player = 'reazuliqbal'; // Your steem username
  const edition = 1; // 0 = Alpha, 1 = Beta, 2 = Promo
  const packsOpened = 100; // Number of packs to check

  // Might not needed to edit below this line
  const cards = [];
  let packs = 0;
  let beforeBlock = null;

  const market = await callApi('market/for_sale_grouped');
  const settings = await callApi('settings');

  do {
    let history = await callHistoryApi(player, -1, beforeBlock);

    history = history
      .filter((h) => h.success)
      .map((h) => ({
        id: h.id,
        type: h.type,
        block: h.block_num,
        data: JSON.parse(h.data),
        ...JSON.parse(h.result),
      }));

    history.forEach((h) => {
      if (h.data.edition === edition && packs < packsOpened) {
        packs += (h.data.qty) ? h.data.qty : 1;

        cards.push(...h.cards);
      }

      beforeBlock = (h.block - 1);
    });
  } while (packs < packsOpened);

  let usdPrice = 0;
  let steemPrice = 0;
  let sbdPrice = 0;
  let decPrice = 0;

  cards.forEach((c) => {
    const marketPrice = market.find((m) => m.card_detail_id === c.card_detail_id
      && m.gold === c.gold
      && m.edition === c.edition);

    usdPrice += marketPrice.low_price;
    steemPrice += marketPrice.low_price / settings.steem_price;
    sbdPrice += marketPrice.low_price / settings.sbd_price;
    decPrice += marketPrice.low_price / settings.dec_price;
  });

  console.log('Packs Opened:', packs);
  console.log('Cards prices in:');
  console.log('\tUSD:', usdPrice.toFixed(3));
  console.log('\tSTEEM:', steemPrice.toFixed(3));
  console.log('\tSBD:', sbdPrice.toFixed(3));
  console.log('\tDEC:', decPrice.toFixed(3));
})();

Here is the Gist.

To use the script you need to have Node JS installed and a bit knowledge about how to install a npm package.

  • Download or copy paste the code to a JS file inside a folder. Make changes to line #41-43 according to your needs.
  • Install axios npm package using this command npm i axios.
  • Now command node your_js_filename.js

You'll get your results like this

Screenshot from 2019-10-05 11-03-59.png

This script might have some limitations or the value shown might not be accurate. Please use at your own risk.

Carbon was used for the cover image. 5% post rewards goes to Steem DAO.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

The quick way:

git clone https://gist.github.com/563ba009a5d08b3c7865c607595096af.git
cd 563ba009a5d08b3c7865c607595096af
npm i axios
node splinterlands-pack-openings.js

Thanks :)

Nice work!

Thanks.

Excellent work, dude. Now I do not have to manually check each card's prices and put on to the spreadsheet. Keep up the good work. 👍

~ BDVoter Team

Glad that it would help. :)

This post has been included in the latest edition of The Steem News - a compilation of the key news stories on the Steem blockchain.

Pretty awesome tool to get the value of the packs instead of using excel or some other way to keep track of the cards and sum all of their value. Sharing is caring, so much apreciated to have this piece of code available for everybody to use.

I am glad it would help and you liked it.

nice tool!

Thank :)