@monarkmarkets/api-client v1.0.4
@monarkmarkets/api-client
This package provides a TypeScript client for interacting with the Monark Markets API.
Installation
npm install @monarkmarkets/api-clientUsage
To use this client, you'll need to set up a simple proxy server that forwards requests to the Monark API with the appropriate authentication.
Important: API Proxy Server Requirement
This client requires a server running under the /api path that forwards requests to the Monark API with authentication. This proxy server:
- Injects authentication credentials
- Forwards all requests to the Monark API
- Returns the responses to the client
Setting up a Proxy Server
Below is an example of a minimal Express.js server that forwards requests to the Monark API:
// server.js
import express from 'express';
import axios from "axios";
import * as dotenv from 'dotenv';
dotenv.config();
const app = express();
const API_BASE_URL = process.env.API_BASE_URL || 'https://demo-api.monark-markets.com';
const AUTH_TOKEN = process.env.AUTH_TOKEN;
// Parse JSON payloads
app.use(express.json());
// API router for forwarding requests
const apiRouter = express.Router();
apiRouter.use('*', async (req, res) => {
try {
// Build the target URL by combining base URL and original path
let targetUrl = `${API_BASE_URL}${req.originalUrl}`;
targetUrl = targetUrl.replace("/api/", "/");
// Forward the request to the target API
const response = await axios({
method: req.method,
url: targetUrl,
data: req.body,
headers: {
// Add the authorization header
'Authorization': `Bearer ${AUTH_TOKEN}`
},
// Forward query parameters
params: req.query,
// Handle binary responses
responseType: 'arraybuffer'
});
// Set response headers
Object.entries(response.headers).forEach(([key, value]) => {
// Skip Transfer-Encoding header to prevent conflicts with Express
if (key.toLowerCase() !== 'transfer-encoding') {
res.set(key, value);
}
});
// Send response
res.status(response.status).send(response.data);
} catch (error) {
// Handle errors from the target API
if (error.response) {
res.status(error.response.status).send(error.response.data);
} else {
res.status(500).json({
error: 'Internal Server Error',
message: error.message
});
}
}
});
// Mount API router - all API routes will be prefixed with /api
app.use('/api', apiRouter);
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`API proxy server running on port ${PORT}`);
});Environment Variables
Create a .env file in your project root:
API_BASE_URL=https://demo-api.monark-markets.com
AUTH_TOKEN=your_auth_token_hereUsing the Client
import { Client } from '@monarkmarkets/api-client';
// Initialize the client with the proxy API URL
const client = new Client('/api');
// Example: Get all PreIPOCompanies
async function getAllPreIPOCompanies() {
try {
// You can add optional parameters for search, pagination, etc.
const result = await client.preIpoCompany2(
undefined, // searchTerm (optional)
undefined, // sortOrder (optional)
1, // page
10 // pageSize
);
console.log(`Found ${result.pagination?.totalRecords || 0} companies`);
console.log('Companies:', result.items);
return result;
} catch (error) {
console.error('Error fetching PreIPO companies:', error);
throw error;
}
}
// Call the function
getAllPreIPOCompanies();Authentication
The API client itself doesn't handle authentication. Instead, authentication happens at the proxy server level by including the AUTH_TOKEN in the forwarded requests.
API Methods
The client provides methods for all API endpoints in the Monark API. Some examples include:
preIpoCompany2()- Get all PreIPO companiespreIpoCompany(id)- Get a PreIPO company by IDindicationOfInterestPOST(body)- Create an indication of interestinvestorGET(id)- Get investor information- And many more...
For the full list of available methods, refer to the TypeScript definitions in the client code.
The full API documentation can be found here: https://api-docs.monark-markets.com/