statBot bug fix on MYR conversion and added testing

in #utopian-io7 years ago (edited)

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.

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

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

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank you moderator.

@superoo7, I always try to support who contribute to open source project, upvote you.

Boss, I just realized the logo is S7 😍. Cool la. Reminds me of the legendary Selene S7

Its not S7, it means superoo7, 😂

Hey @superoo7 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63592.23
ETH 2551.58
USDT 1.00
SBD 2.75