-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunding_gap.py
More file actions
92 lines (74 loc) · 2.79 KB
/
Copy pathfunding_gap.py
File metadata and controls
92 lines (74 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
"""
funding_gap.py — Calculate how much each bot needs to reach the mining threshold.
Shows per-bot deficit and total LIT needed to get the fleet fully funded.
Usage:
python funding_gap.py
python funding_gap.py --target 5000000
python funding_gap.py --config path/to/config.json
"""
import json
import sys
import argparse
from pathlib import Path
try:
from litcoin import Agent
except ImportError:
print("ERROR: litcoin package not installed. Run: pip install litcoin")
sys.exit(1)
def load_config(path="config.json"):
p = Path(path)
if not p.exists():
print(f"ERROR: Config file not found: {path}")
print("Copy config.example.json to config.json and fill in your values.")
sys.exit(1)
with open(p) as f:
return json.load(f)
def format_lit(amount):
if amount >= 1_000_000:
return f"{amount / 1_000_000:.2f}M"
elif amount >= 1_000:
return f"{amount / 1_000:.1f}K"
return f"{amount:,.0f}"
def main():
parser = argparse.ArgumentParser(description="LITCOIN funding gap calculator")
parser.add_argument("--config", default="config.json", help="Path to config file")
parser.add_argument("--target", type=int, default=None,
help="Target FREE balance per bot (default: from config min_free_balance)")
args = parser.parse_args()
config = load_config(args.config)
bots = [b for b in config.get("bots", []) if b.get("enabled", True)]
target = args.target or config.get("mining", {}).get("min_free_balance", 5_000_000)
if not bots:
print("No enabled bots found in config.")
sys.exit(1)
print(f"\n{'='*55}")
print(f" Funding Gap Analysis — Target: {format_lit(target)} free LIT per bot")
print(f"{'='*55}")
total_deficit = 0
all_funded = True
for bot_cfg in bots:
name = bot_cfg["name"]
try:
agent = Agent(bot_cfg["api_key"])
bal = agent.balance()
free = bal.get("litcoin", 0)
deficit = max(0, target - free)
if deficit > 0:
all_funded = False
total_deficit += deficit
print(f" {name:12s} {format_lit(free):>10} free → needs {format_lit(deficit):>10}")
else:
surplus = free - target
print(f" {name:12s} {format_lit(free):>10} free ✓ surplus {format_lit(surplus):>10}")
except Exception as e:
print(f" {name:12s} ERROR: {e}")
print(f"\n{'─'*55}")
if all_funded:
print(" All bots are at or above the target balance.")
else:
print(f" Total deficit: {format_lit(total_deficit)}")
print(f" Fund these bots to reach mining threshold.")
print(f"{'='*55}\n")
if __name__ == "__main__":
main()