Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@deriv-com/api-client

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deriv-com/api-client

A lightweight wrapper around Deriv's WebSocket API

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Deriv API Client

A lightweight, zero dependency wrapper around the WebSockets Web API and the native Node WebSocket (Node V22 and above) that is fully typed to Deriv's Backend WebSocket (Deriv WS API Explorer).

Requirements

  • Node version 22 and above (With native WebSocket API): for running it on the Backend or a Node runner
  • For browser - generally all is supported

Getting Started

Using the Library

You can start by installing the library via the following commands:

npm

npm i @deriv-com/api-client

pnpm

pnpm install @deriv-com/api-client

yarn

yarn add @deriv-com/api-client

To use it in your codebase, simply initialise the `DerivAPICLient` class and invoke the methods available. Most of the things you need (Deriv WS endpoints, handler, etc) are all included and internalised within the library itself.
const derivAPI = new DerivAPIClient();
const response = await derivAPI.send({ name: 'get_account_status' });
console.log(response);

Contributing to the Library

Starting the Development Server

This project comes with a sandbox served with HMR. In it you have a sample code which you can test your changes. To run the sandbox run:

npm run dev

Functionalities

  • Conversion of Request/Response Deriv WS Calls to JavaScript Promises
  • Deduping Subscriptions via Internal Subscription Tracking
  • Separating data handlers (onData) with WebSocket message streams - there will always be only one subscription per payload to Deriv WS BE
  • Asynchronous queuing calls when WebSocket calls are connecting, disconnect or reconnecting
  • Connection keep alive mechanism
  • Allow error handling via callbacks by forwarding the generic Deriv WS response.error property
  • Fully typed safe endpoints - Typed payload based on endpoint names

Core Functions

Send

async send({ name, payload })

The send method is for request/response Deriv WS call that do not have subscriptions. These types of call will only return one response for every call you make.

  • name - typesafe to all deriv WS request/response endpoint names (TSocketEndpointNames).
  • payload - typesafe to the expected payload (mapped to the name). Default payload will always be set to { [name]: 1 }. For example for the get_account_status call, if no payload is passed will result in the following payload sent to the BE
{
    "get_account_status": 1
}

Subscribe

Unsubscribe

Keywords

FAQs

Package last updated on 13 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc