Skip to content

zeriontech/defi-sdk-js

Repository files navigation

defi-sdk

A JS client for interacting with Zerion API

Install

npm install defi-sdk

Getting Started

import { client } from "defi-sdk";

client.configure({ url: endpoint, apiToken: API_TOKEN });

API

General usage

client.subscribe(options)

import { client } from "defi-sdk";

client.subscribe({
  namespace: "assets",
  body: {
    scope: ["prices"],
    payload: { asset_codes: ["eth"], currency: "usd" }
  },
  onMessage: (event: Event, data: Response) => {
    /* handle data */
  }
});

Domain Helpers

Instead of calling client.subscribe and passing type information manually, the SDK provides helpers for most of the existing request scopes

addressAssets

import { client } from "defi-sdk";

client.addressAssets({
  payload: { asset_codes: ["eth"], currency: "usd" },
  onData: data => {
    /* handle data */
  }
});

Types

Request

interface Request<T, ScopeName extends string> {
  scope: ScopeName[];
  payload: T;
}

Response

interface Response<T> {
  meta: any;
  payload: T;
}

See Response in Zerion Docs

License

MIT License, see the included LICENSE file.