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

okx-api-node-client

v1.0.5

Published

Node.js connector for OKX market REST APIs and WebSockets

Downloads

270

Readme

Node.js & Typescript OKX API client

connector logo

Node.js connector for the OKX APIs and WebSockets:

  • Complete integration with all OKX APIs.
  • TypeScript support (with type declarations for most API requests & responses).
  • Robust WebSocket integration
    • Configurable connection heartbeats (automatically detect failing connections).
    • Automatic reconnect then resubscribe workflows.
    • Automatic authentication and heartbeat handling.
  • Browser support (via webpack bundle - see "Browser Usage" below).

Installation

npm install okx-api-node-client

Documentation

Most methods accept JS objects. These can be populated using parameters specified by okx's API documentation, or check the type definition in the rest-client class methods.


Usage

Create API credentials at okx

REST Client

Requests & Responses

  • If your IDE doesn't have IntelliSense, check the rest-client.ts for a list of methods, params & return types.
  • Requests follow the same ordering and format as the categories in the API docs.
  • Responses are parsed automatically for less nesting. Error responses are thrown in full:
    • If the response looks successful (HTTP 200 and "code" in the response body === "0"), only the data property is directly (without the code, data & msg properties).
    • If the response looks like an error (HTTP error OR the "code" property in the response does not equal "0"), the full response is thrown (including code and msg properties). See the interface for APIResponse.

Websocket Client

This connector includes a high-performance node.js & typescript websocket client for the OKX public & private websockets.

  • If your IDE doesn't have IntelliSense, check the websocket-client.ts for a list of methods, params & return types.
  • When subscribing to channels, only the "args" should be passed as an object or array when calling the websocket client subcribe() function: API docs.
  • TypeScript recommended (but it is not required) for a richer experience: typescript-subscribe
  • The ws client will automatically open connections as needed when subscribing to a channel.
  • If the connection is lost for any reason, the ws client will detect this (via the connection heartbeats). It will then:
    • Automatically teardown the dead connection.
    • Automatically respawn a fresh connection.
    • Automatically reauthenticate, if using private channels.
    • Automatically resubscribe to previously subscribed topics.
    • Resume producing events as before, without extra handling needed in your logic.
  • The ws client will automatically authenticate if accounts are provided and a private channel is subscribed to.
  • Up to 100 accounts are supported on the private connection, as per the API docs. Authentication is automatic if accounts are provided.
  • For examples in using the websocket client, check the examples in the repo:
    • Private channels (account data): examples/ws-private.ts
    • Public chanels (market data): examples/ws-public.ts
    • These examples are written in TypeScript, so can be executed with ts-node for easy testing: ts-node examples/ws-private.ts
    • Or convert them to javascript:
      • Change the import { ... } from 'okx-api-node-client' to const { ... } = require('okx-api-node-client');
      • Rename the file to ws-private.js
      • And execute with node: node examples/ws-private.js

Browser Usage

Build a bundle using webpack:

  • npm install
  • npm build
  • npm pack

The bundle can be found in dist/. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.