def _cb_new_alert(self, bot, update, args): """ Set a price alert for a tradepair All price alerts expire after they get triggered 100 times /newalert iotusd 0.55 """ LOGGER.info(f"{update.message.chat.username} : /newalert {args}") chat_id = update.message.chat.id # Verify parameters if len(args) < 2: self.send_help(chat_id, "newalert") return tradepair = args[0] price = args[1] if tradepair not in self.btfx_symbols: msgtext = f"incorect tradepair , available pairs are {self.btfx_symbols}" bot.send_message(chat_id, text=msgtext, parse_mode='HTML') return if not utils.isnumber(price): bot.send_message(chat_id, text=f"incorect price , {price} is not a number") return tradepair = f"t{tradepair.upper()}" response = self.btfx_client2.alert_set('price', tradepair, float(price)) if response[4] == 100: msgtext = "<pre> Alert Set Succesfully </pre>" bot.send_message(chat_id, text=msgtext, parse_mode='HTML')
def cb_new_volume(self, bot, update, user_data): LOGGER.info("cb_new_volume called") chat_id = update.message.chat.id amount = update.message.text if not utils.isnumber(amount): message = (f"{amount} is not a valid number\n" "Please send me a valid number or tap /cancel") bot.send_message(chat_id, text=message) return None bot.sendChatAction(chat_id, "TYPING") self.btfxwss.update_order(id=user_data['update_volume_order_id'], amount=amount) return ConversationHandler.END
def cb_new_price(self, bot, update, user_data): LOGGER.info("cb_new_price called") chat_id = update.message.chat.id price = update.message.text if not utils.isnumber(price): LOGGER.info("cb_new_price not a number") message = (f"{price} is not a valid number\n" "Please send me a valid number or tap /cancel") update.message.reply_text(message, parse_mode='HTML') return None bot.sendChatAction(chat_id, "TYPING") self.btfxwss.update_order(id=user_data['update_price_order_id'], price=price) return ConversationHandler.END
def cb_new_order(self, bot, update, args): LOGGER.info(f"{update.message.chat.username} : /neworder {args}") chat_id = update.message.chat.id # Verify parameters if len(args) < 4: self.send_help(chat_id, "neworder") return volume = args[0] price = args[1] tradepair = args[2] tradetype = args[3] if not utils.isnumber(volume): bot.send_message( chat_id, text=f"incorect volume , {volume} is not a number") return if not utils.isnumber(price): bot.send_message(chat_id, text=f"incorect price , {price} is not a number") return if tradepair not in self.btfx_symbols: msgtext = f"incorect tradepair , available pairs are {self.btfx_symbols}" bot.send_message(chat_id, text=msgtext, parse_mode='HTML') return if tradetype not in utils.REST_TYPES: types = " ".join(utils.REST_TYPES) msgtext = f"incorect tradetype , available types are : {types}" bot.send_message(chat_id, text=msgtext, parse_mode='HTML') return side = 'buy' if float(volume) > 0 else 'sell' volume = abs(float(volume)) neworder = self.btfx_client.place_order(str(volume), price, side, utils.REST_TYPES[tradetype], symbol=tradepair) if 'message' in neworder: bot.send_message(chat_id, text=neworder['message']) return order_id = neworder['id'] buttons = [ InlineKeyboardButton('Update Price', callback_data=f"update_price:{order_id}"), InlineKeyboardButton('Update Volume', callback_data=f"update_volume:{order_id}"), InlineKeyboardButton('Cancel order', callback_data=f"cancel_order:{order_id}") ] keyboard = InlineKeyboardMarkup([buttons]) formated_message = f"Order {order_id} placed succesfully\n" try: update.message.reply_text(formated_message, reply_markup=keyboard) except (TimedOut, TelegramError) as error: LOGGER.info(f"coult not send message keyboard to {chat_id}") LOGGER.info(error)
def test_isnumber(self): self.assertTrue(utils.isnumber("100.4")) self.assertFalse(utils.isnumber("100.a"))