-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfleet_accounting.py
More file actions
171 lines (139 loc) · 5.05 KB
/
Copy pathfleet_accounting.py
File metadata and controls
171 lines (139 loc) · 5.05 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
"""
fleet_accounting.py — Full financial breakdown for all bots.
Shows free, staked, totals, staking yields, APY, and fleet aggregates.
Usage:
python fleet_accounting.py
python fleet_accounting.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 fetch_accounting(bot_cfg):
"""Fetch full accounting data for a single bot."""
name = bot_cfg["name"]
result = {"name": name, "error": None}
try:
agent = Agent(bot_cfg["api_key"])
bal = agent.balance()
result["free_lit"] = bal.get("litcoin", 0)
result["litcredit"] = bal.get("litcredit", 0)
try:
stk = agent.stake_info()
result["staked"] = stk.get("amount", 0)
result["tier"] = stk.get("tier", 0)
result["lock_remaining"] = 0
try:
result["lock_remaining"] = agent.time_until_unlock()
except Exception:
pass
except Exception:
result["staked"] = 0
result["tier"] = 0
result["lock_remaining"] = 0
result["total"] = result["free_lit"] + result["staked"]
try:
sy = agent.staking_yield()
result["daily_yield"] = sy.get("dailyYield", 0)
result["apy"] = sy.get("apy", 0)
except Exception:
result["daily_yield"] = 0
result["apy"] = 0
try:
result["boost"] = agent.mining_boost()
except Exception:
result["boost"] = 0
try:
status = agent.status()
result["claimable"] = status.get("claimable", 0)
result["total_earned"] = status.get("totalEarned", 0)
except Exception:
result["claimable"] = 0
result["total_earned"] = 0
except Exception as e:
result["error"] = str(e)
return result
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 fleet accounting")
parser.add_argument("--config", default="config.json", help="Path to config file")
args = parser.parse_args()
config = load_config(args.config)
bots = [b for b in config.get("bots", []) if b.get("enabled", True)]
if not bots:
print("No enabled bots found in config.")
sys.exit(1)
results = []
for bot_cfg in bots:
results.append(fetch_accounting(bot_cfg))
# Per-bot detail
print(f"\n{'='*70}")
print(f" LITCOIN Fleet Accounting — {len(bots)} bot(s)")
print(f"{'='*70}")
fleet_free = 0
fleet_staked = 0
fleet_total = 0
fleet_yield = 0
fleet_claimable = 0
fleet_total_earned = 0
for r in results:
if r.get("error"):
print(f"\n {r['name']}: ERROR — {r['error']}")
continue
free = r["free_lit"]
staked = r["staked"]
total = r["total"]
tier = r["tier"]
daily_yield = r["daily_yield"]
apy = r["apy"]
boost = r["boost"]
claimable = r["claimable"]
total_earned = r["total_earned"]
lock = r["lock_remaining"]
fleet_free += free
fleet_staked += staked
fleet_total += total
fleet_yield += daily_yield
fleet_claimable += claimable
fleet_total_earned += total_earned
lock_str = f"{lock // 86400}d {(lock % 86400) // 3600}h" if lock > 0 else "Unlocked"
print(f"\n {r['name']} (Tier {tier})")
print(f" Free: {format_lit(free):>12}")
print(f" Staked: {format_lit(staked):>12} (lock: {lock_str})")
print(f" Total: {format_lit(total):>12}")
print(f" LITCREDIT: {r.get('litcredit', 0):>12,.0f}")
print(f" Daily yield: {daily_yield:>12,.0f} LIT ({apy:.1f}% APY)")
print(f" Mining boost: {boost/100:.0f}%")
print(f" Claimable: {claimable:>12,.0f}")
print(f" Total earned: {format_lit(total_earned):>12}")
# Fleet totals
print(f"\n{'─'*70}")
print(f" FLEET TOTALS")
print(f" Free: {format_lit(fleet_free):>12}")
print(f" Staked: {format_lit(fleet_staked):>12}")
print(f" Total: {format_lit(fleet_total):>12}")
print(f" Daily yield: {fleet_yield:>12,.0f} LIT")
print(f" Claimable: {fleet_claimable:>12,.0f}")
print(f" Total earned: {format_lit(fleet_total_earned):>12}")
print(f"{'='*70}\n")
if __name__ == "__main__":
main()