python 比特币机器人

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 比特币机器人相关的知识,希望对你有一定的参考价值。

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"

以上是关于python 比特币机器人的主要内容,如果未能解决你的问题,请参考以下文章

如何让比特币在 0.0.0.0:8332 上市? [关闭]

特斯拉暂停使用比特币支付 | 《爱死亡和机器人》第二季明日上线

比特币自动交易代码和套利机器人 (开源软件)

在比特币上构建机器学习竞赛市场

CCR炒币机器人:4.21比特币/BTC行情分析及CCR表现分享

使用PHP和树莓派开发一个比特币和以太坊交易机器人