api for ETH and TRX

This commit is contained in:
root 2025-01-13 01:59:10 +03:00
parent f76d9a179a
commit 6a0b8f5312
3 changed files with 1367 additions and 27 deletions

View File

@ -1,25 +1,46 @@
import fetch from 'node-fetch'
import express from 'express'
import sqlite3 from 'sqlite3'
sqlite3.verbose()
const app = express()
const db = '../db'
const db = new sqlite3.Database('../db')
const port = 3102
app.get('/ETH/:date', async (req, res) => {
const response = await fetch(`https://api.coingecko.com/api/v3/coins/ethereum/history?date=${req.params.date}`)
const data = await response.json()
res.send(data.market_data.current_price.rub.toString())
})
app.get('/TRX/:date', async (req, res) => {
const response = await fetch(`https://api.coingecko.com/api/v3/coins/tron/history?date=${req.params.date}`)
const data = await response.json()
res.send(data.market_data.current_price.rub.toString())
})
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})
process
.on('unhandledRejection', () => {})
.on('uncaughtException', () => {})
.on('unhandledRejection', console.log)
.on('uncaughtException', console.log)
db.serialize(async () => {
app.get('/ETH/:date', async (req, res) => {
const date = new Date(req.params.date)
if(date.toString() == 'Invalid Date') {
res.send('Invalid Date')
return
}
db.each(`SELECT * FROM assets WHERE asset = 'ETH' AND date = ${Number(date)} LIMIT 1`, (err, row) => {
res.send(row.price.toString())
}, (err, count) => {
if(count == 0) {
res.send('Invalid Date')
}
})
})
app.get('/TRX/:date', async (req, res) => {
const date = new Date(req.params.date)
if(date.toString() == 'Invalid Date') {
res.send('Invalid Date')
return
}
db.each(`SELECT * FROM assets WHERE asset = 'TRX' AND date = ${Number(date)} LIMIT 1`, (err, row) => {
res.send(row.price.toString())
}, (err, count) => {
if(count == 0) {
res.send('Invalid Date')
}
})
})
app.listen(port, () => {
console.log(`App listening on port ${port}`)
})
})

1321
api/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,15 +4,15 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.21.2",
"node-fetch": "^3.3.2",
"nodemon": "^3.1.9"
"express": "^4.21.2",
"node-fetch": "^3.3.2",
"nodemon": "^3.1.9",
"sqlite3": "^5.1.7"
},
"type": "module"
}
}