ThresholdRecommendations
Get close recommendations for currently open channels based whether they are below a set threshold.
Example request: http://localhost:8466/v1/faraday/threshold/UPTIME?rec_request.minimum_monitored=123
Source: faraday.proto
gRPC
rpc ThresholdRecommendations (ThresholdRecommendationsRequest) returns (CloseRecommendationsResponse);
REST
| HTTP Method | Path | 
|---|---|
| GET | /v1/faraday/threshold/{rec_request.metric} | 
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:8465'
const MACAROON_PATH = 'FARADAY_DIR/regtest/faraday.macaroon'
const TLS_PATH = 'FARADAY_DIR/tls.cert'
const loaderOptions = {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
};
const packageDefinition = protoLoader.loadSync('faraday.proto', loaderOptions);
const frdrpc = grpc.loadPackageDefinition(packageDefinition).frdrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
  let metadata = new grpc.Metadata();
  metadata.add('macaroon', macaroon);
  callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new frdrpc.FaradayServer(GRPC_HOST, creds);
let request = {
  rec_request: <CloseRecommendationRequest>,
  threshold_value: <float>,
};
client.thresholdRecommendations(request, function(err, response) {
  console.log(response);
});
// Console output:
//  {
//    "total_channels": <int32>,
//    "considered_channels": <int32>,
//    "recommendations": <Recommendation>,
//  }
import codecs, grpc, os
# Generate the following 2 modules by compiling the faraday.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import faraday_pb2 as frdrpc, faraday_pb2_grpc as faradaystub
GRPC_HOST = 'localhost:8465'
MACAROON_PATH = 'FARADAY_DIR/regtest/faraday.macaroon'
TLS_PATH = 'FARADAY_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
  callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = faradaystub.FaradayServerStub(channel)
request = frdrpc.ThresholdRecommendationsRequest(
  rec_request=<CloseRecommendationRequest>,
  threshold_value=<float>,
)
response = stub.ThresholdRecommendations(request)
print(response)
# {
#    "total_channels": <int32>,
#    "considered_channels": <int32>,
#    "recommendations": <Recommendation>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8082'
const MACAROON_PATH = 'FARADAY_DIR/regtest/faraday.macaroon'
let options = {
  url: `https://${REST_HOST}/v1/faraday/threshold/{rec_request.metric}`,
  // Work-around for self-signed certificates.
  rejectUnauthorized: false,
  json: true,
  headers: {
    'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
  },
}
request.get(options, function(error, response, body) {
  console.log(body);
});
// Console output:
//  {
//    "total_channels": <integer>, // <int32> 
//    "considered_channels": <integer>, // <int32> 
//    "recommendations": <array>, // <Recommendation> 
//  }
import base64, codecs, json, requests
REST_HOST = 'localhost:8082'
MACAROON_PATH = 'FARADAY_DIR/regtest/faraday.macaroon'
TLS_PATH = 'FARADAY_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/faraday/threshold/{rec_request.metric}'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
r = requests.get(url, headers=headers, verify=TLS_PATH)
print(r.json())
# {
#    "total_channels": <int32>,
#    "considered_channels": <int32>,
#    "recommendations": <Recommendation>,
# }
$ frcli threshold --help
NAME:
   frcli threshold - Get close recommendations for currently open channels based on whether they are below a set threshold.
USAGE:
   frcli threshold [command options] [arguments...]
CATEGORY:
   recommendations
OPTIONS:
   --uptime value         Ratio of uptime to time monitored, expressed in [0;1]. (default: 0)
   --revenue value        threshold revenue (in msat) per confirmation beneath which channels will be identified for close. (default: 0)
   --incoming value       threshold incoming volume (in msat) per confirmation beneath which channels will be identified for close (default: 0)
   --outgoing value       threshold outgoing volume (in msat) per confirmation beneath which channels will be identified for close (default: 0)
   --volume value         threshold total volume (in msat) per confirmation beneath which channels will be identified for close (default: 0)
   --min_monitored value  amount of time in seconds a channel should be monitored for to be eligible for close (default: 2419200)
   
Messages
frdrpc.ThresholdRecommendationsRequest
Source: faraday.proto
| Field | gRPC Type | REST Type | REST Placement | 
|---|---|---|---|
| rec_request | CloseRecommendationRequest | object | mixed | 
| threshold_value | float | number | query | 
frdrpc.CloseRecommendationsResponse
Source: faraday.proto
| Field | gRPC Type | REST Type | 
|---|---|---|
| total_channels | int32 | integer | 
| considered_channels | int32 | integer | 
| recommendations | Recommendation[] | array | 
Nested Messages
frdrpc.CloseRecommendationRequest
| Field | gRPC Type | REST Type | 
|---|---|---|
| minimum_monitored | int64 | string | 
| metric | Metric | string | 
frdrpc.Recommendation
| Field | gRPC Type | REST Type | 
|---|---|---|
| chan_point | string | string | 
| value | float | number | 
| recommend_close | bool | boolean | 
Enums
frdrpc.CloseRecommendationRequest.Metric
| Name | Number | 
|---|---|
| UNKNOWN | 0 | 
| UPTIME | 1 | 
| REVENUE | 2 | 
| INCOMING_VOLUME | 3 | 
| OUTGOING_VOLUME | 4 | 
| TOTAL_VOLUME | 5 |