SIMPLIFIED ORDERS
Splits the order route into multiple routes for clearer error handling
1. Limit orders
HTTP Request Type: POST
Route:
/firestapi/orders/limit
URL / Body Parameters:
Required:
security
: "TESTJ"side
: "B" (Buy) or "S" (Sell)qty
: The quantity to buy or sell.price
: The unit price.ordertype
: "LMT" (Limit), "POST" (Post Only), "ICEBERG", "STOP"If
ordertype:"ICEBERG", displayqty
is required.If
ordertype:"STOP", stopprice
is required.tif
: "GTC" (Good Till Cancelled), "IOC" (Immediate Or Cancel), "GTT" (Good Till Time), "FOK" (Fill Or Kill), "DAY" (Day)tif: "GTT"
If set to GTT we also need inputexptime
Info: Adds a new order.
HTTPS Body Example:
json
{
"security": "TESTJ",
"side": "B",
"qty": 100,
"price": 50,
"ordertype": "LMT",
"tif": "GTC"
}
WS Example:
json
{
"type": "addorder",
"security": "TESTJ",
"side": "B",
"qty": 100,
"price": 50,
"ordertype": "LMT",
"tif": "GTC",
}
Example Implementation in Express.js
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.
2. Market orders
HTTP Request Type: POST
Route:
/firestapi/orders/market
URL / Body Parameters:
Required:
security
: "TESTJ"side
: "B" (Buy) or "S" (Sell)qty
: The quantity to buy or sell.price
: The unit price.
Info: Adds a new order.
HTTPS Body Example:
json
{
"security": "TESTJ",
"side": "B",
"qty": 100,
"price": 50,
}
WS Example:
json
{
"type": "addorder",
"security": "TESTJ",
"side": "B",
"qty": 100,
"price": 50,
"ordertype": "MKT",
"tif": "GTC"
}
Example Implementation in Express.js
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.
Last updated