A JS client for interacting with Zerion API
npm install defi-sdk
import { client } from "defi-sdk";
client.configure({ url: endpoint, apiToken: API_TOKEN });
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 */
}
});
namespace
: aNamespace
stringevent
: one ofreceived | changed | appended | removed
, see Zerion Docsbody
: aRequest
objectdata
: aResponse
object
Instead of calling client.subscribe
and passing type information manually, the SDK provides helpers for most of the existing request scopes
import { client } from "defi-sdk";
client.addressAssets({
payload: { asset_codes: ["eth"], currency: "usd" },
onData: data => {
/* handle data */
}
});
interface Request<T, ScopeName extends string> {
scope: ScopeName[];
payload: T;
}
interface Response<T> {
meta: any;
payload: T;
}
See Response
in Zerion Docs
MIT License, see the included LICENSE file.