statBot bug fix on MYR conversion and added testing

Words
251
Reading
2 min
9y
Listen to this post
~2 min

StatBot was implemented into #teammalaysia few weeks ago, but there exist a bug on the conversion to MYR (Malaysian Ringgit).

favicon.png


statBot

Screen Shot 2018-02-11 at 10.35.25 AM.png
Commits to github repo

Bug Fixes

  • What was the issue(s)?
    • Wrongly converted MYR ratio.
      Screen Shot 2018-02-11 at 10.09.55 AM.png
    • The reason why this happen because the API that I use mistook MYR as MyriadCoin
  • What was the solution?
    • Use coinmarketcap's API
    • Since coinmarketcap's required long name (e.g. steem-dollars), I use hardcoded Short name and Long name pair in crypto.json from this github repo by codingdefined@codingdefined.

Screen Shot 2018-02-11 at 10.37.10 AM.png
Fixed bug

New Features

What feature(s) did you add?

  • The price now is using CoinMarketCap API, and MYR is correctly converted
  • A basic testing is added.
  • Added sbd/s suggested by awesomianist@awesomianist

How did you implement it/them?

  • Price Codes
    crypto.json example
  "steem-dollars": "steem-dollars",
  "sbd": "steem-dollars",
  • Get price with axios library in api.js using functions
let getOnlyPrice = async (coin, currency) => {
  let res = await axios.get(
    `https://api.coinmarketcap.com/v1/ticker/${crypto[coin]}/?convert=${currency}`
  ).catch((err) => 'Wrong Coin');
  let price = res.data[0][`price_${currency.toLowerCase()}`] || '-';
  return price;
};
let countRatio = async (coin1, coin2) => {
  let coinPrice1, coinPrice2;
  return await getOnlyPrice(coin1, 'USD')
    .then(price1 => {
      coinPrice1 = price1;
      return getOnlyPrice(coin2, 'USD').then(price2 => price2);
    })
    .then(price2 => {
      coinPrice2 = price2;
    })
    .then(() => {
      return coinPrice1/coinPrice2;
    });
};
  • Testing
import { getPrice, getOnlyPrice, countRatio } from '../api';
// api.js
getPrice('steem', 'usd').then(data =>
  console.log(`getPrice of Steem: ${data}`)
);
getOnlyPrice('steem', 'usd').then(data =>
  console.log(`getOnlyPrice of Steem: ${data}`)
);
countRatio('steem', 'sbd').then(data =>
  console.log(`countRatio of Steem/SBD: ${data}`)
);

About the Projects

  • What is the project about?
    Most of our member are on discord all the time, won't it be nice that everything can be done on discord? Therefore, I had this idea of creating a bot that solves my problem, and maybe others too! This bot currently holds utility feature for all steemit user!

  • Technology Stack
    Node.js

  • Roadmap

    • Suitable use of SteemSQL to query useful statistics (User status, etc)
    • Create an API server instead of inbound SQL queries to seperate API backend with Discord Front end
  • How to contribute?
    This project repo is on GitHub with MIT License. Pull Request Contribution and Issue Filling are welcome.



Posted on Utopian.io - Rewarding Open Source Contributors

statBot bug fix on MYR conversion and added testing | Ecency