Skip to content
Merged
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
54 changes: 54 additions & 0 deletions .github/workflows/publish-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Publish SDK

# Publishes @ozpool/perplex-sdk to GitHub Packages when a `sdk-v*` tag is
# pushed (e.g. `git tag sdk-v0.1.0 && git push origin sdk-v0.1.0`) or via
# manual dispatch. Builds + tests the SDK first; never publishes a tag
# whose build is red.

on:
push:
tags:
- "sdk-v*"
workflow_dispatch:
inputs:
dry_run:
description: "Skip the final `npm publish` step"
type: boolean
default: false

jobs:
publish:
name: Build, test, publish
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
defaults:
run:
working-directory: sdk/typescript
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://npm.pkg.github.com"
scope: "@ozpool"

- name: Install
run: npm ci

- name: Typecheck
run: npm run typecheck

- name: Build
run: npm run build

- name: Test
run: npm test

- name: Publish to GitHub Packages
if: ${{ github.event_name == 'push' || inputs.dry_run != true }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm publish
66 changes: 66 additions & 0 deletions sdk/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# @ozpool/perplex-sdk

Typed REST + WebSocket client for the [Perplex](https://github.com/ozpool/Perplex) perpetuals exchange.

## Install

The SDK is published to **GitHub Packages** under the `@ozpool` scope. Configure npm to route `@ozpool/*` to GitHub Packages — your project's `.npmrc`:

```ini
@ozpool:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
```

`GITHUB_TOKEN` needs the `read:packages` scope. Then:

```bash
npm install @ozpool/perplex-sdk
```

## Usage

```ts
import { PerplexClient } from "@ozpool/perplex-sdk";

const client = new PerplexClient({
baseUrl: "https://edge.perplex.exchange",
// bearer is optional — only required for /v1/orders, /v1/positions, etc.
bearer: process.env.PERPLEX_JWT,
});

const markets = await client.markets();
console.log(markets);
```

WebSocket:

```ts
import { PerplexWs } from "@ozpool/perplex-sdk";

const ws = new PerplexWs({
url: "wss://edge.perplex.exchange/ws",
token: process.env.PERPLEX_JWT,
});

ws.on((msg) => {
if (msg.type === "oracle") console.log(msg.priceX18);
});

ws.subscribe("oracle.btc-usd");
ws.connect();
```

## Channels

| Channel | Auth | Payload |
|---|---|---|
| `orderbook.{marketId}` | public | snapshot + deltas |
| `trades.{marketId}` | public | public fills |
| `oracle.{marketId}` | public | live Pyth Hermes ticks (~500ms) |
| `funding.{marketId}` | public | funding rate + next-settlement boundary |
| `user.fills` | bearer | private fills |
| `user.positions` | bearer | private position diffs |

## License

BUSL-1.1 — see the main repo for terms.
4 changes: 2 additions & 2 deletions sdk/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions sdk/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"name": "@perplex/sdk",
"name": "@ozpool/perplex-sdk",
"version": "0.1.0",
"description": "Typed REST + WebSocket client for the Perplex perpetuals exchange.",
"license": "BUSL-1.1",
"repository": "https://github.com/ozpool/Perplex",
"repository": {
"type": "git",
"url": "https://github.com/ozpool/Perplex.git",
"directory": "sdk/typescript"
},
"homepage": "https://github.com/ozpool/Perplex#readme",
"bugs": "https://github.com/ozpool/Perplex/issues",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
Expand All @@ -16,8 +22,13 @@
},
"files": [
"dist",
"src"
"src",
"README.md"
],
"publishConfig": {
"registry": "https://npm.pkg.github.com",
"access": "public"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json --noEmit",
Expand Down
Loading