Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions core/docs/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

PMXT implements CCXT-style unified error handling across supported exchanges and venues. All errors follow a consistent structure with HTTP status codes, error codes, and retry semantics.

This guide describes the native TypeScript library (`npm install pmxt-core`). Its `BaseError`, `NotFound`, and `status` property belong to `pmxt-core`. The sidecar TypeScript SDK (`pmxtjs`) instead exports `PmxtError` and `NotFoundError`; see the [SDK error reference](../../docs/api-reference/errors.mdx) for that API.

## Table of Contents

- [Error Class Hierarchy](#error-class-hierarchy)
Expand All @@ -21,7 +23,7 @@ All PMXT errors extend from `BaseError`, which provides consistent properties ac
Generic bad request error. Base class for more specific validation errors.

```typescript
import { BadRequest } from 'pmxt';
import { BadRequest } from 'pmxt-core';

throw new BadRequest('Invalid parameter', 'Polymarket');
```
Expand All @@ -30,7 +32,7 @@ throw new BadRequest('Invalid parameter', 'Polymarket');
Authentication credentials are missing or invalid.

```typescript
import { AuthenticationError } from 'pmxt';
import { AuthenticationError } from 'pmxt-core';

throw new AuthenticationError('Invalid API key', 'Polymarket');
```
Expand All @@ -39,7 +41,7 @@ throw new AuthenticationError('Invalid API key', 'Polymarket');
The authenticated user doesn't have permission for this operation.

```typescript
import { PermissionDenied } from 'pmxt';
import { PermissionDenied } from 'pmxt-core';

throw new PermissionDenied('Insufficient permissions', 'Kalshi');
```
Expand All @@ -48,7 +50,7 @@ throw new PermissionDenied('Insufficient permissions', 'Kalshi');
The requested resource doesn't exist.

```typescript
import { NotFound, OrderNotFound, MarketNotFound } from 'pmxt';
import { NotFound, OrderNotFound, MarketNotFound } from 'pmxt-core';

// Generic not found
throw new NotFound('Resource not found', 'Limitless');
Expand All @@ -64,7 +66,7 @@ throw new MarketNotFound('market-456', 'Kalshi');
Rate limit exceeded. This error is retryable and may include `retryAfter` seconds.

```typescript
import { RateLimitExceeded } from 'pmxt';
import { RateLimitExceeded } from 'pmxt-core';

// With retry-after header
throw new RateLimitExceeded('Too many requests', 60, 'Polymarket');
Expand All @@ -77,7 +79,7 @@ throw new RateLimitExceeded('Rate limit exceeded', undefined, 'Kalshi');
Order parameters are invalid (price, size, tick size, etc.).

```typescript
import { InvalidOrder } from 'pmxt';
import { InvalidOrder } from 'pmxt-core';

throw new InvalidOrder('Invalid tick size: must be 0.01', 'Polymarket');
```
Expand All @@ -86,7 +88,7 @@ throw new InvalidOrder('Invalid tick size: must be 0.01', 'Polymarket');
Insufficient funds to complete the operation.

```typescript
import { InsufficientFunds } from 'pmxt';
import { InsufficientFunds } from 'pmxt-core';

throw new InsufficientFunds('Insufficient balance: need $100, have $50', 'Kalshi');
```
Expand All @@ -95,7 +97,7 @@ throw new InsufficientFunds('Insufficient balance: need $100, have $50', 'Kalshi
Input validation failed. Includes optional `field` property.

```typescript
import { ValidationError } from 'pmxt';
import { ValidationError } from 'pmxt-core';

throw new ValidationError('ID cannot be empty', 'id');
```
Expand All @@ -106,7 +108,7 @@ throw new ValidationError('ID cannot be empty', 'id');
Network connectivity issues. This error is retryable.

```typescript
import { NetworkError } from 'pmxt';
import { NetworkError } from 'pmxt-core';

throw new NetworkError('Connection timeout', 'Polymarket');
```
Expand All @@ -115,7 +117,7 @@ throw new NetworkError('Connection timeout', 'Polymarket');
Exchange is down or unreachable. This error is retryable.

```typescript
import { ExchangeNotAvailable } from 'pmxt';
import { ExchangeNotAvailable } from 'pmxt-core';

throw new ExchangeNotAvailable('Exchange is temporarily unavailable', 'Limitless');
```
Expand Down Expand Up @@ -163,7 +165,7 @@ Additional properties for specific errors:
### Basic Error Handling

```typescript
import { Polymarket, AuthenticationError, InsufficientFunds } from 'pmxt';
import { Polymarket, AuthenticationError, InsufficientFunds } from 'pmxt-core';

const exchange = new Polymarket({ privateKey: '0x...' });

Expand All @@ -190,9 +192,9 @@ try {
### Retry Logic for Retryable Errors

```typescript
import { Polymarket, BaseError, RateLimitExceeded } from 'pmxt';
import { Polymarket, BaseError, RateLimitExceeded } from 'pmxt-core';

async function fetchMarketsWithRetry(exchange: Polymarket, maxRetries = 3) {
async function fetchMarketsWithRetry(exchange: InstanceType<typeof Polymarket>, maxRetries = 3) {
let retries = 0;

while (retries < maxRetries) {
Expand Down Expand Up @@ -291,7 +293,7 @@ Uses CLOB client (similar to Polymarket):
### Before (v1.6.0 and earlier)

```typescript
import { Polymarket } from 'pmxt';
import { Polymarket } from 'pmxt-core';

const exchange = new Polymarket({ privateKey: '0x...' });

Expand All @@ -310,7 +312,7 @@ try {
### After (v1.7.0+)

```typescript
import { Polymarket, NetworkError, AuthenticationError, BaseError } from 'pmxt';
import { Polymarket, NetworkError, AuthenticationError, BaseError } from 'pmxt-core';

const exchange = new Polymarket({ privateKey: '0x...' });

Expand Down
26 changes: 12 additions & 14 deletions core/docs/SETUP_KALSHI.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,27 @@ balance = kalshi_demo.fetch_balance()

## 5. Initialization (TypeScript)

Install the TypeScript SDK with `npm install pmxtjs`. Its classes are `Kalshi` and `KalshiDemo`; `KalshiExchange` and `KalshiDemoExchange` are native `pmxt-core` exports.

```typescript
import { KalshiExchange } from 'pmxt';
import { Kalshi, KalshiDemo } from 'pmxtjs';

// ── Public data — no credentials needed ──────────────────────────────────────
const kalshi = new KalshiExchange();
const markets = await kalshi.fetchMarkets({ query: 'Fed rates' });
const publicKalshi = new Kalshi();
const markets = await publicKalshi.fetchMarkets({ query: 'Fed rates' });

// ── Production trading ────────────────────────────────────────────────────────
const kalshi = new KalshiExchange({
credentials: {
apiKey: process.env.KALSHI_API_KEY,
privateKey: process.env.KALSHI_PRIVATE_KEY,
},
const kalshi = new Kalshi({
apiKey: process.env.KALSHI_API_KEY,
privateKey: process.env.KALSHI_PRIVATE_KEY,
});

const balance = await kalshi.fetchBalance();
console.log(`Available: ${balance[0].available}`);

const order = await kalshi.createOrder({
marketId: 'FED-25JAN29-B4.75',
outcomeId: 'outcome-id-from-fetchMarkets', // Choose the desired market outcome
side: 'buy',
type: 'limit',
price: 0.55,
Expand All @@ -118,13 +119,10 @@ const order = await kalshi.createOrder({

// ── Demo / paper-trading environment ─────────────────────────────────────────
// Use demo credentials generated on demo.kalshi.com
import { KalshiDemoExchange } from 'pmxt';

const kalshiDemo = new KalshiDemoExchange({
credentials: {
apiKey: process.env.KALSHI_API_KEY, // demo API key
privateKey: process.env.KALSHI_PRIVATE_KEY,
},
const kalshiDemo = new KalshiDemo({
apiKey: process.env.KALSHI_API_KEY, // demo API key
privateKey: process.env.KALSHI_PRIVATE_KEY,
});

const demoBalance = await kalshiDemo.fetchBalance();
Expand Down