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 🙏

© 2024 – Pkg Stats / Ryan Hefner

serum-machine

v0.1.3

Published

Real-time market data API server for Serum DEX

Downloads

11

Readme

Serum Machine

Version

Real-time market data API server for Serum DEX

Architecture

architecture diagram

  • server runs with multiple Minions worker threads* and single Serum Producer that runs in the main thread
  • Minions are responsible for WebSockets subscriptions management that includes handling subscriptions requests and sending data to all connected clients
  • Serum Producer is responsible for connecting to Serum Node RPC WS API and subscribing all relevant accounts changes (event & request queue, bids & asks) for all supported markets as well as producing market data messages that are then passed to minions and published as WebSocket messages to all subscribed clients

* multi core support via worker_threads is linux only feature which allows multiple threads to bind to the same port, see https://github.com/uNetworking/uWebSockets.js/issues/304 and https://lwn.net/Articles/542629/ - for other OSes there's only one worker thread running

Installation options

  • npx (requires Node.js >= 12 installed on host machine)

    That will start Serum Machine server running on port 8000

    npx serum-machine

    If you'd like to switch to different Serum Node endpoint, change port or run with debug logs enabled, just add one of the available CLI options:

    npx serum-machine --endpoint https://solana-api.projectserum.com --debug --port 8080

    Run npx serum-machine --help to see all available startup options (node endpoint url, port etc.)

  • npm (requires Node.js >= 12 installed on host machine)

    Installs serum-machine globally and runs it on port 8000.

    npm install -g serum-machine
    serum-machine

    If you'd like to switch to different Serum Node endpoint, change port or run with debug logs enabled, just add one of the available CLI options:

    serum-machine --endpoint https://solana-api.projectserum.com --debug --port 8080

    Run serum-machine --help to see all available startup options (node endpoint url, port etc.)

  • Docker

    Pulls and runs latest version of tardisdev/serum-machine image. Serum Matchine server will available on host via 8000 port (for example http://localhost:8000/v1/markets) with debug logs enabled (TM_DEBUG env var).

    docker run -p 8000:8000 -e "SM_ENDPOINT=https://solana-api.projectserum.com" -e "SM_DEBUG=true" -d tardisdev/serum-machine:latest

WebSocket /streams endpoint

Allows subscribing to Serum DEX real-market data streams.

const ws = new WebSocket('ws://localhost:8000/v1/streams')

ws.onmessage = (message) => {
  console.log(message)
}

ws.onopen = () => {
  const subscribePayload = {
    op: 'subscribe',
    channel: 'trades',
    markets: ['BTC/USDT', 'SRM/USDT']
  }

  ws.send(JSON.stringify(subscribePayload))
}

HTTP endpoints

/markets

Accepts no params and returns supported Serum markets.

Sample request & response

http://localhost:8000/v1/markets

[
  {
    "name": "ALEPH/USDT",
    "address": "EmCzMQfXMgNHcnRoFwAdPe1i2SuiSzMj1mx6wu3KN2uA",
    "programId": "4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn",
    "deprecated": false
  },
  {
    "name": "ALEPH/USDC",
    "address": "B37pZmwrwXHjpgvd9hHDAx1yeDsNevTnbbrN9W12BoGK",
    "programId": "4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn",
    "deprecated": false
  },
  {
    "name": "BTC/USDT",
    "address": "8AcVjMG2LTbpkjNoyq8RwysokqZunkjy3d5JDzxC6BJa",
    "programId": "4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn",
    "deprecated": false
  }
]