npm package: @oko-agent/sdk
Description: TypeScript SDK for the OKO protocol API — market data, AI chat, wallet analysis, and trading
Latest version: 0.1.0

# @oko-agent/sdk

TypeScript SDK for the [OKO protocol](https://oko-agent.io) — market data, live tickers, AI chat, wallet analysis, and trading management.

## Installation

```bash
npm install @oko-agent/sdk
# or
yarn add @oko-agent/sdk
```

## Quick Start

```typescript
import { OkoClient } from '@oko-agent/sdk'

const client = new OkoClient({ baseUrl: 'https://api.oko-agent.io' })

// Live price stream
const { unsubscribe } = client.ticker.subscribe((update) => {
  console.log(update.symbol, update.price, update.changePercent)
})

// Market data
const coins = await client.market.getCoins()
console.log(coins[0].name, coins[0].price)

// AI chat
const res = await client.chat.send("What's the latest crypto news?")
console.log(res.message)

// Wallet analysis (streaming)
await client.wallet.analyze('0x123...', (chunk) => process.stdout.write(chunk))
```

## API Reference

### `new OkoClient(config)`

| Option | Type | Description |
|--------|------|-------------|
| `baseUrl` | `string` | OKO backend URL (required) |
| `apiKey` | `string` | JWT for authenticated endpoints (optional) |
| `timeout` | `number` | Request timeout in ms (default: 10000) |

### `client.ticker`

| Method | Description |
|--------|-------------|
| `subscribe(callback, options?)` | Subscribe to live price updates (SSE). Returns `{ unsubscribe }` |
| `stream()` | Async generator yielding `TickerUpdate` values |

### `client.market`

| Method | Returns | Description |
|--------|---------|-------------|
| `getGlobal()` | `GlobalMarketData` | Market cap, volume, Fear & Greed |
| `getCoins()` | `CoinRow[]` | Top 20 by market cap |
| `getTrending()` | `TrendingCoin[]` | Trending coins |
| `getGainers()` | `TopGainer[]` | Top 24h gainers |
| `getChart()` | `ChartDataPoint[]` | 7-day market cap + BTC price |

### `client.wallet`

| Method | Description |
|--------|-------------|
| `getBalances(address)` | Token balances for an EVM or Solana wallet |
| `analyze(address, onChunk, options?)` | Stream AI wallet analysis |
| `chat(address, payload)` | Follow-up chat in wallet analysis context |

### `client.chat`

| Method | Description |
|--------|-------------|
| `send(message, history?)` | General AI crypto chat |

### `client.auth` (requires account)

| Method | Description |
|--------|-------------|
| `register({ email, password })` | Create account, returns OTP setup details |
| `completeRegistration({ user_id, otp_code })` | Verify first OTP, returns JWT |
| `login({ email, password })` | Login, may require OTP |
| `verifyOTP({ user_id, otp_code })` | Verify OTP after login, returns JWT |
| `logout()` | Blacklist current JWT |

### `client.traders` (requires JWT)

| Method | Description |
|--------|-------------|
| `list()` | List all your traders |
| `create(payload)` | Create a new trader |
| `start(id)` / `stop(id)` | Start or stop a trader |
| `status(traderId)` | Live status + position |
| `statistics(traderId)` | Trading statistics |

### `client.strategies` (requires JWT)

| Method | Description |
|--------|-------------|
| `list()` | List strategies |
| `create(payload)` | Create strategy |
| `activate(id)` | Set as active strategy |
| `previewPrompt(config)` | Preview AI prompt for a config |

## Examples

```bash
# Stream live tickers
OKO_BASE_URL=https://api.oko-agent.io npx tsx examples/stream-tickers.ts

# Market overview
OKO_BASE_URL=https://api.oko-agent.io npx tsx examples/market-data.ts

# Analyze a wallet
OKO_BASE_URL=https://api.oko-agent.io WALLET=0x123... npx tsx examples/wallet-analyze.ts

# Interactive AI chat
OKO_BASE_URL=https://api.oko-agent.io npx tsx examples/chat.ts
```

## License

MIT