npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bayse-markets-sdk

v0.1.1

Published

TypeScript SDK for the Bayse Markets prediction market API

Readme

Bayse-Markets SDK

npm version License: MIT

A TypeScript SDK for the Bayse Markets prediction market API. Bayse is Nigeria's premier prediction market platform where users can trade on real-world events and outcomes.

Features

  • Full TypeScript Support - Complete type definitions for all API responses
  • Prediction Markets - Access events, markets, and trading data
  • Portfolio Management - Track positions, balances, and trading history
  • Real-time Streaming - WebSocket connections for live market data -Secure Authentication - API key-based authentication with proper error handling
  • Comprehensive Testing - Smoke tests and integration tests included

Installation

npm install bayse-markets-sdk

Quick Start

1. Get Your API Keys

  1. Sign up for a Bayse account at bayse.markets
  2. Generate API keys from your account settings
  3. Store them securely (never commit to version control)

2. Initialize the Client

import BayseClient from 'bayse-markets-sdk';

const bayse = new BayseClient({
  publicKey: process.env.BAYSE_PUBLIC_KEY!,
  secretKey: process.env.BAYSE_SECRET_KEY!,
});

3. Fetch Open Events

// Get all open prediction markets
const result = await bayse.events.getAll({
  status: 'open',
  size: 10,
});

console.log(`Found ${result.events.length} open events`);

// Example output:
// Found 5 open events

4. Get Market Details

// Get details for a specific event
const event = await bayse.events.getById('event-id-here');

console.log(`${event.title}`);
// Show YES/NO prices for the first market
if (event.markets.length > 0) {
  const market = event.markets[0];
  console.log(`YES: ${market.outcome1Price} | NO: ${market.outcome2Price}`);
}

5. Real-time Market Data

// Connect to real-time market updates
const stream = bayse.stream.markets();

stream.on('data', (data) => {
  console.log('Market update:', data);
});

stream.on('error', (error) => {
  console.error('Stream error:', error);
});

// Connect to a specific market
await stream.connect('market-id-here');

API Reference

Events

// List open events
const { events, pagination } = await bayse.events.getAll({
  status: 'open',
  category: 'sports',
  size: 20,
})

// Get single event
const event = await bayse.events.getById('evt_123')

// Get by slug
const event = await bayse.events.getBySlug('super-eagles-afcon-2026')

// Price history
const history = await bayse.events.getPriceHistory('evt_123')

Markets

// Get ticker
const ticker = await bayse.markets.getTicker('mkt_123')

// Get order book
const books = await bayse.markets.getOrderBook(['outcome_id_1', 'outcome_id_2'])

// Get recent trades
const trades = await bayse.markets.getTrades({ marketId: 'mkt_123' })

// Get quote before trading
const quote = await bayse.markets.getQuote('evt_123', 'mkt_123', {
  side: 'BUY',
  outcome: 'YES',
  amount: 100,
  currency: 'NGN',
})
// quote.expectedShares, quote.total, quote.fee

Orders

// Place an order
const order = await bayse.orders.place('evt_123', 'mkt_123', {
  side: 'BUY',
  outcome: 'YES',
  amount: 100,
  currency: 'NGN',
})

// AMM markets fill instantly
console.log(order.ammOrder?.id)

// Cancel an order (CLOB only)
await bayse.orders.cancel('ord_123')

// View your orders
const { data, pagination } = await bayse.orders.getAll({ status: 'open' })

Portfolio & Wallet

// Your open positions
const positions = await bayse.portfolio.getPositions()

// Your trade history
const { data } = await bayse.portfolio.getActivities({ page: 1, size: 20 })

// Your wallet balances
const { assets } = await bayse.wallet.getAssets()
assets.forEach(a => console.log(`${a.symbol}: ${a.availableBalance}`))

WebSockets — Real-time Data

// Market prices and activity
const feed = bayse.stream.markets()
await feed.connect()

feed.subscribePrices('evt_123', (data) => {
  console.log('Price update:', data)
})

feed.subscribeActivity('evt_123', (data) => {
  console.log('Trade:', data)
})

feed.subscribeOrderbook(['mkt_123'], 'NGN', (data) => {
  console.log('Orderbook:', data)
})

// Handle server-side errors
feed.onError = (message) => {
  console.error('Stream error:', message)
}

// Disconnect when done
feed.disconnect()
// Live asset prices — crypto and FX
const prices = bayse.stream.realtime()
await prices.connect()

// USD/NGN live rate
prices.subscribeAssetPrices(['USDNGN'], (data) => {
  console.log('USD/NGN:', data)
})

// Available: BTCUSDT, ETHUSDT, SOLUSDT, XAUUSD, EURUSD, GBPUSD, USDNGN

Streaming

Markets Stream

const stream = bayse.stream.markets();
await stream.connect(marketId);

Real-time Stream

const stream = bayse.stream.realtime();
await stream.connect();

Configuration

interface BayseConfig {
  publicKey: string;        // Required: Your public API key
  secretKey: string;        // Required: Your secret API key
  baseUrl?: string;         // Optional: Defaults to https://relay.bayse.markets
}

Error Handling

The SDK throws typed errors for different scenarios:

import {
  BayseApiError,
  BayseAuthError,
  BayseRateLimitError,
  BayseNotFoundError
} from 'bayse-markets-sdk';

try {
  const result = await bayse.events.getAll();
} catch (error) {
  if (error instanceof BayseAuthError) {
    console.log('Authentication failed');
  } else if (error instanceof BayseRateLimitError) {
    console.log('Rate limit exceeded, retry later');
  } else if (error instanceof BayseNotFoundError) {
    console.log('Resource not found');
  } else {
    console.log('API error:', error.message);
  }
}

Testing

Smoke Test

Run the included smoke test to verify your setup:

# Set your API keys in .env first
echo "BAYSE_PUBLIC_KEY=your_public_key_here" > .env
echo "BAYSE_SECRET_KEY=your_secret_key_here" >> .env

# Run the smoke test
npm test

Integration Tests

# Run integration tests
npx ts-node tests/integration.ts

WebSocket Tests

# Test WebSocket connections
npx ts-node tests/websocket.ts

Development

Building

npm run build

Development Mode

npm run dev

Project Structure

src/
├── index.ts          # Main entry point
├── client.ts         # HTTP client
├── auth.ts           # Authentication utilities
├── utils.ts          # Helper functions
├── types/            # TypeScript definitions
├── modules/          # API modules
│   ├── events.ts
│   ├── markets.ts
│   ├── orders.ts
│   ├── portfolio.ts
│   ├── wallet.ts
│   └── system.ts
└── websocket/        # WebSocket streaming
    ├── markets.ts
    └── realtime.ts

Contributing

This is a community SDK built during the Bayse Public API Beta. Issues and PRs welcome.

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Make your changes and add tests
  4. Run tests: npm test
  5. Commit your changes: git commit -am 'Add my feature'
  6. Push to the branch: git push origin feature/my-feature
  7. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support


Built by @Mudigram · Not officially affiliated with Bayse Markets