-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (41 loc) · 1.58 KB
/
index.js
File metadata and controls
57 lines (41 loc) · 1.58 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
52
53
54
55
56
57
const express = require('express');
const bodyParser = require('body-parser');
const { formatFixMessage, explainFixMessage } = require('./fixFormatter');
const app = express();
const port = 14001;
// Middleware to parse JSON payloads
app.use(bodyParser.json());
// Endpoint to convert stock data to FIX protocol and show what each means
app.post('/convert-to-fix-deparsed', (req, res) => {
const stockData = req.body;
// Validate the incoming data
if (!stockData.symbol || !stockData.price || !stockData.quantity || !stockData.clOrdId) {
return res.status(400).json({ error: 'Missing required stock data: symbol, price, quantity, or clOrdId' });
}
// Convert to FIX format
const fixMessage = formatFixMessage(stockData);
// Annotate the FIX message with explanations
const explainedFix = explainFixMessage(fixMessage);
// Return FIX message and explanation as the response
res.json({
fixMessage,
explainedFix
});
});
app.post('/fix', (req, res) => {
const stockData = req.body;
// Validate the incoming data
if (!stockData.symbol || !stockData.price || !stockData.quantity || !stockData.clOrdId) {
return res.status(400).json({ error: 'Missing required stock data: symbol, price, quantity, or clOrdId' });
}
// Convert to FIX format
const fixMessage = formatFixMessage(stockData);
// Return FIX message and explanation as the response
res.json({
fixMessage,
});
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});