The Securities section of the RESTAPI allows subscribers to perform various operations related to securities, including listing, retrieving details, adding, and modifying securities
Endpoints
1. Get Currency List
HTTP Request Type: GET
Route:/firestapi/securities?deposit=true
URL / Body Parameters: None
Info: Lists all the currencies registered in the system, including FIAT and Cryptocurrency.
2. Get Tradeable Pairs
HTTP Request Type: GET
Route:/firestapi/securities?pair=true
URL / Body Parameters: None
Info: Lists all the tradeable pairs. This is the same route as above with a different URL parameter.
3. Get Instrument Details
HTTP Request Type: GET
Route:/firestapi/securities/:security
URL / Body Parameters::security - the symbol of the security.
Info: Provides details of an individual pair. The route will check if the entered symbol is tradable or not before returning the information.
Info: Adds a new security. When creating a crypto-pair, this request will throw an error if the firstpair + secondpair does not equal the security string.
fractionbase: Number (### HEAVY WARNING IF YOU HAVE LIVE ORDERS ###)
description: String
name: String
priceprecision: Number
OPTIONAL IF TYPE trading:
comm: Number
Info: Edits an existing security. The route checks if the security being edited exists, then follows similar constraints for the create route based on the type of security ("deposit", "trading", "crypto-pair").
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 data for demonstration purposes
const securities = [
{ security: 'BTCUSD', type: 'crypto-pair', fractionbase: 1000000, firstpair: 'BTC', secondpair: 'USD', priceprecision: 100 },
// Add more securities as needed
];
// Get Currency List
app.get('/firestapi/securities', (req, res) => {
if (req.query.deposit === 'true') {
// Return the list of currencies
res.status(200).json(securities.filter(s => s.type === 'deposit'));
} else if (req.query.pair === 'true') {
// Return the list of tradeable pairs
res.status(200).json(securities.filter(s => s.type === 'crypto-pair'));
} else {
res.status(400).send('Invalid query parameter');
}
});
// Get Instrument Details
app.get('/firestapi/securities/:security', (req, res) => {
const security = securities.find(s => s.security === req.params.security);
if (security) {
res.status(200).json(security);
} else {
res.status(404).send('Security not found or not tradable');
}
});
// Add New Security
app.post('/firestapi/securities', (req, res) => {
const { security, type, fractionbase, description, name, clearinginstrument, comm, priceprecision, firstpair, secondpair } = req.body;
// Perform necessary validations here
securities.push({ security, type, fractionbase, description, name, clearinginstrument, comm, priceprecision, firstpair, secondpair });
res.status(201).send('Security added successfully');
});
// Modify Existing Security
app.post('/firestapi/securities/:security', (req, res) => {
const { security } = req.params;
const { fractionbase, description, name, priceprecision, comm } = req.body;
const existingSecurity = securities.find(s => s.security === security);
if (existingSecurity) {
// Perform updates and necessary validations here
Object.assign(existingSecurity, { fractionbase, description, name, priceprecision, comm });
res.status(200).send('Security updated successfully');
} else {
res.status(404).send('Security not found');
}
});
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, handles getting currency lists, getting instrument details, adding new securities, and modifying existing securities. It includes the necessary validations and error handling for the endpoints.