Created
October 5, 2019 04:55
-
-
Save reazuliqbal/563ba009a5d08b3c7865c607595096af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment