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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@claasahl/spotware-adapter

v3.2.0

Published

Protocol Buffers and Data Models for Spotware Open API 2.0

Downloads

92

Readme

@claasahl/spotware-adapter

NPM - version NPM - downloads

ALPHA VERSION

Use this package's SpotwareClientSocket to communicate with Spotware Open API servers in NodeJS environments. It comes with TypeScript support for all Spotware ProtoBuffer meesages, it sticks to recommended heartbeat-intervals and recommended rate limits (see here).

Example: Client

Want to exchange messages with a Spotware Open API server? This is for you:

import tls from "tls";
import {
  SpotwareClientSocket,
  ProtoOAPayloadType,
  FACTORY,
} from "@claasahl/spotware-adapter";

const host = "demo.ctraderapi.com";
const port = 5035;

const socket = tls.connect(port, host);
socket.once("secureConnect", () => {
  console.log(`requesting version number from ${host}:${port}`);
  s.write(FACTORY.PROTO_OA_VERSION_REQ());
});

const s = new SpotwareClientSocket(socket);
s.on("data", (message) => {
  switch (message.payloadType) {
    case ProtoOAPayloadType.PROTO_OA_VERSION_RES:
      console.log(`got response from ${host}:${port}`);
      console.log(`server version: ${message.payload.version}`);
      s.end();
      break;
    // ...
  }
});

Or take this RunKit for a spin: https://runkit.com/claasahl/spotware-example-client

Example: Server

Want to test your client without sending messages over the wire? Take a peek at this:

import { Server } from "net";
import {
  SpotwareSocket,
  ProtoOAPayloadType,
  FACTORY,
} from "@claasahl/spotware-adapter";

const port = 5035;

const server = new Server((socket) => {
  const address = socket.address();
  const source = typeof address === "string" ? address : address.address;
  console.log(`${source} connected`);

  const s = new SpotwareSocket(socket);
  s.on("error", (err) => console.log(source, err));
  s.on("data", (message) => {
    const { clientMsgId } = message;
    switch (message.payloadType) {
      case ProtoOAPayloadType.PROTO_OA_VERSION_REQ:
        s.write(FACTORY.PROTO_OA_VERSION_RES({ version: "00" }, clientMsgId));
        break;
      // ...
    }
  });
});
server.listen(port, () => console.log(`listening on port ${port}`));

Getting Started

For a meaningful interaction with a Spotware Open API server, such as live.ctraderapi.com:5035 or demo.ctraderapi.com:5035, you will need:

  1. an account at Spotware 🥁
  2. a set of OAUTH credentials (i.e. clientId and clientSecret)
    • navigate to applications
    • view credentials for one of your applications (or create a new application)
  3. a set of OAUTH tokens (i.e. accessToken and refreshToken)
    • navigate to applications
    • open playground for one of your applications
    • fetch tokens for one or more of your accounts

Debugging

This package uses debug for logging. These namespaces are supported:

  • spotware.input incoming message from server
  • spotware.input.human incoming message from server with humanreadable payloadType
  • spotware.output outgoing message to server
  • spotware.output.human outgoing message to server with humanreadable payloadType
  • spotware.${payloadType} any proto message (i.e. incoming or outgoing)
  • spotware.${payloadTypeText} any proto message (i.e. incoming or outgoing)

Further Reading