cipher-ai
TypeScript SDK for the CIPHER trading engine REST API.
Installation
npm install cipher-ai
Quick Start
import { CipherClient } from 'cipher-ai';
const client = new CipherClient({
baseUrl: 'http://localhost:8000',
apiKey: 'cipher_sk_your_api_key'
});
const signal = await client.createSignal({
symbol: 'BTC',
model_version: 1
});
console.log(signal.signal);
console.log(signal.confidence);
API Reference
Constructor
const client = new CipherClient(options?: CipherClientOptions);
Options:
baseUrl (optional): API base URL. Default: http://localhost:8000
apiKey (optional): API key for authentication
Trading Endpoints
createSignal
Create a trading signal.
const signal = await client.createSignal({
symbol: 'BTC',
model_version: 1
});
getStatus
Get system status.
const status = await client.getStatus();
getPerformance
Get performance metrics.
const performance = await client.getPerformance();
getHistory
Get trade history.
const history = await client.getHistory(20);
getModels
Get model versions.
const models = await client.getModels();
getModelStatus
Get model status (no authentication required).
const modelStatus = await client.getModelStatus();
API Key Management
getKeyUsage
Get API key usage statistics.
const usage = await client.getKeyUsage(
'user@example.com',
'your_admin_secret',
30
);
Error Handling
All API methods throw a CipherError on non-2xx responses.
import { CipherClient, CipherError } from 'cipher-ai';
try {
const signal = await client.createSignal({
symbol: 'BTC',
model_version: 1
});
} catch (error) {
if (error instanceof CipherError) {
console.error('Status:', error.status);
console.error('Message:', error.message);
if (error.status === 401) {
console.error('Invalid API key');
} else if (error.status === 429) {
console.error('Rate limit exceeded');
}
}
}
Development
Setup
git clone https://github.com/getcipherAI/cipher-ai.git
cd cipher-ai
npm install
npm test
npm run build
Scripts
npm run build - Build the package (CJS + ESM)
npm test - Run tests in watch mode
npm run test:run - Run tests once
npm run typecheck - Type-check without emitting files
Requirements
- Node.js >= 18
- TypeScript 5.3+
License
MIT