async def _handle_order_notification(self, dict_order, linked_notification, order_identifier,
                                         exchange_manager, exchange):
        notification = None
        order_status = parse_order_status(dict_order)

        if order_status is OrderStatus.OPEN:
            notification = OrderCreationNotification(linked_notification, dict_order, exchange)
            # update last notification for this order
            self.previous_notifications_by_identifier[order_identifier] = notification
        else:
            is_simulated = is_trader_simulated(exchange_manager)
            if order_status is OrderStatus.CANCELED or \
                    (order_status is OrderStatus.CLOSED
                     and dict_order[ExchangeConstantsOrderColumns.FILLED.value] == 0):
                notification = OrderEndNotification(linked_notification, None, exchange, [dict_order],
                                                    None, None, None, False, is_simulated)
            elif order_status in (OrderStatus.CLOSED, OrderStatus.FILLED):
                _,  profitability_percent, profitability_diff, _,  _ = get_profitability_stats(exchange_manager)
                order_profitability = get_order_profitability(exchange_manager,
                                                              dict_order[ExchangeConstantsOrderColumns.ID.value])
                notification = OrderEndNotification(linked_notification, dict_order, exchange, [], order_profitability,
                                                    profitability_percent, profitability_diff, True, is_simulated)
            # remove order from previous_notifications_by_identifier: no more notification from it to be received
            if order_identifier in self.previous_notifications_by_identifier:
                self.previous_notifications_by_identifier.pop(order_identifier)
        await self._notification_callback(notification)
Beispiel #2
0
def has_real_and_or_simulated_traders():
    has_real_trader = False
    has_simulated_trader = False
    exchange_managers = get_exchange_managers()
    for exchange_manager in exchange_managers:
        if is_trader_simulated(exchange_manager):
            has_simulated_trader = True
        else:
            has_real_trader = True
    return has_real_trader, has_simulated_trader
def _get_portfolios():
    simulated_portfolios = []
    real_portfolios = []

    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):
            if is_trader_simulated(exchange_manager):
                simulated_portfolios.append(get_portfolio(exchange_manager))
            else:
                real_portfolios.append(get_portfolio(exchange_manager))

    return real_portfolios, simulated_portfolios
def get_all_open_orders():
    simulated_open_orders = []
    real_open_orders = []

    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):
            if is_trader_simulated(exchange_manager):
                simulated_open_orders += get_open_orders(exchange_manager)
            else:
                real_open_orders += get_open_orders(exchange_manager)

    return real_open_orders, simulated_open_orders
Beispiel #5
0
def get_total_paid_fees(bot=None):
    real_trader_fees = None
    simulated_trader_fees = None

    for exchange_manager in get_exchange_managers(bot):
        if is_trader_enabled(exchange_manager):
            if is_trader_simulated(exchange_manager):
                simulated_trader_fees = _merge_trader_fees(
                    simulated_trader_fees, exchange_manager)
            else:
                real_trader_fees = _merge_trader_fees(real_trader_fees,
                                                      exchange_manager)

    return real_trader_fees, simulated_trader_fees
def get_portfolio_holdings():
    real_currency_portfolio = {}
    simulated_currency_portfolio = {}

    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):

            trader_currencies_values = run_in_bot_main_loop(
                get_current_holdings_values(exchange_manager))
            if is_trader_simulated(exchange_manager):
                _merge_portfolio_values(simulated_currency_portfolio,
                                        trader_currencies_values)
            else:
                _merge_portfolio_values(real_currency_portfolio,
                                        trader_currencies_values)

    return real_currency_portfolio, simulated_currency_portfolio
Beispiel #7
0
def get_trades_history(bot_api=None,
                       symbol=None,
                       independent_backtesting=None,
                       since=None,
                       as_dict=False):
    simulated_trades_history = []
    real_trades_history = []

    for exchange_manager in get_exchange_managers(
            bot_api=bot_api, independent_backtesting=independent_backtesting):
        if is_trader_enabled(exchange_manager):
            if is_trader_simulated(exchange_manager):
                simulated_trades_history += get_trade_history(
                    exchange_manager, symbol, since, as_dict)
            else:
                real_trades_history += get_trade_history(
                    exchange_manager, symbol, since, as_dict)

    return real_trades_history, simulated_trades_history
def get_global_profitability():
    simulated_global_profitability = 0
    real_global_profitability = 0
    simulated_no_trade_profitability = 0
    real_no_trade_profitability = 0
    simulated_full_origin_value = 0
    real_full_origin_value = 0
    market_average_profitability = None
    has_real_trader = False
    has_simulated_trader = False

    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):

            current_value, _, _, market_average_profitability, initial_portfolio_current_profitability = \
                get_profitability_stats(exchange_manager)

            if is_trader_simulated(exchange_manager):
                simulated_full_origin_value += get_origin_portfolio_value(
                    exchange_manager)
                simulated_global_profitability += current_value
                simulated_no_trade_profitability += initial_portfolio_current_profitability
                has_simulated_trader = True
            else:
                real_full_origin_value += get_origin_portfolio_value(
                    exchange_manager)
                real_global_profitability += current_value
                real_no_trade_profitability += initial_portfolio_current_profitability
                has_real_trader = True

    simulated_percent_profitability = simulated_global_profitability * 100 / simulated_full_origin_value \
        if simulated_full_origin_value > 0 else 0
    real_percent_profitability = real_global_profitability * 100 / real_full_origin_value \
        if real_full_origin_value > 0 else 0

    return 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
def get_portfolio_current_value():
    simulated_value = 0
    real_value = 0
    has_real_trader = False
    has_simulated_trader = False

    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):

            current_value = get_current_portfolio_value(exchange_manager)

            # current_value might be 0 if no trades have been made / canceled => use origin value
            if current_value == 0:
                current_value = get_origin_portfolio_value(exchange_manager)

            if is_trader_simulated(exchange_manager):
                simulated_value += current_value
                has_simulated_trader = True
            else:
                real_value += current_value
                has_real_trader = True

    return has_real_trader, has_simulated_trader, real_value, simulated_value