-
-
Save halienm/f906e5995a1277bb555c476f11c3db2f to your computer and use it in GitHub Desktop.
bitcoin bot
This file contains 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
from telegram.ext import CommandHandler, Updater, Job | |
from exchanges.bitfinex import Bitfinex | |
from exchanges.coindesk import CoinDesk | |
bitfinex = Bitfinex() | |
coindesk = CoinDesk() | |
up = Updater("YOUR CUSTOM BOT-FATHER-ROVIDED TOKEN") | |
listjobs = [] | |
def stop(bot, update): | |
bot.sendMessage(chat_id=update.message.chat_id, text="Stoping right now") | |
for j in listjobs: | |
if j.context["id"] == update.message.chat_id: | |
j.schedule_removal() | |
def kill(bot, update): | |
import sys | |
up.job_queue.stop() | |
up.stop() | |
sys.exit(0) | |
def watch(bot, job): | |
value = job.context['value'] | |
coin = coindesk.get_current_price() | |
bit = bitfinex.get_current_price() | |
if value > coin or value > bit: | |
job.context["count"] = 0 | |
msg = "Current price coindesk: {} and bitfinex:{}" | |
bot.sendMessage(chat_id=job.context['id'], | |
text=msg.format(coin, bit)) | |
else: | |
if job.context.get('count') is None: | |
job.context["count"] = 0 | |
if job.context["count"] == 360: | |
job.context["count"] = 0 | |
bot.sendMessage(chat_id=job.context[ | |
'id'], text="all ok {}".format(coin)) | |
else: | |
job.context["count"] += 1 | |
def updates(bot, update): | |
value = update.message.text.split(" ") | |
if len(value) >= 2: | |
value = float(value[1]) | |
print value | |
bot.sendMessage(chat_id=update.message.chat_id, | |
text="Starting right now: ") | |
context = { | |
'id': update.message.chat_id, | |
'value': value | |
} | |
job_watch = Job(watch, 10.0, context=context) | |
listjobs.append(job_watch) | |
up.job_queue.put(job_watch, next_t=0.0) | |
up.dispatcher.add_handler(CommandHandler('stop', stop)) | |
up.dispatcher.add_handler(CommandHandler('kill', kill)) | |
up.dispatcher.add_handler(CommandHandler('updates', updates)) | |
up.start_polling() | |
print "all rigth" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment