Exemplo n.º 1
0
    def __init__(self, telegram_token, auth_pass, btfx_key, btfx_secret):
        LOGGER.info("Here be dragons")
        self.userdata = utils.read_userdata()
        self.auth_pass = auth_pass
        self.btfx_client = Client(btfx_key, btfx_secret)
        self.btfx_client2 = Client2(btfx_key, btfx_secret)
        self.btfx_symbols = self.btfx_client.symbols()

        updater = Updater(telegram_token)
        self.tbot = updater.bot
        self.btfxwss = Bfxwss(self.tbot,
                              self.send_to_users,
                              key=btfx_key,
                              secret=btfx_secret)
        # Get the dispatcher to register handlers
        qdp = updater.dispatcher
        # on different commands - answer in Telegram
        qdp.add_handler(CommandHandler("start", self.cb_start))
        qdp.add_handler(CommandHandler("graph", self.cb_graph, pass_args=True))
        qdp.add_handler(CommandHandler("auth", self.cb_auth, pass_args=True))
        qdp.add_handler(
            CommandHandler("option", self.cb_option, pass_args=True))
        qdp.add_handler(
            CommandHandler("neworder", self.cb_new_order, pass_args=True))
        qdp.add_handler(
            CommandHandler("orders", self.cb_orders, pass_args=True))
        qdp.add_handler(CommandHandler("calc", self.cb_calc, pass_args=True))
        qdp.add_handler(CommandHandler("help", self.cb_help, pass_args=True))
        qdp.add_handler(
            CallbackQueryHandler(self.cb_btn_cancel_order,
                                 pattern=r'^cancel_order:[0-9]+$'))
        qdp.add_handler(
            CallbackQueryHandler(self.cb_btn_orders, pattern=r'^orders:\w+$'))

        # log all errors
        qdp.add_error_handler(self.cb_error)

        # Start the Bot
        updater.start_polling(timeout=60, read_latency=0.2)

        # Block until you press Ctrl-C or the process receives SIGINT, SIGTERM or
        # SIGABRT. This should be used most of the time, since start_polling() is
        # non-blocking and will stop the bot gracefully.
        updater.idle()
Exemplo n.º 2
0
    def __init__(self, telegram_token, auth_pass, btfx_key, btfx_secret):
        LOGGER.info("Here be dragons")
        self.userdata = utils.read_userdata()
        self.auth_pass = auth_pass
        self.btfx_client = Client(btfx_key, btfx_secret)
        self.btfx_client2 = Client2(btfx_key, btfx_secret)
        self.btfx_symbols = self.btfx_client.symbols()
        self.currencies = utils.get_currencies(self.btfx_symbols)

        updater = Updater(telegram_token)
        self.tbot = updater.bot
        self.btfxwss = Bfxwss(self.send_to_users,
                              key=btfx_key,
                              secret=btfx_secret)
        # Get the dispatcher to register handlers
        qdp = updater.dispatcher
        # on different commands - answer in Telegram
        qdp.add_handler(CommandHandler("start", self.cb_start))
        qdp.add_handler(CommandHandler("auth", self.cb_auth, pass_args=True))
        qdp.add_handler(CommandHandler("graph", self.cb_graph, pass_args=True))
        qdp.add_handler(CommandHandler("set", self._cb_set, pass_args=True))
        qdp.add_handler(
            CommandHandler("getbalance", self._cb_get_balance, pass_args=True))
        qdp.add_handler(
            CommandHandler("enable", self.cb_enable, pass_args=True))
        qdp.add_handler(
            CommandHandler("disable", self.cb_disable, pass_args=True))
        qdp.add_handler(
            CommandHandler("neworder", self.cb_new_order, pass_args=True))
        qdp.add_handler(
            CommandHandler("newalert", self._cb_new_alert, pass_args=True))
        qdp.add_handler(
            CommandHandler("orders", self._cb_orders, pass_args=True))
        qdp.add_handler(CommandHandler("calc", self._cb_calc, pass_args=True))
        qdp.add_handler(CommandHandler("help", self._cb_help, pass_args=True))
        qdp.add_handler(CommandHandler("ticker", self.ticker, pass_args=True))

        update_volume_handler = CallbackQueryHandler(
            self.cb_btn_update_volume,
            pattern=r'^update_volume:[0-9]+$',
            pass_user_data=True)
        new_volume_handler = MessageHandler(Filters.text,
                                            self.cb_new_volume,
                                            pass_user_data=True)
        upvh = ConversationHandler(
            entry_points=[update_volume_handler],
            states={UPDVOLUME: [new_volume_handler]},
            fallbacks=[CommandHandler('cancel', self.cb_cancel)])
        qdp.add_handler(upvh)

        update_price_handler = CallbackQueryHandler(
            self.cb_btn_update_price,
            pattern=r'^update_price:[0-9]+$',
            pass_user_data=True)
        new_price_handler = MessageHandler(Filters.text,
                                           self.cb_new_price,
                                           pass_user_data=True)

        upch = ConversationHandler(
            entry_points=[update_price_handler],
            states={UPDPRICE: [new_price_handler]},
            fallbacks=[CommandHandler('cancel', self.cb_cancel)])

        qdp.add_handler(upch)

        qdp.add_handler(
            CallbackQueryHandler(self.cb_btn_cancel_order,
                                 pattern=r'^cancel_order:[0-9]+$'))
        qdp.add_handler(
            CallbackQueryHandler(self.cb_btn_orders, pattern=r'^orders:\w+$'))

        # log all errors
        qdp.add_error_handler(self.cb_error)

        # Start the Bot
        updater.start_polling(timeout=60, read_latency=0.2)

        # Block until you press Ctrl-C or the process receives SIGINT, SIGTERM or
        # SIGABRT. This should be used most of the time, since start_polling() is
        # non-blocking and will stop the bot gracefully.
        updater.idle()
Exemplo n.º 3
0
 def test_save_userdata(self):
     userdata = utils.read_userdata()
     self.assertIsNone(utils.save_userdata(userdata))
     self.assertTrue(glob.glob('data/usersdata.pickle'))
     self.assertTrue(glob.glob('data/usersdata.json'))
Exemplo n.º 4
0
 def test_read_userdata(self):
     userdata = utils.read_userdata()
     self.assertIsInstance(userdata, dict)