forked from tuhinpal/WhatsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Support for Fetching Live CryptoCurrency Prices
- Loading branch information
1 parent
a15ff04
commit 2a90ea5
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Coded by Sumanjay (https://github.com/cyberboysumanjay) | ||
const axios = require('axios'); | ||
|
||
async function getPrice(cryptoCode) { | ||
cryptoCode = cryptoCode.toUpperCase() | ||
var mainconfig = { | ||
method: 'get', | ||
url: 'https://public.coindcx.com/market_data/current_prices' | ||
} | ||
return axios(mainconfig) | ||
.then(async function (response) { | ||
var data = response.data | ||
var cryptoCodeINR = cryptoCode + "INR" | ||
if (data.cryptoCode != undefined || data.cryptoCodeINR != undefined) { | ||
cryptoCode = data.cryptoCode == undefined ? cryptoCodeINR : cryptoCode | ||
var out = ({ | ||
name: cryptoCode, | ||
price: data.cryptoCode | ||
}) | ||
return out | ||
} else { | ||
return "unsupported" | ||
} | ||
}) | ||
.catch(function (error) { | ||
return "error" | ||
}) | ||
} | ||
|
||
|
||
module.exports = { | ||
getPrice | ||
} |