def command_profitability(_, update): has_real_trader, has_simulated_trader, \ real_global_profitability, simulated_global_profitability, \ real_percent_profitability, simulated_percent_profitability, \ market_average_profitability = get_global_profitability() profitability_string = "" if has_real_trader: profitability_string = "{0}Global profitability : {1} ({2}%), market: {3}%{4}".format( REAL_TRADER_STR, PrettyPrinter.portfolio_profitability_pretty_print( real_global_profitability, None, get_reference_market()), PrettyPrinter.get_min_string_from_number( real_percent_profitability, 2), PrettyPrinter.get_min_string_from_number( market_average_profitability, 2), TelegramApp.EOL) if has_simulated_trader: profitability_string += "{0}Global profitability : {1} ({2}%), market: {3}%".format( SIMULATOR_TRADER_STR, PrettyPrinter.portfolio_profitability_pretty_print( simulated_global_profitability, None, get_reference_market()), PrettyPrinter.get_min_string_from_number( simulated_percent_profitability, 2), PrettyPrinter.get_min_string_from_number( market_average_profitability, 2)) if not profitability_string: profitability_string = TelegramApp.NO_TRADER_MESSAGE update.message.reply_text(profitability_string)
def get_command_profitability(markdown=False): _, b, c = PrettyPrinter.get_markets(markdown) has_real_trader, has_simulated_trader, \ real_global_profitability, simulated_global_profitability, \ real_percent_profitability, simulated_percent_profitability, \ real_no_trade_profitability, simulated_no_trade_profitability, \ market_average_profitability = get_global_profitability() profitability_string = "" if has_real_trader: real_profitability_pretty = PrettyPrinter.portfolio_profitability_pretty_print(real_global_profitability, None, get_reference_market()) profitability_string = \ f"{b}{REAL_TRADER_STR}{b}Global profitability : {c}{real_profitability_pretty}" \ f"({PrettyPrinter.get_min_string_from_number(real_percent_profitability, 2)}%){c}, market: {c}" \ f"{PrettyPrinter.get_min_string_from_number(market_average_profitability, 2)}%{c}, initial portfolio:" \ f" {c}{PrettyPrinter.get_min_string_from_number(real_no_trade_profitability, 2)}%{c}{EOL}" if has_simulated_trader: simulated_profitability_pretty = \ PrettyPrinter.portfolio_profitability_pretty_print(simulated_global_profitability, None, get_reference_market()) profitability_string += \ f"{b}{SIMULATOR_TRADER_STR}{b}Global profitability : {c}{simulated_profitability_pretty}" \ f"({PrettyPrinter.get_min_string_from_number(simulated_percent_profitability, 2)}%){c}, " \ f"market: {c}{PrettyPrinter.get_min_string_from_number(market_average_profitability, 2)}%{c}, " \ f"initial portfolio: {c}" \ f"{PrettyPrinter.get_min_string_from_number(simulated_no_trade_profitability, 2)}%{c}" if not profitability_string: profitability_string = NO_TRADER_MESSAGE return profitability_string
def get_command_profitability(): has_real_trader, has_simulated_trader, \ real_global_profitability, simulated_global_profitability, \ real_percent_profitability, simulated_percent_profitability, \ real_no_trade_profitability, simulated_no_trade_profitability, \ market_average_profitability = get_global_profitability() profitability_string = "" if has_real_trader: real_profitability_pretty = PrettyPrinter.portfolio_profitability_pretty_print( real_global_profitability, None, get_reference_market()) profitability_string = f"{REAL_TRADER_STR}Global profitability : {real_profitability_pretty} " \ f"({PrettyPrinter.get_min_string_from_number(real_percent_profitability, 2)}%), " \ f"market: {PrettyPrinter.get_min_string_from_number(market_average_profitability, 2)}%, " \ f"initial portfolio: {PrettyPrinter.get_min_string_from_number(real_no_trade_profitability, 2)}%{EOL}" if has_simulated_trader: simulated_profitability_pretty = \ PrettyPrinter.portfolio_profitability_pretty_print(simulated_global_profitability, None, get_reference_market()) profitability_string += f"{SIMULATOR_TRADER_STR}Global profitability : {simulated_profitability_pretty} " \ f"({PrettyPrinter.get_min_string_from_number(simulated_percent_profitability, 2)}%), " \ f"market: {PrettyPrinter.get_min_string_from_number(market_average_profitability, 2)}%, " \ f"initial portfolio: {PrettyPrinter.get_min_string_from_number(simulated_no_trade_profitability, 2)}%" if not profitability_string: profitability_string = NO_TRADER_MESSAGE return profitability_string
def command_profitability(_, update): real_global_profitability, simulated_global_profitability = get_global_profitability() update.message.reply_text("Real global profitability : {0}".format( PrettyPrinter.portfolio_profitability_pretty_print(real_global_profitability, None, get_reference_market()))) update.message.reply_text("Simulated global profitability : {0}".format( PrettyPrinter.portfolio_profitability_pretty_print(simulated_global_profitability, None, get_reference_market())))
def command_profitability(_, update): real_global_profitability, simulated_global_profitability = get_global_profitability( ) update.message.reply_text("Real global profitability : {0}".format( PrettyPrinter.portfolio_profitability_pretty_print( real_global_profitability, None, get_reference_market()))) update.message.reply_text( "Simulated global profitability : {0}".format( PrettyPrinter.portfolio_profitability_pretty_print( simulated_global_profitability, None, get_reference_market())))
def notify_order_close(self, order, cancel=False, cancel_linked_only=False): # Cancel linked orders for linked_order in order.get_linked_orders(): self.cancel_order(linked_order) # If need to cancel the order call the method and no need to update the portfolio (only availability) if cancel: order_closed = None orders_canceled = order.get_linked_orders() + [order] self.cancel_order(order) _, profitability_percent, profitability_diff = self.get_trades_manager( ).get_profitability_without_update() elif cancel_linked_only: order_closed = None orders_canceled = order.get_linked_orders() _, profitability_percent, profitability_diff = self.get_trades_manager( ).get_profitability_without_update() else: order_closed = order orders_canceled = order.get_linked_orders() # update portfolio with ended order with self.get_order_portfolio(order) as pf: pf.update_portfolio(order) # debug purpose profitability, profitability_percent, profitability_diff = self.get_trades_manager( ).get_profitability() self.logger.info("Current portfolio profitability : {0}".format( PrettyPrinter.portfolio_profitability_pretty_print( profitability, profitability_percent, self.get_trades_manager().get_reference()))) # add to trade history self.trades_manager.add_new_trade_in_history( Trade(self.exchange, order)) # remove order to open_orders self.order_manager.remove_order_from_list(order) profitability_activated = order_closed is not None # update current order list with exchange if not self.simulate: self.update_open_orders(order.get_order_symbol()) # notification order.get_order_notifier().end(order_closed, orders_canceled, order.get_profitability(), profitability_percent, profitability_diff, profitability_activated)
def notify_order_close(self, order, cancel=False): # Cancel linked orders for linked_order in order.get_linked_orders(): self.cancel_order(linked_order) # If need to cancel the order call the method and no need to update the portfolio (only availability) if cancel: order_closed = None orders_canceled = order.get_linked_orders() + [order] self.cancel_order(order) _, profitability_percent, profitability_diff = self.get_trades_manager().get_profitability_without_update() with self.portfolio as pf: # ensure availability reset pf.reset_portfolio_available() else: order_closed = order orders_canceled = order.get_linked_orders() # update portfolio with ended order with self.portfolio as pf: pf.update_portfolio(order) # debug purpose profitability, profitability_percent, profitability_diff = self.get_trades_manager().get_profitability() self.logger.info("Current portfolio profitability : {0}".format( PrettyPrinter.portfolio_profitability_pretty_print(profitability, profitability_percent, self.get_trades_manager().get_reference()))) # add to trade history self.trades_manager.add_new_trade_in_history(Trade(self.exchange, order)) # remove order to open_orders self.order_manager.remove_order_from_list(order) if order_closed is not None: profitability_activated = True else: profitability_activated = False # update current order list with exchange if not self.simulate: self.update_open_orders() # notification order.get_order_notifier().end(order_closed, orders_canceled, order.get_profitability(), profitability_percent, profitability_diff, profitability_activated)