diff --git a/.github/workflows/publish-sdk.yml b/.github/workflows/publish-sdk.yml new file mode 100644 index 0000000..497c19a --- /dev/null +++ b/.github/workflows/publish-sdk.yml @@ -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 diff --git a/sdk/typescript/README.md b/sdk/typescript/README.md new file mode 100644 index 0000000..d0a4c62 --- /dev/null +++ b/sdk/typescript/README.md @@ -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. diff --git a/sdk/typescript/package-lock.json b/sdk/typescript/package-lock.json index 679c37d..dcf2e69 100644 --- a/sdk/typescript/package-lock.json +++ b/sdk/typescript/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@perplex/sdk", + "name": "@ozpool/perplex-sdk", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@perplex/sdk", + "name": "@ozpool/perplex-sdk", "version": "0.1.0", "license": "BUSL-1.1", "devDependencies": { diff --git a/sdk/typescript/package.json b/sdk/typescript/package.json index 34e0bbb..7a2db21 100644 --- a/sdk/typescript/package.json +++ b/sdk/typescript/package.json @@ -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", @@ -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",