Skip to content
JS/TS client library for interacting with Suredbits APIs
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

npm version Build Status

JS/TS client library for Suredbits APIs

This is a client library for interacting with the Suredbits APIs for NFL, NBA and cryptocurrency market data. See our API docs for more information.

You're also welcome to join our Slack, if you have any questions about our APIs, our open source Bitcoin library Bitcoin-S or just want to discuss Bitcoin, Lightning, NBA & NFL or anything else.

Add it to your project:


$ yarn add sb-api


$ npm install --save sb-api


Setting up the connection

Our APIs are paid for by using the Bitcoin Lightning Network. We suport the major Lightning implementations: lnd, c-lightning and Eclair.

We assume you have a running Lightning client. Behind the scenes it does two things with the provided client:

  1. Pay invoices. We pay for access to the Suredbits` APIs by paying Lightning invoices.
  2. Generate invoices without an amount specified. When setting up a subscription we provide a refund invoice where money can be refunded to us if we abort or subscription before it's up or something causes the server to abort the subscription.

You should not keep large amounts of money on the node you're using with this library.


import { Eclair, Sockets } from 'sb-api'

const eclair = await Eclair({ rpcPass: 'super_secret' })
const futuresSocket = await Sockets.exchangeSpot(eclair)


import { Lnd, Sockets } from 'sb-api'

const lnd = await Lnd()
// You then pass lnd into the appropriate socket you're interested in.


import { CLightning } from 'sb-api'

const client = await CLightning()

// You then pass client into the appropriate socket you're interested in.

See doc/ for more information on how to use your favorite LN implementation, and what the available options are.

Request data

import { Lnd, Sockets } from 'sb-api'

const ln = await Lnd()
const spot = await Sockets.exchangeSpot(ln)
  duration: 10000,
  exchange: 'binance',
  // data has types! data.bidSize works, data.wrongField gives an error
  onData: data => console.log('received some data:', data),
  // snap has types! => handleS(s)) works, snap.wrongField gives an error
  onSnapshot: snap => console.log('received a snapshot:', snap),
  // this callback is called at the end of your subscription, and provides
  // you with a list of all the elements you've received
  onSubscriptionEnded: datapoints => datapoints[0],

// the comments above on the callbacks used for the spot socket
// also apply for the futures socket

const futures = await Sockets.exchangeFutures(ln)
  exchange: 'bitmex',
  symbol: 'BTCUSD',
  interval: 'biquarterly',
  onData: data => data,
  onSnapshot: snap => snap[0],
  onSubscriptionEnded: datapoints => datapoints[0],
  duration: 20000,

const nflSocket = await Sockets.nflTestnet()
const cleRoster = await nflSocket.roster({ teamId: 'CLE' })

const nbaSocket = await Sockets.nbaTestnet()
const dalRoster = await nbaSocket.roster({ teamId: 'DAL' })

See our API docs for complete code samples for making requests, as well as what responses look like, for all API endpoints and request types.


We recommend using TypeScript with this library. It has excellent type support built in, as it's written in TypeScript. When using TS you'll have all parameters passed to your requests type checked. The data type of the argument in onData or onSnapshot in a exchange socket will also change based on which exchange and which data type (tickers, books or trades) you request.

Debug logging

This library uses the debug module for logging what's going on. debug logs using what it calls namespaces. This library logs under the following namespaces:

  • sb-abi:lightning:lnd - LND related functionality
  • sb-api:lightning:eclair - Eclair related functionality
  • sb-api:lightning:clightning - c-lightning related functionality
  • sb-api:socket:base - functionality common for all sockets
  • sb-api:socket:ppc - functionality common for pay-per-call sockets (NBA & NFL)
  • sb-api:socket:exchange - crypto market data logging
  • sb-api:validation - logs the validation of incoming data from the API

To activate logging output for a given namespace you need to set the DEBUG environment variable. Namespaces are hierarchically organized with : as the level separator. It's possible to specify multiple namespaces by comma-separating them. DEBUG=sb-api:* causes all namespaces to get logged. Setting DEBUG to sb-api:socket:* activates the sb-api:socket:base, sb-api:socket:ppc and sb-api:socket:exchange namespaces.

DEBUG=sb-api:lightning:*,sb-api:socket:base,sb-api:socket:ppc would enable logging of all Lightning activity, the functionality common for all sockets and the functionality common for pay-per-call sockets (NBA & NFL).


$ yarn publish

Lints, checks formatting, makes new git tag, pushes new git tag, build, pushes build to npm

You can’t perform that action at this time.