stake-trading
v0.1.0
Published
An unofficial TypeScript SDK for Stake trading platform
Maintainers
Readme
stake-trading
Unofficial TypeScript SDK for the Stake trading APIs (US / NYSE-style routes and ASX). This project is not affiliated with or endorsed by Stake. Stake may change their APIs at any time; use this library at your own risk and review Stake’s terms of use.
Features
- Typed requests and responses (Zod schemas + TypeScript types)
- Promise-based
StakeClientwith sub-clients (orders,watchlist,equities, …) - NYSE (US) and ASX exchange configurations with shared patterns where possible
- Structured logging via Winston (
LOG_LEVELenv var)
Requirements
- Node.js 20+
Installation
yarn add stake-tradingor
npm install stake-tradingQuick start
Session token
import StakeClient, { SessionTokenLoginRequestSchema } from 'stake-trading';
import { NYSE } from 'stake-trading';
const loginRequest = SessionTokenLoginRequestSchema.parse({
token: process.env.STAKE_TOKEN!,
});
const client = new StakeClient(loginRequest, NYSE);
await client.login(loginRequest);
const orders = await client.orders.list();Credentials (creates a session via Stake’s login API)
Environment variables STAKE_USER, STAKE_PASS, and optionally STAKE_PLATFORM_TYPE / STAKE_TOKEN are read by the Zod schemas when fields are omitted.
import StakeClient, { CredentialsLoginRequestSchema } from 'stake-trading';
import { NYSE } from 'stake-trading';
const loginRequest = CredentialsLoginRequestSchema.parse({});
const client = new StakeClient(loginRequest, NYSE);
await client.login(loginRequest);ASX
import StakeClient, { SessionTokenLoginRequestSchema } from 'stake-trading';
import { ASX } from 'stake-trading';
const loginRequest = SessionTokenLoginRequestSchema.parse({ token: '...' });
const client = new StakeClient(loginRequest, ASX);
await client.login(loginRequest);NYSE-only clients (e.g. fx, ratings, statements) are omitted when using ASX.
API shape
The client is organized by domain, not by a single flat placeOrder / getAccount surface:
| Area | Client accessor | Examples |
| ---------- | ------------------ | ------------------------------------------ |
| Orders | client.orders | list(), cancel(...), brokerage(...) |
| Watchlists | client.watchlist | listWatchlists(), watchlist({ id }), … |
| Products | client.products | get(...), search({ keyword }) |
| Equities | client.equities | list() |
| Trades | client.trades | (see src/trade.ts) |
| … | … | Explore src/*.ts and src/asx/ |
Base URLs and paths live in constant.ts (NYSE, ASX).
Error handling
InvalidLoginException— failed credential login or invalid session when loading the user profile (extendsAuthenticationError).StakeHttpError— non-2xx HTTP response (statusCode,statusText, optionalresponseBody).StakeError— base class; alsoValidationError,RateLimitError,OrderError,NetworkError, etc. for app-level use.
import {
StakeClient,
InvalidLoginException,
StakeHttpError,
} from 'stake-trading';
try {
await client.login(request);
} catch (e) {
if (e instanceof InvalidLoginException) {
// bad credentials or session
} else if (e instanceof StakeHttpError) {
console.error(e.statusCode, e.responseBody);
}
}Zod may throw ZodError if API responses no longer match the packaged schemas.
Logging
The SDK uses a shared Winston logger (see src/logging.ts). Set LOG_LEVEL to debug, info, etc. POST bodies are never logged, so passwords and tokens are not written by the debug logger.
import { logger } from 'stake-trading';
logger.info('Application message');Manual smoke test (maintainers)
With STAKE_TOKEN set and network access:
yarn example:sessionDevelopment
yarn install
yarn build
yarn test
yarn run check # lint + format check + testsSee TESTING.md and PUBLISHING.md for more detail.
Contributing
- Fork the repository
- Create a feature branch
- Run
yarn run checkbefore opening a PR
License
MIT — see LICENSE.
Issues
Report problems on GitHub Issues.
