Crypto data API

In December, Suredbits released the worlds first streaming API for cryptocurrency exchange market data over the Lightning Network. It allows developers and traders to query for realtime market data on both spot and futures based products. This is in addition to our sports APIs, where we provide data on NFL and NBA.

All of our APIs are available over web sockets, to ensure low latency and high through put. If you’re not familiar with this technology, we recommend you to do some reading on it first. A good start is this MDN article on the WebSocket API.

To make it easier for developers to integrate our APIs, we have built a JavaScript/TypeScript client library as well as a WebSocket plaground for trying out our APIs. In this post we will go through how to use the client library.

General notes

Our APIs are powered by the Lightning Network, allowing you to stream precisely the data you want, in exchange for micro payments. Our client library handles the payment for you. We encourage you to audit the code that handles sending payments and receiving refunds, so you can stay informed as to what is happening with your money. If you don’t have a Lightning Node set up, we can recommend this Medium article by Pierre Rochard.

This library has handy type inference of all types used for both requests and responses. If you’re using a modern editor like VSCode or WebStorm, you should get feedback in your editor as to what the correct and available fields are at any given time

A subset of our APIs are available on the Bitcoin testnet. Testnet is a version of the Bitcoin network where the coins have no value. Testnet API access is provided to make integration easier, so you have something to play with without risking real money.

Note on async JS: our client library uses promises for handling asynchronous code. If you are using a JavaScript version without support for async/await, you can also use promise chaining. Read more about using both async/await and promise chaining on MDN.

Adding the client library to your project

The client library currently only works with Node.js. It is written in TypeScript, meaning it will have excellent editor support in JavaScript, as well as powerful type inference in TypeScript. We assume you have a preexisting Node.js project you want to integrate our APIs in.

First, add the client library to your project:

# if you're using Yarn: 
yarn add sb-api
#if you're using npm: 
npm install sb-api

Setting up your Lightning connection

Our client library supports all the major Lightning implementations: c-lightningLND and Eclair.


There are several options available for connecting to your LND server. If you don’t provide any of them, we assume you have LND running locally with the default configuration.


You can specify the path to the data directory of your C-Lightning server. If you omit it, we assume it’s in the default location.


You can specify the host, port number and RPC server passphrase of your Eclair server. Both host and port can be omitted, and defaults to localhost:8080.

Requesting streaming data

When it comes to requesting data from our cryptocurrency exchange market APIs, we support multiple different data channels, exchanges, trading pairs and financial products. For a complete overview over what we support, see our API docs for spot based exchanges as well as futures based exchanges. For the purpose of this guide, we will request data from a spot exchange.

Here’s a complete example for requesting 5 minutes of data about Binance BTCUSDT trades:

During your subscription you can top up with a longer duration:

If you for some reason want to cancel your subscription, that only requires one line of code:

Any remaining time left in your subscription is paid back to you. On subscription start, your node generates a Lightning invoice for the refund payment. You can also specify this manually, if you want full control.

Requesting data with request/response

Our sport data APIs for NFL and NBA are centered around a traditional request/response model. You send a request, and you get a simple response in return. Our library helps you construct a correct request, as well as help you figure out the type of the response. Here’s an example:

Our NBA API works similarly to our NFL API. For a complete walk through of all the various requests you can make, see our API docs on NFL and NBA.

We hope this guide helped you in getting started with our Lightning-enabled APIs. If you have any questions or feedback, we’d love to hear from you. Hit us up on Twitter or join our public Suredbits Slack.