-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (40 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const candleService = require('./src/services/candles')
const candleHandler = require('./src/handlers/candles')
const trackerHandler = require('./src/handlers/tracker')
const db = require('./src/models')
const express = require('express')
const app = express();
startApp = async() => {
console.log("Conecting to DB");
db.mongoose.connect(db.url, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log("Conected to DB");
candleService.createCandle() //Starts creating candles.
candleService.trackOperations() //Starts listening for operations from router tracker.
await setInterval(async () => {
console.log("Closing and creating new candle")
candleService.closeCandle()
candleService.createCandle()
}, 60000);
}
startApp()
app.use(express.json());
app.get('/ping', (req,res) =>{
res.status(200).send('pong')
})
app.get('/bsc/:pair/candlesticks', async function(req,res){
/* Get candles for a given pair */
const response = await candleHandler.getCandles(req.params.pair, req.query.timeframe)
res.status(response.code).send(response)
});
app.post('/bsc/:token/track', async function(req,res){
/* Post a token to start tracking*/
const response = await trackerHandler.startTracking(req.params.token)
res.status(response.code).send(response)
});
const server = app.listen(process.env.PORT || 8080, () => {
const { port } = server.address();
console.log('TRADING APP listening at http://localhost:%s', port);
});