StatBot was implemented into #teammalaysia few weeks ago, but there exist a bug on the conversion to MYR (Malaysian Ringgit).
statBot
Commits to github repo
Bug Fixes
- What was the issue(s)?
- Wrongly converted MYR ratio.
- The reason why this happen because the API that I use mistook MYR as MyriadCoin
- Wrongly converted MYR ratio.
- 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 incrypto.jsonfrom this github repo by@codingdefined.
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/ssuggested 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.jsusing 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.jsRoadmap
- 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