Exemple #1
0
    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
Exemple #2
0
    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
Exemple #3
0
    def get_command_open_orders():
        has_real_trader, has_simulated_trader = has_real_and_or_simulated_traders(
        )
        portfolio_real_open_orders, portfolio_simulated_open_orders = get_open_orders(
        )

        orders_string = ""
        if has_real_trader:
            orders_string += f"{REAL_TRADER_STR}Open orders :{EOL}"
            for orders in portfolio_real_open_orders:
                for order in orders:
                    orders_string += PrettyPrinter.open_order_pretty_printer(
                        order) + EOL

        if has_simulated_trader:
            orders_string += EOL + f"{SIMULATOR_TRADER_STR}Open orders :{EOL}"
            for orders in portfolio_simulated_open_orders:
                for order in orders:
                    orders_string += PrettyPrinter.open_order_pretty_printer(
                        order) + EOL

        if not orders_string:
            orders_string = NO_TRADER_MESSAGE

        return orders_string
Exemple #4
0
    def command_portfolio(_, update):
        has_real_trader, has_simulated_trader, \
            portfolio_real_current_value, portfolio_simulated_current_value = get_portfolio_current_value()
        reference_market = get_reference_market()
        real_global_portfolio, simulated_global_portfolio = get_global_portfolio_currencies_amounts(
        )

        portfolios_string = ""
        if has_real_trader:
            portfolios_string += "{0}Portfolio value : {1} {2}{3}".format(
                REAL_TRADER_STR,
                PrettyPrinter.get_min_string_from_number(
                    portfolio_real_current_value), reference_market,
                TelegramApp.EOL)
            portfolios_string += "{0}Portfolio : {2}{1}{2}{2}".format(
                REAL_TRADER_STR,
                PrettyPrinter.global_portfolio_pretty_print(
                    real_global_portfolio), TelegramApp.EOL)

        if has_simulated_trader:
            portfolios_string += "{0}Portfolio value : {1} {2}{3}".format(
                SIMULATOR_TRADER_STR,
                PrettyPrinter.get_min_string_from_number(
                    portfolio_simulated_current_value), reference_market,
                TelegramApp.EOL)
            portfolios_string += "{0}Portfolio : {2}{1}".format(
                SIMULATOR_TRADER_STR,
                PrettyPrinter.global_portfolio_pretty_print(
                    simulated_global_portfolio), TelegramApp.EOL)

        if not portfolios_string:
            portfolios_string = TelegramApp.NO_TRADER_MESSAGE
        update.message.reply_text(portfolios_string)
Exemple #5
0
    def command_trades_history(_, update):
        has_real_trader, has_simulated_trader = has_real_and_or_simulated_traders(
        )
        real_trades_history, simulated_trades_history = get_trades_history()

        trades_history_string = ""
        if has_real_trader:
            trades_history_string += "{0}Trades :{1}".format(
                REAL_TRADER_STR, TelegramApp.EOL)
            for trades in real_trades_history:
                for trade in trades:
                    trades_history_string += PrettyPrinter.trade_pretty_printer(
                        trade) + TelegramApp.EOL

        if has_simulated_trader:
            for trades in simulated_trades_history:
                trades_history_string += TelegramApp.EOL + "{0}Trades :{1}".format(
                    SIMULATOR_TRADER_STR, TelegramApp.EOL)
                for trade in trades:
                    trades_history_string += PrettyPrinter.trade_pretty_printer(
                        trade) + TelegramApp.EOL

        if not trades_history_string:
            trades_history_string = TelegramApp.NO_TRADER_MESSAGE

        update.message.reply_text(trades_history_string)
Exemple #6
0
    def command_open_orders(_, update):
        has_real_trader, has_simulated_trader = has_real_and_or_simulated_traders(
        )
        portfolio_real_open_orders, portfolio_simulated_open_orders = get_open_orders(
        )

        orders_string = ""
        if has_real_trader:
            orders_string += "{0}Open orders :{1}".format(
                REAL_TRADER_STR, TelegramApp.EOL)
            for orders in portfolio_real_open_orders:
                for order in orders:
                    orders_string += PrettyPrinter.open_order_pretty_printer(
                        order) + TelegramApp.EOL

        if has_simulated_trader:
            orders_string += TelegramApp.EOL + "{0}Open orders :{1}".format(
                SIMULATOR_TRADER_STR, TelegramApp.EOL)
            for orders in portfolio_simulated_open_orders:
                for order in orders:
                    orders_string += PrettyPrinter.open_order_pretty_printer(
                        order) + TelegramApp.EOL

        if not orders_string:
            orders_string = TelegramApp.NO_TRADER_MESSAGE

        update.message.reply_text(orders_string)
Exemple #7
0
 def _print_open_orders(open_orders, trader_str, markdown=False):
     _, b, c = PrettyPrinter.get_markets(markdown)
     orders_string = f"{b}{trader_str}{b}{c}Open orders :{c}{EOL}"
     for orders in open_orders:
         if orders:
             for order in orders:
                 orders_string += PrettyPrinter.open_order_pretty_printer(order, markdown=markdown) + EOL
         else:
             orders_string += f"{c}No open order yet.{c}"
     return orders_string
Exemple #8
0
 def _print_portfolio(current_val, ref_market, portfolio, trader_str, markdown=False):
     _, b, c = PrettyPrinter.get_markets(markdown)
     portfolios_string = f"{b}{trader_str}{b}Portfolio value : " \
         f"{b}{PrettyPrinter.get_min_string_from_number(current_val)} {ref_market}{b}" \
         f"{EOL}"
     portfolio_str = PrettyPrinter.global_portfolio_pretty_print(portfolio, markdown=markdown)
     if not portfolio_str:
         portfolio_str = "Nothing there."
     portfolios_string += f"{b}{trader_str}{b}Portfolio : {EOL}{c}{portfolio_str}{c}"
     return portfolios_string
Exemple #9
0
    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())))
Exemple #10
0
    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())))
Exemple #11
0
    def command_portfolio(_, update):
        portfolio_real_current_value, portfolio_simulated_current_value = get_portfolio_current_value()
        reference_market = get_reference_market()
        real_global_portfolio, simulated_global_portfolio = get_global_portfolio_currencies_amounts()

        update.message.reply_text("Portfolio real value : {0} {1}".format(portfolio_real_current_value,
                                                                          reference_market))
        update.message.reply_text("Global real portfolio : \n{0}"
                                  .format(PrettyPrinter.global_portfolio_pretty_print(real_global_portfolio)))

        update.message.reply_text("Portfolio simulated value : {0} {1}".format(portfolio_simulated_current_value,
                                                                               reference_market))
        update.message.reply_text("Global simulated portfolio : \n{0}"
                                  .format(PrettyPrinter.global_portfolio_pretty_print(simulated_global_portfolio)))
Exemple #12
0
    def notify_state_changed(self, final_eval, crypto_currency_evaluator, symbol, trader, result, matrix):
        if self.gmail_notification_available():
            profitability, profitability_percent, _ = trader.get_trades_manager().get_profitability()

            self.gmail_notification_factory(
                "CRYPTO BOT ALERT : {0} / {1}".format(crypto_currency_evaluator.crypto_currency,
                                                      result),
                "CRYPTO BOT ALERT : {0} / {1} \n {2} \n Current portfolio "
                "profitability : {3} "
                "{4} ({5}%)".format(
                    crypto_currency_evaluator.crypto_currency,
                    result,
                    pprint.pformat(matrix),
                    round(profitability, 2),
                    TradesManager.get_reference_market(self.config),
                    round(profitability_percent, 2)))

        alert_content = PrettyPrinter.cryptocurrency_alert(
                    crypto_currency_evaluator.crypto_currency,
                    symbol,
                    result,
                    final_eval)

        if self.twitter_notification_available():
            self.tweet_instance = self.twitter_notification_factory(alert_content)

        if self.telegram_notification_available():
            self.telegram_notification_factory(alert_content)

        return self
Exemple #13
0
    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)
Exemple #14
0
    def notify_create(self, evaluator_notification, orders):
        if orders:
            content = orders[0].trader.trader_type_str
            if evaluator_notification is not None:
                self.evaluator_notification = evaluator_notification

            title = "Order(s) creation "
            content += title
            for order in orders:
                content += "\n- {0}".format(
                    PrettyPrinter.open_order_pretty_printer(order))

            if self.twitter_notification_available(CONFIG_NOTIFICATION_TRADES) \
                    and self.evaluator_notification is not None \
                    and self.evaluator_notification.get_tweet_instance() is not None:
                tweet_instance = self.evaluator_notification.get_tweet_instance(
                )
                self.twitter_response_factory(tweet_instance, content)

            if self.telegram_notification_available(
                    CONFIG_NOTIFICATION_TRADES):
                self.telegram_notification_factory(content)

            if self.web_interface_notification_available(
                    CONFIG_NOTIFICATION_TRADES):
                self.web_interface_notification_factory(
                    InterfaceLevel.INFO, title, content)
Exemple #15
0
    def notify_state_changed(self, final_eval, crypto_currency_evaluator,
                             symbol, trader, result, matrix):
        if self.gmail_notification_available():
            profitability, profitability_percent, _ = trader.get_trades_manager(
            ).get_profitability()

            self.gmail_notification_factory(
                "CRYPTO BOT ALERT : {0} / {1}".format(
                    crypto_currency_evaluator.crypto_currency, result),
                "CRYPTO BOT ALERT : {0} / {1} \n {2} \n Current portfolio "
                "profitability : {3} "
                "{4} ({5}%)".format(
                    crypto_currency_evaluator.crypto_currency, result,
                    pprint.pformat(matrix), round(profitability, 2),
                    TradesManager.get_reference_market(self.config),
                    round(profitability_percent, 2)))

        alert_content = PrettyPrinter.cryptocurrency_alert(
            crypto_currency_evaluator.crypto_currency, symbol, result,
            final_eval)

        if self.twitter_notification_available():
            self.tweet_instance = self.twitter_notification_factory(
                alert_content)

        if self.telegram_notification_available():
            self.telegram_notification_factory(alert_content)

        return self
Exemple #16
0
    def get_command_configuration(markdown=False):
        _, b, c = PrettyPrinter.get_markets(markdown)
        message = f"{b}My configuration:{b}{EOL}{EOL}"

        message += f"{b}Traders: {b}{EOL}"
        has_real_trader, has_simulated_trader = has_real_and_or_simulated_traders()
        if has_real_trader:
            message += f"{c}- Real trader{c}{EOL}"
        if has_simulated_trader:
            message += f"{c}- Simulated trader{c}{EOL}"

        message += f"{EOL}{b}Exchanges:{b}{EOL}"
        for exchange in get_bot().get_exchanges_list().values():
            message += f"{c}- {exchange.get_name()}{c}{EOL}"

        message += f"{EOL}{b}Evaluators:{b}{EOL}"
        first_evaluator = next(iter(get_bot().get_symbols_tasks_manager().values())).get_evaluator()
        evaluators = copy.copy(first_evaluator.get_social_eval_list())
        evaluators += first_evaluator.get_ta_eval_list()
        evaluators += first_evaluator.get_real_time_eval_list()
        for evaluator in evaluators:
            message += f"{c}- {evaluator.get_name()}{c}{EOL}"

        first_symbol_evaluator = next(iter(get_bot().get_symbol_evaluator_list().values()))
        first_exchange = next(iter(get_bot().get_exchanges_list().values()))
        message += f"{EOL}{b}Strategies:{b}{EOL}"
        for strategy in first_symbol_evaluator.get_strategies_eval_list(first_exchange):
            message += f"{c}- {strategy.get_name()}{c}{EOL}"

        message += f"{EOL}{b}Trading mode:{b}{EOL}"
        message += f"{c}- {next(iter(get_bot().get_exchange_trading_modes().values())).get_name()}{c}"

        return message
    def notify_alert(self, final_eval, crypto_currency_evaluator, symbol, trader, result, matrix):
        title = f"OCTOBOT ALERT : {crypto_currency_evaluator.crypto_currency} / {result}"

        if self.gmail_notification_available(CONFIG_NOTIFICATION_PRICE_ALERTS):
            profitability, profitability_percent, _, _ = trader.get_trades_manager().get_profitability()

            self.gmail_notification_factory(
                title,
                "OCTOBOT ALERT : {0} / {1} \n {2} \n Current portfolio "
                "profitability : {3} "
                "{4} ({5}%)".format(
                    crypto_currency_evaluator.crypto_currency,
                    result,
                    pprint.pformat(matrix),
                    round(profitability, 2),
                    TradesManager.get_reference_market(self.config),
                    round(profitability_percent, 2)))

        alert_content = PrettyPrinter.cryptocurrency_alert(
            crypto_currency_evaluator.crypto_currency,
            symbol,
            result,
            final_eval)

        self.tweet_instance = self.send_twitter_notification_if_necessary(alert_content,
                                                                          CONFIG_NOTIFICATION_PRICE_ALERTS)

        self.send_telegram_notification_if_necessary(alert_content, CONFIG_NOTIFICATION_PRICE_ALERTS)

        self.send_web_notification_if_necessary(InterfaceLevel.INFO, title, alert_content,
                                                CONFIG_NOTIFICATION_PRICE_ALERTS)

        return self
    async def notify_alert(self, final_eval, crypto_currency_evaluator, symbol,
                           trader, result, matrix):
        title = f"OCTOBOT ALERT : {crypto_currency_evaluator.crypto_currency} / {result}"
        try:

            alert_content, alert_content_markdown = PrettyPrinter.cryptocurrency_alert(
                crypto_currency_evaluator.crypto_currency, symbol, result,
                final_eval)

            self.tweet_instance = await self.send_twitter_notification_if_necessary(
                alert_content, CONFIG_NOTIFICATION_PRICE_ALERTS)

            await self.send_telegram_notification_if_necessary(
                alert_content_markdown,
                CONFIG_NOTIFICATION_PRICE_ALERTS,
                markdown=True)

            await self.send_web_notification_if_necessary(
                InterfaceLevel.INFO, title, alert_content,
                CONFIG_NOTIFICATION_PRICE_ALERTS)
        except Exception as e:
            self.logger.error(f"Error when sending alert [{title}] error: {e}")
            self.logger.exception(e)

        return self
Exemple #19
0
    def notify_end(self,
                   order_filled,
                   orders_canceled,
                   trade_profitability,
                   portfolio_profitability,
                   portfolio_diff,
                   profitability=False):

        title = "Order status updated"
        content = ""

        if order_filled is not None:
            content += "\n{0}Order(s) filled : \n- {1}".format(
                order_filled.trader.trader_type_str,
                PrettyPrinter.open_order_pretty_printer(order_filled))

        if orders_canceled is not None and len(orders_canceled) > 0:
            content += "\n{0}Order(s) canceled :".format(
                orders_canceled[0].trader.trader_type_str)
            for order in orders_canceled:
                content += "\n- {0}".format(
                    PrettyPrinter.open_order_pretty_printer(order))

        if trade_profitability is not None and profitability:
            content += "\n\nTrade profitability : {0}{1}%".format(
                "+" if trade_profitability >= 0 else "",
                round(trade_profitability * 100, 7))

        if portfolio_profitability is not None and profitability:
            content += "\nGlobal Portfolio profitability : {0}% {1}{2}%".format(
                round(portfolio_profitability, 5),
                "+" if portfolio_diff >= 0 else "", round(portfolio_diff, 7))

        if self.twitter_notification_available(CONFIG_NOTIFICATION_TRADES) \
                and self.evaluator_notification is not None \
                and self.evaluator_notification.get_tweet_instance() is not None:
            tweet_instance = self.evaluator_notification.get_tweet_instance()

            self.twitter_response_factory(tweet_instance, content)

        if self.telegram_notification_available(CONFIG_NOTIFICATION_TRADES):
            self.telegram_notification_factory(content)

        if self.web_interface_notification_available(
                CONFIG_NOTIFICATION_TRADES):
            self.web_interface_notification_factory(InterfaceLevel.INFO, title,
                                                    content)
Exemple #20
0
 def print_trades_history(self):
     trader = self.get_trader()
     trades_history = trader.get_trades_manager().get_trade_history()
     trades_history_string = ""
     for trade in trades_history:
         trades_history_string += PrettyPrinter.trade_pretty_printer(
             trade) + "\n"
     self.logger.info(trades_history_string.strip())
Exemple #21
0
    def command_open_orders(_, update):
        portfolio_real_open_orders, portfolio_simulated_open_orders = get_open_orders()

        portfolio_real_current_value_string = TelegramApp.EOL
        for orders in portfolio_real_open_orders:
            for order in orders:
                portfolio_real_current_value_string += PrettyPrinter.open_order_pretty_printer(order) + \
                                                       TelegramApp.EOL

        portfolio_simulated_current_value_string = TelegramApp.EOL
        for orders in portfolio_simulated_open_orders:
            for order in orders:
                portfolio_simulated_current_value_string += PrettyPrinter.open_order_pretty_printer(order) + \
                                                            TelegramApp.EOL

        update.message.reply_text("Real open orders : {0}".format(portfolio_real_current_value_string))
        update.message.reply_text("Simulated open orders : {0}".format(portfolio_simulated_current_value_string))
Exemple #22
0
    def command_portfolio(_, update):
        portfolio_real_current_value, portfolio_simulated_current_value = get_portfolio_current_value(
        )
        reference_market = get_reference_market()
        real_global_portfolio, simulated_global_portfolio = get_global_portfolio_currencies_amounts(
        )

        update.message.reply_text("Portfolio real value : {0} {1}".format(
            portfolio_real_current_value, reference_market))
        update.message.reply_text("Global real portfolio : \n{0}".format(
            PrettyPrinter.global_portfolio_pretty_print(
                real_global_portfolio)))

        update.message.reply_text("Portfolio simulated value : {0} {1}".format(
            portfolio_simulated_current_value, reference_market))
        update.message.reply_text("Global simulated portfolio : \n{0}".format(
            PrettyPrinter.global_portfolio_pretty_print(
                simulated_global_portfolio)))
Exemple #23
0
 def _print_trades(trades_history, trader_str, markdown=False):
     _, b, c = PrettyPrinter.get_markets(markdown)
     trades_history_string = f"{b}{trader_str}{b}{c}Trades :{EOL}{c}"
     if trades_history:
         for trade in trades_history:
             trades_history_string += f"{PrettyPrinter.trade_pretty_printer(trade, markdown=markdown)}{EOL}"
     else:
         trades_history_string += f"{c}No trade yet.{c}"
     return trades_history_string
Exemple #24
0
    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)
Exemple #25
0
    def command_open_orders(_, update):
        portfolio_real_open_orders, portfolio_simulated_open_orders = get_open_orders(
        )

        portfolio_real_current_value_string = TelegramApp.EOL
        for orders in portfolio_real_open_orders:
            for order in orders:
                portfolio_real_current_value_string += PrettyPrinter.open_order_pretty_printer(order) + \
                                                       TelegramApp.EOL

        portfolio_simulated_current_value_string = TelegramApp.EOL
        for orders in portfolio_simulated_open_orders:
            for order in orders:
                portfolio_simulated_current_value_string += PrettyPrinter.open_order_pretty_printer(order) + \
                                                            TelegramApp.EOL

        update.message.reply_text("Real open orders : {0}".format(
            portfolio_real_current_value_string))
        update.message.reply_text("Simulated open orders : {0}".format(
            portfolio_simulated_current_value_string))
Exemple #26
0
def profitability():
    profitability_digits = 4
    has_real_trader, has_simulated_trader, \
        _, _, \
        real_percent_profitability, simulated_percent_profitability, \
        real_no_trade_profitability, simulated_no_trade_profitability, \
        market_average_profitability = get_global_profitability()
    profitability_data = \
        {"market_average_profitability":
            PrettyPrinter.round_with_decimal_count(market_average_profitability, profitability_digits)}
    if has_real_trader:
        profitability_data["bot_real_profitability"] = \
            PrettyPrinter.round_with_decimal_count(real_percent_profitability, profitability_digits)
        profitability_data["real_no_trade_profitability"] = \
            PrettyPrinter.round_with_decimal_count(real_no_trade_profitability, profitability_digits)
    if has_simulated_trader:
        profitability_data["bot_simulated_profitability"] = \
            PrettyPrinter.round_with_decimal_count(simulated_percent_profitability, profitability_digits)
        profitability_data["simulated_no_trade_profitability"] = \
            PrettyPrinter.round_with_decimal_count(simulated_no_trade_profitability, profitability_digits)
    return jsonify(profitability_data)
Exemple #27
0
 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)
Exemple #28
0
    def notify_end(self,
                   order_filled,
                   orders_canceled,
                   trade_profitability,
                   portfolio_profitability,
                   portfolio_diff,
                   profitability=False):

        content = ""

        if order_filled is not None:
            content += "\nOrder(s) filled : \n- {0}".format(
                PrettyPrinter.open_order_pretty_printer(order_filled))

        if orders_canceled is not None and len(orders_canceled) > 0:
            content += "\nOrder(s) canceled :"
            for order in orders_canceled:
                content += "\n- {0}".format(
                    PrettyPrinter.open_order_pretty_printer(order))

        if trade_profitability is not None and profitability:
            content += "\n\nTrade profitability : {0}{1}%".format(
                "+" if trade_profitability >= 0 else "",
                round(trade_profitability * 100, 7))

        if portfolio_profitability is not None and profitability:
            content += "\nGlobal Portfolio profitability : {0}% {1}{2}%".format(
                round(portfolio_profitability, 5),
                "+" if portfolio_diff >= 0 else "", round(portfolio_diff, 7))

        if self.twitter_notification_available() \
                and self.evaluator_notification is not None \
                and self.evaluator_notification.get_tweet_instance() is not None:
            tweet_instance = self.evaluator_notification.get_tweet_instance()

            self.twitter_response_factory(tweet_instance, content)

        if self.telegram_notification_available():
            self.telegram_notification_factory(content)
Exemple #29
0
 def get_command_fees(markdown=False):
     _, b, _ = PrettyPrinter.get_markets(markdown)
     real_trader_fees, simulated_trader_fees = get_total_paid_fees()
     result_str = ""
     if real_trader_fees is not None:
         result_str = f"{b}{REAL_TRADER_STR}{b}{PAID_FEES_STR}: " \
             f"{PrettyPrinter.pretty_print_dict(real_trader_fees, markdown=markdown)}"
     if simulated_trader_fees is not None:
         result_str = f"{result_str}\n{b}{SIMULATOR_TRADER_STR}{b}{PAID_FEES_STR}: " \
             f"{PrettyPrinter.pretty_print_dict(simulated_trader_fees, markdown=markdown)}"
     if not result_str:
         result_str = NO_TRADER_MESSAGE
     return result_str
Exemple #30
0
    def get_command_market_status(markdown=False):
        _, b, c = PrettyPrinter.get_markets(markdown)
        message = f"{b}My cryptocurrencies evaluations are:{b} {EOL}{EOL}"
        at_least_one_currency = False
        for currency_pair, currency_info in get_currencies_with_status().items():
            at_least_one_currency = True
            message += f"{c}{currency_pair}:{c}{EOL}"
            for exchange_name, evaluation in currency_info.items():
                message += f"{c}- {exchange_name}: {evaluation[0]}{c}{EOL}"
        if not at_least_one_currency:
            message += f"{c}{NO_CURRENCIES_MESSAGE}{c}{EOL}"
        message += f"{EOL}{c}My current risk is: {get_risk()}{c}"

        return message
Exemple #31
0
    def notify_end(self,
                   order_filled,
                   orders_canceled,
                   trade_profitability,
                   portfolio_profitability,
                   portfolio_diff,
                   profitability=False):

        content = ""

        if order_filled is not None:
            content += "\nOrder(s) filled : \n- {0}".format(PrettyPrinter.open_order_pretty_printer(order_filled))

        if orders_canceled is not None and len(orders_canceled) > 0:
            content += "\nOrder(s) canceled :"
            for order in orders_canceled:
                content += "\n- {0}".format(PrettyPrinter.open_order_pretty_printer(order))

        if trade_profitability is not None and profitability:
            content += "\n\nTrade profitability : {0}{1}%".format("+" if trade_profitability >= 0 else "",
                                                                  round(trade_profitability * 100, 7))

        if portfolio_profitability is not None and profitability:
            content += "\nGlobal Portfolio profitability : {0}% {1}{2}%".format(round(portfolio_profitability, 5),
                                                                                "+" if portfolio_diff >= 0 else "",
                                                                                round(portfolio_diff, 7))

        if self.twitter_notification_available() \
                and self.evaluator_notification is not None \
                and self.evaluator_notification.get_tweet_instance() is not None:
            tweet_instance = self.evaluator_notification.get_tweet_instance()

            self.twitter_response_factory(tweet_instance, content)

        if self.telegram_notification_available():
            self.telegram_notification_factory(content)
Exemple #32
0
    def get_command_trades_history():
        has_real_trader, has_simulated_trader = has_real_and_or_simulated_traders(
        )
        real_trades_history, simulated_trades_history = get_trades_history()

        trades_history_string = ""
        if has_real_trader:
            trades_history_string += f"{REAL_TRADER_STR}Trades :{EOL}"
            for trades in real_trades_history:
                for trade in trades:
                    trades_history_string += PrettyPrinter.trade_pretty_printer(
                        trade) + EOL

        if has_simulated_trader:
            for trades in simulated_trades_history:
                trades_history_string += EOL + f"{SIMULATOR_TRADER_STR}Trades :{EOL}"
                for trade in trades:
                    trades_history_string += PrettyPrinter.trade_pretty_printer(
                        trade) + EOL

        if not trades_history_string:
            trades_history_string = NO_TRADER_MESSAGE

        return trades_history_string
Exemple #33
0
    def notify_create(self, evaluator_notification, orders):
        if evaluator_notification is not None:
            self.evaluator_notification = evaluator_notification

        content = "Order(s) creation "
        for order in orders:
            content += "\n- {0}".format(PrettyPrinter.open_order_pretty_printer(order))

        if self.twitter_notification_available() \
                and self.evaluator_notification is not None \
                and self.evaluator_notification.get_tweet_instance() is not None:
            tweet_instance = self.evaluator_notification.get_tweet_instance()
            self.twitter_response_factory(tweet_instance, content)

        if self.telegram_notification_available():
            self.telegram_notification_factory(content)
Exemple #34
0
    def notify_create(self, evaluator_notification, orders):
        if evaluator_notification is not None:
            self.evaluator_notification = evaluator_notification

        content = "Order(s) creation "
        for order in orders:
            content += "\n- {0}".format(
                PrettyPrinter.open_order_pretty_printer(order))

        if self.twitter_notification_available() \
                and self.evaluator_notification is not None \
                and self.evaluator_notification.get_tweet_instance() is not None:
            tweet_instance = self.evaluator_notification.get_tweet_instance()
            self.twitter_response_factory(tweet_instance, content)

        if self.telegram_notification_available():
            self.telegram_notification_factory(content)
Exemple #35
0
    def get_command_open_orders(markdown=False):
        _, b, c = PrettyPrinter.get_markets(markdown)
        has_real_trader, has_simulated_trader = has_real_and_or_simulated_traders()
        portfolio_real_open_orders, portfolio_simulated_open_orders = get_open_orders()

        orders_string = ""
        if has_real_trader:
            orders_string += InterfaceBot._print_open_orders(portfolio_real_open_orders, REAL_TRADER_STR, markdown)

        if has_simulated_trader:
            orders_string += f"{EOL}" \
                f"{InterfaceBot._print_open_orders(portfolio_simulated_open_orders, SIMULATOR_TRADER_STR, markdown)}"

        if not orders_string:
            orders_string = NO_TRADER_MESSAGE

        return orders_string
Exemple #36
0
    def get_command_portfolio(markdown=False):
        _, b, c = PrettyPrinter.get_markets(markdown)
        has_real_trader, has_simulated_trader, \
          portfolio_real_current_value, portfolio_simulated_current_value = get_portfolio_current_value()
        reference_market = get_reference_market()
        real_global_portfolio, simulated_global_portfolio = get_global_portfolio_currencies_amounts()

        portfolios_string = ""
        if has_real_trader:
            portfolios_string += InterfaceBot._print_portfolio(portfolio_real_current_value, reference_market,
                                                               real_global_portfolio, REAL_TRADER_STR, markdown)

        if has_simulated_trader:
            portfolio_str = InterfaceBot._print_portfolio(portfolio_simulated_current_value, reference_market,
                                                          simulated_global_portfolio, SIMULATOR_TRADER_STR, markdown)
            portfolios_string += f"{EOL}{portfolio_str}"

        if not portfolios_string:
            portfolios_string = NO_TRADER_MESSAGE

        return portfolios_string
    async def notify_alert(self, final_eval, crypto_currency_evaluator, symbol,
                           trader, result, matrix):
        title = f"OCTOBOT ALERT : {crypto_currency_evaluator.crypto_currency} / {result}"

        alert_content = PrettyPrinter.cryptocurrency_alert(
            crypto_currency_evaluator.crypto_currency, symbol, result,
            final_eval)

        self.tweet_instance = await self.send_twitter_notification_if_necessary(
            alert_content, CONFIG_NOTIFICATION_PRICE_ALERTS)

        await self.send_telegram_notification_if_necessary(
            alert_content, CONFIG_NOTIFICATION_PRICE_ALERTS)

        await self.send_web_notification_if_necessary(
            InterfaceLevel.INFO, title, alert_content,
            CONFIG_NOTIFICATION_PRICE_ALERTS)

        await self.send_notifier_notification_if_necessary(
            alert_content, CONFIG_NOTIFICATION_PRICE_ALERTS)

        return self