Last active
May 14, 2024 11:33
-
-
Save darosior/3651bf3f601910a13e07829672831dcd to your computer and use it in GitHub Desktop.
A quick script to plot the balance over time of a C-lightning routing node using the report from `bkpr-listincome`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from datetime import datetime | |
STARTING_BALANCE = 0 | |
with open("bkpr_report.json", "r") as report: | |
events = json.load(report)["income_events"] | |
# Balance variations per day, disregarding our own payments. | |
variations = {} | |
for e in events: | |
if e["tag"] == "invoice" or e["tag"] == "invoice_fee": | |
continue | |
date = datetime.fromtimestamp(e["timestamp"]).strftime("%Y-%m-%d") | |
if date not in variations: | |
variations[date] = 0 | |
variations[date] += (e["credit_msat"] - e["debit_msat"]) // 1_000 | |
fig, ax = plt.subplots() | |
fig.suptitle("Balance over time, no payments") | |
ax.plot(variations.keys(), variations.values(), label="Balance variations", color="orange") | |
ax.set_xticks(np.arange(0, len(variations), len(variations) // 5)) | |
ax.set_ylabel("Variations (sats)") | |
ax.legend(loc="upper right") | |
# Balance per day, disregarding our own payments. NOTE: dicts are sorted since Python 3.7 | |
balance, balances = (STARTING_BALANCE, {}) | |
for ts, var in variations.items(): | |
balance += var / 10**8 | |
balances[ts] = balance | |
bal_ax = ax.twinx() | |
bal_ax.plot(balances.keys(), balances.values(), label="Balance", color="blue") | |
bal_ax.set_ylabel("Balance (BTC)") | |
bal_ax.legend(loc="upper left") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment