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.
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.
Adding the client library to your project
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
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
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: