Skip to content

Commit

Permalink
Merge pull request #4 from Rahul-Prasad-07/server/redis-2
Browse files Browse the repository at this point in the history
Server/redis 2 : added price converter api
  • Loading branch information
Rahul-Prasad-07 authored Sep 13, 2023
2 parents a43fa64 + afadc8d commit ba0d921
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 119 deletions.
208 changes: 208 additions & 0 deletions server/Crypto-Server.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,214 @@
}
},
"response": []
},
{
"name": "volume_24",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/SOL/volume_24h",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"SOL",
"volume_24h"
]
}
},
"response": []
},
{
"name": "volume_change_24h",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/ETH/volume_change_24h",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"ETH",
"volume_change_24h"
]
}
},
"response": []
},
{
"name": "percent_change_1h",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/SOL/percent_change_1h",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"SOL",
"percent_change_1h"
]
}
},
"response": []
},
{
"name": "percent_change_24h",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/ETH/percent_change_24h",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"ETH",
"percent_change_24h"
]
}
},
"response": []
},
{
"name": "percent_change_7d",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/LINK/percent_change_7d",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"LINK",
"percent_change_7d"
]
}
},
"response": []
},
{
"name": "percent_change_30d",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/ADA/percent_change_30d",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"ADA",
"percent_change_30d"
]
}
},
"response": []
},
{
"name": "market_cap",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/ETH/market_cap",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"ETH",
"market_cap"
]
}
},
"response": []
},
{
"name": "market_cap_dominance",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3000/crypto/ADA/market_cap_dominance",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"crypto",
"ADA",
"market_cap_dominance"
]
}
},
"response": []
},
{
"name": "convert",
"request": {
"method": "GET",
"header": [
{
"key": "X-CMC_PRO_API_KEY",
"value": "e3cbef6e-746b-4f11-8c34-3ebe787cb615",
"type": "text"
}
],
"url": {
"raw": "http://localhost:3000/Crypto/price-convert?amount=1&symbol=LINK&convert=INR",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"Crypto",
"price-convert"
],
"query": [
{
"key": "amount",
"value": "1"
},
{
"key": "symbol",
"value": "LINK"
},
{
"key": "convert",
"value": "INR"
}
]
}
},
"response": []
}
]
}
1 change: 1 addition & 0 deletions server/controller/Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Controllers for api
1 change: 1 addition & 0 deletions server/middleware/Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Middlewars for api
44 changes: 43 additions & 1 deletion server/routes/CryptoCurrency.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as redis from 'redis';
import * as redis from "redis";
import express from "express";
import axios from "axios";
const router = express.Router();
Expand Down Expand Up @@ -28,6 +28,48 @@ const api = axios.create({
},
});

// Create an Axios instance for API requests
const apipc = axios.create({
baseURL: "https://pro-api.coinmarketcap.com/v2/tools",
headers: {
"X-CMC_PRO_API_KEY": API_KEY,
Accept: "application/json",
},
});

// Define a new route to convert cryptocurrency price
router.get("/price-convert", async (req, res) => {
try {
// Extract query parameters from the request
const { amount, symbol, convert } = req.query;

// Make an API request to CoinMarketCap for price conversion
const response = await apipc.get("/price-conversion", {
params: {
amount,
symbol,
convert,
},
});

// Check if the response is successful
if (response.status === 200) {
// Extract the converted price from the response
//@ts-ignore
const convertedPrice = response.data.data[0].quote[convert].price;

// Send the converted price as a JSON response
res.json({ convertedPrice });
} else {
// Handle API error response
res.status(response.status).json({ error: response.data.error.message });
}
} catch (err) {
console.error(err);
res.status(500).json({ error: "An error occurred" });
}
});

router.get("/top20", async (req, res) => {
try {
const catchData = await redisClient.get("top20");
Expand Down
117 changes: 0 additions & 117 deletions server/routes/cryptoData.ts

This file was deleted.

Loading

0 comments on commit ba0d921

Please sign in to comment.