Enable Balance Streaming
stream::balance::enable
Using this method, you can enable balance events streaming for a specific coin, to a specific client. For ETH-like coins and tokens, you can also specify the streaming interval in seconds (to avoid excessive polling leading to upstream API rate limts)
Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| coin | string | ✓ | Ticker of the coin to activate streaming for. The coin must be activated first. | |
| client_id | integer | – | 0 | In the case of a single client, this defaults to 0. This ID can be used to access data via http://localhost:7783/event-stream?id=1 |
| config | object | – | EVM only. A standard StreamingConfig object. |
Response Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| streamer_id | string | – | An identifier for the data stream. This can be used later to disable streaming for the event with stream::disable. |
📌 Examples
POST Balance Enable
balance_enable {
"userpass": "RPC_UserP@SSW0RD",
"method": "stream::balance::enable",
"mmrpc": "2.0",
"params": {
"coin": "MATIC",
"config": {
"stream_interval_seconds": 15
},
"client_id": 1
}
} curl --url "http://127.0.0.1:7783" --data '{
"userpass": "RPC_UserP@SSW0RD",
"method": "stream::balance::enable",
"mmrpc": "2.0",
"params": {
"coin": "MATIC",
"config": {
"stream_interval_seconds": 15
},
"client_id": 1
}
}' import requests
import json
url = "http://127.0.0.1:7783"
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "stream::balance::enable",
"mmrpc": "2.0",
"params": {
"coin": "MATIC",
"config": {
"stream_interval_seconds": 15
},
"client_id": 1
}
}
response = requests.post(url, json=payload)
print(json.dumps(response.json(), indent=2)) const payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "stream::balance::enable",
"mmrpc": "2.0",
"params": {
"coin": "MATIC",
"config": {
"stream_interval_seconds": 15
},
"client_id": 1
}
};
const response = await fetch("http://127.0.0.1:7783", {
method: "POST",
body: JSON.stringify(payload),
});
console.log(await response.json()); <?php
$payload = <<<'JSON'
{
"userpass": "RPC_UserP@SSW0RD",
"method": "stream::balance::enable",
"mmrpc": "2.0",
"params": {
"coin": "MATIC",
"config": {
"stream_interval_seconds": 15
},
"client_id": 1
}
}
JSON;
$ch = curl_init("http://127.0.0.1:7783");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
echo $response; package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{"userpass":"RPC_UserP@SSW0RD","method":"stream::balance::enable","mmrpc":"2.0","params":{"coin":"MATIC","config":{"stream_interval_seconds":15},"client_id":1}}`)
resp, err := http.Post("http://127.0.0.1:7783", "application/json", bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
} require 'net/http'
require 'json'
require 'uri'
uri = URI("http://127.0.0.1:7783")
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "stream::balance::enable",
"mmrpc": "2.0",
"params": {
"coin": "MATIC",
"config": {
"stream_interval_seconds": 15
},
"client_id": 1
}
}
response = Net::HTTP.post(uri, payload.to_json, 'Content-Type' => 'application/json')
puts JSON.pretty_generate(JSON.parse(response.body)) Show Balance Enable Response
{
"mmrpc": "2.0",
"result": {
"streamer_id": "BALANCE:MATIC"
},
"id": null
} Here is an example of the stream data you should be able to see in http://localhost:7783/event-stream?id=1 once a balance change is detected:
data: {"_type":"BALANCE:MATIC","message":[{"ticker":"MATIC","address":"0xc11b6070c84a1e6fc62b2a2acf70831545d5edd4","balance":{"spendable":"2.00000001","unspendable":"0"}}]}
Error Types
| Parameter | Type | Required | Description |
|---|---|---|---|
| CoinNotFound | string | – | The specified coin was not found or is not activated yet |
| UnknownClient | string | – | No client has an open connection using this client_id |
| ClientAlreadyListening | string | – | The requested events are already being sent to the client_id |
| EnableError | string | – | The config object is not used in non-EVM coins or other configuration errors |
Show Error Responses
Error Response (Coin Not Found)
{
"mmrpc": "2.0",
"error": "CoinNotFound",
"error_path": "balance",
"error_trace": "balance:47]",
"error_type": "CoinNotFound",
"id": null
}Error (Unknown Client)
{
"mmrpc": "2.0",
"error": "UnknownClient",
"error_path": "balance",
"error_trace": "balance:99]",
"error_type": "EnableError",
"error_data": "UnknownClient",
"id": null
}Error (Client Already Listening)
{
"mmrpc": "2.0",
"error": "ClientAlreadyListening",
"error_path": "balance",
"error_trace": "balance:99]",
"error_type": "EnableError",
"error_data": "ClientAlreadyListening",
"id": null
} Error (Enable Error)
{
"mmrpc": "2.0",
"error": "Invalid config provided. No config needed",
"error_path": "balance",
"error_trace": "balance:60]",
"error_type": "EnableError",
"error_data": "Invalid config provided. No config needed",
"id": null
}