-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from vikrampatel0408/CryptoApis
Added CryptoApi
- Loading branch information
Showing
20 changed files
with
10,638 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Holdlinfo | ||
|
||
## git clone the repository | ||
## Go to file | ||
## configure Database | ||
## write on terminal npm start | ||
## go to browser and search http://localhost:8000/api/view/wazirx/data to view data | ||
if data is not added search http://localhost:8000/api/add/wazirx/data |
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,19 @@ | ||
const express = require('express'); | ||
const bodyParser = require('body-parser') | ||
const path = require('path') | ||
global.appRootPath = __dirname | ||
const app = express(); | ||
|
||
|
||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({ extended: true })) | ||
/* global appRootPath */ | ||
app.use(express.static(path.join(appRootPath, 'public'))) | ||
app.set('view engine', 'ejs') | ||
app.use('/', require('./routes')) | ||
require('dotenv').config(); | ||
|
||
|
||
app.listen(process.env.PORT, () => { | ||
console.log('Magic happens on port :' + process.env.PORT) | ||
}); |
68 changes: 68 additions & 0 deletions
68
Existing_API_Collection/CryptoCurrenciesAPIs/controllers.js
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,68 @@ | ||
const axios = require('axios') | ||
require('dotenv').config() | ||
const CurrencyModel = require('./model') | ||
const fs = require('fs') | ||
const ejs = require('ejs') | ||
|
||
async function addWazirxData(req, res) { | ||
try { | ||
|
||
// Take Data from WazirX for Data | ||
let response = await axios.get(process.env.WAZIR_URL) | ||
response = Object.values(response.data).slice(0,10) | ||
|
||
// Create DB Object | ||
|
||
const aCurrencyData = [] | ||
for (const data of response) { | ||
aCurrencyData.push({ | ||
sBaseUnit: data.base_unit, | ||
sQuoteUnit: data.quote_unit, | ||
sLowPrice: data.low, | ||
sHighPrice: data.high, | ||
sLastPrice: data.last, | ||
sType: data.type, | ||
sOpenPrice: data.open, | ||
sVolume: data.volume, | ||
sSell: data.sell, | ||
sBuy: data.buy, | ||
sName: data.name | ||
}) | ||
} | ||
|
||
// Insert WazirX Data in Bulk | ||
const result = await CurrencyModel.create(aCurrencyData) | ||
|
||
res.status(201).send(result) | ||
} catch (error) { | ||
console.log(error) | ||
throw Error(error) | ||
} | ||
} | ||
|
||
async function viewWazirxData(req, res) { | ||
try { | ||
// Fetch Data from DB | ||
const aCurrencyData = await CurrencyModel.find({}).limit(10).lean() | ||
console.log(aCurrencyData[0]) | ||
var iAverage; | ||
var iSum= 0 ; | ||
aCurrencyData.forEach(element => { | ||
iSum += parseInt(element.sBuy); | ||
}); | ||
iAverage = iSum/10; | ||
const template = fs.readFileSync('views/' + 'home.ejs', { | ||
encoding: 'utf-8' // Unicode Transformation Format (UTF). | ||
}) | ||
const renderedData = ejs.render(template, { average:iAverage, response: aCurrencyData, title: 'Vikram Patel' }) | ||
return res.status(201).send(renderedData) | ||
} catch (error) { | ||
console.log(error) | ||
throw Error(error) | ||
} | ||
} | ||
|
||
async function test(req, res) { | ||
console.log('test') | ||
} | ||
module.exports = { addWazirxData, viewWazirxData, test } |
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,19 @@ | ||
const mongoose = require('mongoose') | ||
|
||
|
||
const dbConnect = connection(process.env.DB_URL, parseInt(process.env.DB_POOL_SIZE), 'internship') | ||
function connection(DB_URL, maxPoolSize = 10, DB) { | ||
try { | ||
const dbConfig = { useNewUrlParser: true, useUnifiedTopology: true, readPreference: 'secondaryPreferred' } | ||
|
||
const conn = mongoose.createConnection(DB_URL, dbConfig) | ||
conn.on('connected', () => console.log(`Connected to ${DB} database.`)) | ||
return conn | ||
} catch (error) { | ||
handleCatchError(error) | ||
} | ||
} | ||
|
||
module.exports = { | ||
dbConnect | ||
} |
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,24 @@ | ||
const mongoose = require('mongoose') | ||
const Schema = mongoose.Schema | ||
const { dbConnect } = require('./database') | ||
|
||
const Currency = new Schema({ | ||
// Currency Data | ||
sBaseUnit: { type: String }, | ||
sQuoteUnit: { type: String }, | ||
sLowPrice: { type: String }, | ||
sHighPrice: { type: String }, | ||
sLastPrice: { type: String }, | ||
sType: { type: String }, | ||
sOpenPrice: { type: String || Number }, | ||
sVolume: { type: String }, | ||
sSell: { type: String }, | ||
sBuy: { type: String }, | ||
sName: { type: String } | ||
}, | ||
{ timestamps: { createdAt: 'dCreatedAt', updatedAt: 'dUpdatedAt' } }) | ||
|
||
|
||
const CurrencyModel = dbConnect.model('currencies', Currency) | ||
|
||
module.exports = CurrencyModel; |
Oops, something went wrong.