Here's an example of how you might implement these endpoints in an Express.js application:
javascript
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const app = express();
app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
secret: 'your_secret_key',
resave: false,
saveUninitialized: true,
cookie: { secure: true } // Use secure cookies in production
}));
// Dummy order data for demonstration purposes
const orders = [
{ refno: '1', userid: 'runzhuo.li@fundamentalinteractions.com', security: 'TESTN', side: 'B', qty: 100, price: 50, ordertype: 'LMT', tif: 'GTC', timestamp: 1671195975792 },
// Add more orders as needed
];
// Add New Order
app.post('/firestapi/orders/limit', (req, res) => {
const { security, side, qty, price, ordertype, tif } = req.body;
// Perform necessary validations here
const newOrder = {
userid: req.session.userid,
// When connected to the websocket we do not use userid but token
security,
side,
qty,
price,
ordertype,
tif,
};
orders.push(newOrder);
res.status(201).json(newOrder);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
This example sets up the specified routes using Express.js and handles retrieving user orders, retrieving an order by reference number, and adding new orders. It includes necessary validations and error handling for the endpoints.
Here's an example of how you might implement these endpoints in an Express.js application:
javascript
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const app = express();
app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
secret: 'your_secret_key',
resave: false,
saveUninitialized: true,
cookie: { secure: true } // Use secure cookies in production
}));
// Dummy order data for demonstration purposes
const orders = [
{ refno: '1', userid: 'runzhuo.li@fundamentalinteractions.com', security: 'TESTN', side: 'B', qty: 100, price: 50, ordertype: 'LMT', tif: 'GTC', timestamp: 1671195975792 },
// Add more orders as needed
];
// Add New Order
app.post('/firestapi/orders/market', (req, res) => {
const { security, side, qty, price } = req.body;
// Perform necessary validations here
const newOrder = {
userid: req.session.userid,
// When connected to the websocket we do not use userid but token
security,
side,
qty,
price,
ordertype: "MKT",
tif: "GTC",
};
orders.push(newOrder);
res.status(201).json(newOrder);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
This example sets up the specified routes using Express.js and handles retrieving user orders, retrieving an order by reference number, and adding new orders. It includes necessary validations and error handling for the endpoints.