Added some more logging/notifying to watch-minimum-balances.
This commit is contained in:
parent
7cfc1b76ba
commit
cc5b7b2af7
|
@ -23,26 +23,36 @@ import mango.marketmaking.marketmaker # nopep8
|
|||
import mango.marketmaking.modelstate # nopep8
|
||||
import mango.marketmaking.toleranceorderreconciler # nopep8
|
||||
|
||||
parser = argparse.ArgumentParser(description="Shows the on-chain data of a particular account.")
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Watches one or many accounts (via a websocket) and sends a notification if the SOL balance falls below the --minimum-sol-balance threshold.")
|
||||
mango.ContextBuilder.add_command_line_parameters(parser)
|
||||
mango.Wallet.add_command_line_parameters(parser)
|
||||
parser.add_argument("--name", type=str, required=True, default="watch-minimum-balances",
|
||||
help="Name oh this instance (to appear in notifications)")
|
||||
parser.add_argument("--named-address", type=str, required=True, action="append", default=[],
|
||||
help="Name and address of the Solana account to watch, separated by a colon")
|
||||
parser.add_argument("--minimum-sol-balance", type=Decimal, default=Decimal("0.1"),
|
||||
help="the minimum SOL balance required for the alert. A SOL balance less than this value will trigger a nifitication.")
|
||||
help="the minimum SOL balance required for the alert. A SOL balance less than this value will trigger a nofitication.")
|
||||
parser.add_argument("--timer-limit", type=int, default=(60 * 60),
|
||||
help="notifications for an account will be sent at most once per timer-limit seconds, and accounts will be polled once per timer-limit seconds irrespective of websocket activity")
|
||||
parser.add_argument("--notify", type=mango.parse_subscription_target, action="append", default=[],
|
||||
help="The notification target for low balance events")
|
||||
parser.add_argument("--notify-events", type=mango.parse_subscription_target, action="append", default=[],
|
||||
help="The notification target for low balance events")
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.getLogger().setLevel(args.log_level)
|
||||
logging.warning(mango.WARNING_DISCLAIMER_TEXT)
|
||||
|
||||
|
||||
def send_notification(message: str) -> None:
|
||||
def send_balance_notification(message: str) -> None:
|
||||
for notify in args.notify:
|
||||
notify.send(f"[watch-minimum-balances] {message}")
|
||||
notify.send(f"[{args.name}] {message}")
|
||||
|
||||
|
||||
def send_event_notification(message: str) -> None:
|
||||
for notify in args.notify_events:
|
||||
notify.send(f"[{args.name}] {message}")
|
||||
|
||||
|
||||
def sols_from_lamports(lamports: Decimal) -> Decimal:
|
||||
|
@ -53,7 +63,7 @@ def notifier(name: str) -> typing.Callable[[mango.AccountInfo], None]:
|
|||
def notify(account_info: mango.AccountInfo) -> None:
|
||||
account_sols = sols_from_lamports(account_info.lamports)
|
||||
report = f"Account \"{name} [{account_info.address}]\" on {context.cluster} has only {account_sols} SOL, which is below the minimum required balance of {args.minimum_sol_balance} SOL."
|
||||
send_notification(report)
|
||||
send_balance_notification(report)
|
||||
print(f"Notification sent: {report}")
|
||||
return notify
|
||||
|
||||
|
@ -109,12 +119,13 @@ ws_pong_disposable = ws.pong.subscribe(mango.FileToucherObserver("/var/tmp/mango
|
|||
disposer.add_disposable(ws_pong_disposable)
|
||||
ws_pong_log_disposable = ws.pong.subscribe(on_next=lambda _: logging.info("Pong"))
|
||||
disposer.add_disposable(ws_pong_log_disposable)
|
||||
ws_connecting_log_disposable = ws.connecting.subscribe(on_next=lambda _: send_notification("Re-connecting websocket"))
|
||||
ws_connecting_log_disposable = ws.connecting.subscribe(
|
||||
on_next=lambda _: send_event_notification("Re-connecting websocket"))
|
||||
disposer.add_disposable(ws_connecting_log_disposable)
|
||||
|
||||
ws.open()
|
||||
|
||||
send_notification(f"Starting using context:\n{context}")
|
||||
send_event_notification(f"Starting using context:\n{context}")
|
||||
|
||||
# Wait - don't exit. Exiting will be handled by signals/interrupts.
|
||||
waiter = threading.Event()
|
||||
|
|
Loading…
Reference in New Issue