def initialize_bot(self, update, context): #Start Command: /start DB = Database() message = update.message if self.correct_user(message, DB): chat_id = message.chat.id DB.save_chat_id(chat_id) self.chat_id = chat_id message.reply_text("Hello " + message.from_user.first_name)
def bot_info(self, update, context): #Help Command: /help DB = Database() message = update.message if self.correct_user(message, DB): help = help_message() message.reply_text(help)
def show_order_history(self, update, context): #''' View order history: /orderhistory #Sends a csv of their past orders''' DB = Database() message = update.message if self.correct_user(message, DB): try: if self.csv_file_name != None: os.remove(self.csv_file_name) #Deletes file once sent self.csv_file_name = None quick_token_text = message.text.replace( "/orderhistory", "").replace(" ", "").upper() if "USDT" in quick_token_text: token = quick_token_text else: token = quick_token_text + "USDT" all_orders = self.client.see_all_orders(token) self.order_history_csv(token, all_orders) doc = open(self.csv_file_name, 'rb') self.bot.send_document(self.chat_id, doc) except Exception as e: print(str(e)) message.reply_text( self.general_error_message + " AND make sure that you have made orders in the past using the token in question\n\nex. /orderhistory btc \n\n/orderhistory {symbol}" )
def make_market_order(self, update, context): #Market order: /market {side} {amount} {symbol} DB = Database() message = update.message if self.correct_user(message, DB): try: order_confirmation = self.client.send_order("market", message) message.reply_text(order_confirmation) except Exception as e: print(str(e)) message.reply_text( self.general_error_message + "ex. /market buy 0.01 eth \n\n/market {side} {amount} {symbol}" )
def make_limit_order(self, update, context): #Limit order: /limit {timeInForce} {side} {amount} {symbol} at {price} DB = Database() message = update.message if self.correct_user(message, DB): try: order_confirmation = self.client.send_order("limit", message) message.reply_text(order_confirmation) #bot.reply_to(message, order_confirmation) except Exception as e: print(str(e)) message.reply_text( self.general_error_message + "ex. /limit gtc sell 0.01 ethusdt at 1858 \n\n/limit {timeInForce} {side} {amount} {symbol} at {price}" )
def unblock_tradingview_orders(self, update, context): #''' Unblocks tradingview orders ''' DB = Database() message = update.message if self.correct_user(message, DB): if self.block_tradingview: self.block_tradingview = False message.reply_text( "TradingView orders ready to continue. /block to block TradingView orders" ) #bot.reply_to(message, "TradingView orders ready to continue. /block to block TradingView orders") else: message.reply_text( "TradingView orders are currently active. /block to block TradingView orders" )
def block_tradingview_orders(self, update, context): #''' Temporarily blocks tradingview orders ''' DB = Database() message = update.message if self.correct_user(message, DB): if self.block_tradingview: message.reply_text( "TradingView orders are already blocked. /unblock to continue TradingView orders" ) #bot.reply_to(message, "TradingView orders are already blocked. /unblock to continue TradingView orders") else: self.block_tradingview = True message.reply_text( "TradingView orders are now blocked. /unblock to continue TradingView orders" )
def cancel_order(self, update, context): #'''Cancels an order /cancel {symbol} {orderId}''' DB = Database() message = update.message if self.correct_user(message, DB): try: cancelled_order = self.client.cancel_order(message) cancel_message = cancelled_message(cancelled_order) message.reply_text(cancel_message) #bot.reply_to(message, cancel_message) except Exception as e: print(str(e)) message.reply_text( self.general_error_message + "ex. /cancel eth 6963\n\n/cancel {symbol} {order Id}\n\n")
def make_stoploss_order(self, update, context): #'''Makes only one order: /stoploss {timeInForce} {side} {amount} {symbol} at {price} stop at {stopLoss}''' DB = Database() message = update.message if self.correct_user(message, DB): try: order_confirmation = self.client.send_order( "stoploss", message) message.reply_text(order_confirmation) #bot.reply_to(message, order_confirmation) except Exception as e: print(str(e)) message.reply_text( self.general_error_message + "ex. /stoploss gtc sell 0.1 btc at 55000 stop at 56000\n\n /stoploss {timeInForce} {side} {amount} {symbol} at {price} stop at {stopLoss}" )
def show_open_orders(self, update, context): #''' View open orders for a given token: /openorders {symbol}''' DB = Database() message = update.message if self.correct_user(message, DB): try: quick_token_text = message.text.replace( "/openorders", "").replace(" ", "").upper() if "USDT" in quick_token_text: token = quick_token_text else: token = quick_token_text + "USDT" open_orders = self.client.open_orders(token) self.open_orders_message_chain(open_orders, self.bot, token) except Exception as e: print(str(e)) message.reply_text( self.general_error_message + "ex. /openorders eth\n\n/openorders {symbol}\n\nAlso make sure that you have made orders in the past using the token in question" )
def current_price(self, update, context): #''' Checks current price of a token ''' DB = Database() message = update.message if self.correct_user(message, DB): try: quick_token_text = message.text.replace("/ticker", "").replace( " ", "").upper() if "USDT" in quick_token_text: token = quick_token_text else: token = quick_token_text + "USDT" link = self.ticker_link + token request = requests.get(link) data = request.json() message.reply_text(data['symbol'] + ": " + data['price']) #bot.reply_to(message, data['symbol'] + ": " + data['price']) except Exception as e: message.reply_text(self.general_error_message + "ex. /ticker btc or /ticker btcusdt")
def initial_chat_id_check(self): ''' Default chat_id is 0 ''' DB = Database() chat_id = DB.chat_id_check() if chat_id != 0: self.chat_id = chat_id
def show_account(self, update, context): DB = Database() message = update.message if self.correct_user(message, DB): info = self.client.get_account() message.reply_text(str(info))