v1.0.0

Pinbar AI SDK

Integrate trading data in under 5 minutes. Push trades, fetch analytics, and manage evaluations from any JavaScript environment.

Installation

bash
npm install @pinbar/sdk

NPM package publishing coming soon. Use the CDN or copy the SDK source directly.

Quick Start

typescript
import { PinbarSDK } from '@pinbar/sdk';

const sdk = new PinbarSDK({
  apiKey: 'pnbr_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
});

// Push a trade
const result = await sdk.pushTrades([{
  external_id: 'trade-001',
  account_id: 'trader-123',
  symbol: 'EURUSD',
  side: 'buy',
  entry_price: 1.0850,
  exit_price: 1.0875,
  quantity: 1.0,
  entry_time: '2026-04-11T09:30:00Z',
  exit_time: '2026-04-11T14:15:00Z',
  profit_loss: 250.00,
  commission: -7.00,
  metadata: { asset_class: 'forex', platform: 'MetaTrader 5' }
}]);

console.log(`Inserted: ${result.inserted}, Updated: ${result.updated}`);

Fetch Analytics

typescript
// Fetch analytics
const analytics = await sdk.getAnalytics({
  period: 'daily',
  from: '2026-04-01',
  to: '2026-04-11',
  metrics: ['pnl', 'win_rate', 'sharpe_ratio'],
});

console.log(analytics.data);
// [{ date: '2026-04-01', pnl: 340, win_rate: 0.65, ... }, ...]

Check Evaluations

typescript
// Check evaluation status
const status = await sdk.getEvaluationStatus('trader_123');

if (status.status === 'breached') {
  console.log(`Breach reason: ${status.breach_reason}`);
}

Sandbox Mode

Use pnbr_test_ keys to safely build and test your integration. Sandbox traffic is isolated from live analytics, billing, and webhooks marked as live.

typescript
// Sandbox / test mode — uses pnbr_test_ keys.
// Test keys only deliver to webhooks marked as "test" environment
// and never affect live analytics or billing.
const sdk = new PinbarSDK({
  apiKey: 'pnbr_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  sandbox: true, // optional — auto-detected from key prefix
});

// All calls now route through the sandbox environment
await sdk.pushTrades([{ /* ... */ }]);

Verify Webhook Signatures

Every outbound webhook is signed with HMAC-SHA256 using your webhook secret and sent in the X-Pinbar-Signature header. Use the SDK helper to verify deliveries in constant time.

typescript
import { verifyWebhookSignature } from '@pinbar/sdk';

// Express / Node.js example
app.post('/webhooks/pinbar', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.header('X-Pinbar-Signature'); // "sha256=<hex>"
  const secret    = process.env.PINBAR_WEBHOOK_SECRET!;

  const ok = verifyWebhookSignature(req.body, signature, secret);
  if (!ok) return res.status(401).send('Invalid signature');

  const event = JSON.parse(req.body.toString());
  switch (event.type) {
    case 'trade.ingested':         /* ... */ break;
    case 'risk.alert.triggered':   /* ... */ break;
  }
  res.status(200).send('ok');
});

Always verify on the raw request body — re-serialized JSON will not match the signature.

API Reference

Configuration

OptionTypeRequiredDefaultDescription
apiKeystring
Required
Your enterprise API key
baseUrlstringNo"https://api.pinbar.ai"API base URL
timeoutnumberNo30000Request timeout in ms
retriesnumberNo3Max retry attempts
onErrorfunctionNoundefinedGlobal error callback

Error Handling

typescript
import { PinbarSDK, PinbarError, ErrorCodes } from '@pinbar/sdk';

const sdk = new PinbarSDK({
  apiKey: 'pnbr_live_...',
  retries: 3,
  timeout: 15000,
  onError: (err) => console.error(`[${err.code}] ${err.message}`),
});

try {
  await sdk.pushTrades(trades);
} catch (err) {
  if (err instanceof PinbarError) {
    switch (err.code) {
      case ErrorCodes.RATE_LIMITED:
        console.log('Slow down — retry after backoff');
        break;
      case ErrorCodes.UNAUTHORIZED:
        console.log('Check your API key');
        break;
      case ErrorCodes.INVALID_INPUT:
        console.log('Fix your request:', err.message);
        break;
    }
  }
}

Error Codes

CodeHTTPDescriptionRetries
RATE_LIMITED429Too many requests. SDK auto-retries with backoff.
Auto
UNAUTHORIZED401Invalid or revoked API key.No
INVALID_INPUT400Malformed request body or params.No
NETWORK_ERRORDNS/connection failure.
Auto
TIMEOUT408Request exceeded timeout.
Auto
SERVER_ERROR500Transient server issue.
Auto

Ready to integrate?

Get your API key and start pushing trades in minutes.