Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic yield generator with telegram notifications #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions yield-generators/yg-telegram-notifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

import time
from http import client
from jmbase import jmprint
from jmclient import YieldGeneratorBasic, ygmain, calc_cj_fee
from urllib import parse

API_KEY = ''
CHAT_ID = ''

# YIELD GENERATOR SETTINGS ARE NOW IN YOUR joinmarket.cfg CONFIG FILE
# (You can also use command line flags; see --help for this script).

class TelegramNotifierYieldGeneratorBasic(YieldGeneratorBasic):
def on_tx_confirmed(self, offer, txid, confirmations):
real_cjfee = calc_cj_fee(offer['offer']['ordertype'],
offer['offer']['cjfee'], offer['amount'])
earned_sats = real_cjfee - offer['offer']['txfee']
mix_amount = offer['amount']
if offer['cjaddr'] in self.tx_unconfirm_timestamp:
confirm_time = int(time.time()) - self.tx_unconfirm_timestamp[offer['cjaddr']]
else:
confirm_time = 0

confirm_time = round(confirm_time / 60.0)

message = f"💰 earned {earned_sats:,} sats mixing {mix_amount:,} sats in {confirm_time} minutes"
params = parse.urlencode({'chat_id': CHAT_ID, 'text': message})
conn = client.HTTPSConnection('api.telegram.org')
conn.request('POST', f'/bot{API_KEY}/sendMessage', params, {'Content-Type': 'application/x-www-form-urlencoded'})
_ = conn.getresponse()

return super().on_tx_confirmed(offer, txid, confirmations)

if __name__ == "__main__":
ygmain(TelegramNotifierYieldGeneratorBasic)
jmprint('done', "success")