@crl-technologies/sdk
v2.0.1
Published
CRL White Label API - TypeScript SDK with HMAC authentication
Maintainers
Readme
@crl-technologies/sdk
Official TypeScript/JavaScript SDK for CRL White Label API with production-ready HMAC authentication.
Installation
npm install @crl-technologies/sdkQuick Start
import { CRLApiClient } from '@crl-technologies/sdk';
// Initialize client (uses production endpoint by default)
const client = new CRLApiClient({
keyId: process.env.CRL_KEY_ID!,
secretKey: process.env.CRL_SECRET_KEY!
});
// Calculate Long CRL position
const result = await client.calculateLong(
100.0, // S0 - Entry price
110.0, // ST - Current price
105.0, // K - Strike price
5.0, // L - Leverage multiplier
2.5 // Premium paid
);
console.log(`P&L: ${result.pnl}`);
console.log(`State: ${result.state}`);
console.log(`Retro Jump: ${result.retroJump}`);Configuration
Default Configuration (v2.0.0+)
The SDK uses the production endpoint by default:
const client = new CRLApiClient({
keyId: "your-api-key",
secretKey: "your-secret-key"
// baseUrl defaults to: https://crl-api.crl-technologies.com
});Custom Base URL
Override for testing or custom deployments:
const client = new CRLApiClient({
keyId: "your-api-key",
secretKey: "your-secret-key",
baseUrl: "https://staging.crl-technologies.com" // Custom endpoint
});API Reference
calculateLong(S0, ST, K, L, premium): Promise<CalcResponse>
Calculate P&L for a LONG position with Conditional Retro-Leverage.
Parameters:
S0(number): Entry priceST(number): Current/Exit priceK(number): Strike price (trigger level)L(number): Leverage multiplier (applied retroactively if triggered)premium(number): Premium paid for the CRL feature
Returns: Promise<CalcResponse>
interface CalcResponse {
pnl: number; // Profit & Loss
state: string; // 'INITIAL' | 'LEVERAGED'
retroJump: number; // Additional P&L from retro-leverage
calcId: string; // Unique calculation ID
}Example:
const result = await client.calculateLong(100, 110, 105, 5, 2.5);
// Entry at 100, current price 110, strike at 105
// If ST > K: retroactive 5x leverage applied from S0 to KcalculateShort(S0, ST, K, L, premium): Promise<CalcResponse>
Calculate P&L for a SHORT position with Conditional Retro-Leverage.
Parameters: Same as calculateLong()
Example:
const result = await client.calculateShort(100, 90, 95, 5, 2.5);
// Entry at 100, current price 90, strike at 95
// If ST < K: retroactive 5x leverage applied from S0 to KAuthentication
The SDK uses HMAC-SHA256 authentication with automatic request signing.
Required Headers (handled automatically):
X-API-Key: Your tenant API keyX-CRL-Timestamp: Unix timestampX-CRL-Signature: HMAC signature of the request
Signature Construction:
HMAC-SHA256(secret, "METHOD|PATH|TIMESTAMP|BODY")Error Handling
try {
const result = await client.calculateLong(100, 110, 105, 5, 2.5);
console.log(result);
} catch (error) {
if (error.response?.status === 401) {
console.error('Authentication failed - check your credentials');
} else if (error.response?.status === 429) {
console.error('Rate limit exceeded');
} else {
console.error('API error:', error.message);
}
}Environment Variables
Recommended setup:
# .env file
CRL_KEY_ID=your-tenant-key-id
CRL_SECRET_KEY=your-secret-key
CRL_BASE_URL=https://crl-api.crl-technologies.com # Optional (default)import { CRLApiClient } from '@crl-technologies/sdk';
const client = new CRLApiClient({
keyId: process.env.CRL_KEY_ID!,
secretKey: process.env.CRL_SECRET_KEY!,
baseUrl: process.env.CRL_BASE_URL // Optional override
});TypeScript Support
Full TypeScript support with type definitions included:
import { CRLApiClient, CalcRequest, CalcResponse } from '@crl-technologies/sdk';
const request: CalcRequest = {
mode: 'long',
S0: 100,
ST: 110,
K: 105,
L: 5,
premium: 2.5,
side: 'buy'
};Production Endpoints
| Endpoint | Method | Description |
|----------|--------|-------------|
| /v1/calc | POST | Calculate CRL position P&L |
| /health | GET | Health check (no auth required) |
Base URL: https://crl-api.crl-technologies.com
Migration from v1.x
See CHANGELOG.md for detailed migration guide.
Summary:
- v2.0.0 uses production URL by default (
https://crl-api.crl-technologies.com) - Removed non-existent best-execution endpoints
- Fixed endpoint path (
/v1/calcinstead of/api/v1/calc)
If you're using custom baseUrl, no changes required.
Support
- Documentation: GitHub Repository
- Issues: GitHub Issues
- Email: [email protected]
License
PROPRIETARY - CRL Technologies Inc.
Version: 2.0.0
Last Updated: 2025-11-15
