-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (40 loc) · 1.18 KB
/
server.js
File metadata and controls
51 lines (40 loc) · 1.18 KB
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
48
49
50
51
const express = require("express");
const parser = require("body-parser");
const cors = require("cors");
const dotenv = require("dotenv");
dotenv.config();
const { placeOrder } = require("./binance");
const { sendText } = require("./nodemailer");
const PORT = process.env.PORT;
const app = express();
app.use(cors());
app.use(parser.json());
app.use(
parser.urlencoded({
extended: true,
})
);
app.post("/trade", async (req, res) => {
const { tradingPair, coinOne, coinTwo, orderType } = req.body;
let status = undefined;
// Send order recieved text
sendText(`🤖 An order to ${orderType} ${coinOne} was sent to Binance Bot.`);
console.log(
`🤖 An order to ${orderType} ${coinOne} was sent to Binance Bot.`
);
// Place the order if variables are not undefined, else log warning
if (
tradingPair !== undefined &&
coinOne !== undefined &&
coinTwo !== undefined &&
orderType !== undefined
) {
status = await placeOrder(tradingPair, coinOne, coinTwo, orderType);
} else {
console.log("❗ One of the variables was undefined");
}
res.status(200).json(status);
});
app.listen(PORT, () => {
console.log("App is listening on PORT: ", PORT);
});