コード例 #1
0
def sell_all(currency):
    orders = []
    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):
            orders += run_in_bot_main_loop(
                sell_currency_for_reference_market(exchange_manager, currency))
    return orders
コード例 #2
0
def trigger_portfolios_refresh():
    at_least_one = False
    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):
            at_least_one = True
            run_in_bot_main_loop(
                refresh_real_trader_portfolio(exchange_manager))

    if not at_least_one:
        raise RuntimeError("no real trader to update.")
コード例 #3
0
def cancel_all_open_orders(currency=None):
    for exchange_manager in get_exchange_managers():
        if is_trader_enabled(exchange_manager):
            if currency is None:
                run_in_bot_main_loop(
                    api_cancel_all_open_orders(exchange_manager))
            else:
                run_in_bot_main_loop(
                    cancel_all_open_orders_with_currency(
                        exchange_manager, currency))
コード例 #4
0
def cancel_orders(order_ids):
    removed_count = 0
    if order_ids:
        for order_id in order_ids:
            for exchange_manager in get_exchange_managers():
                if is_trader_enabled(exchange_manager):
                    removed_count += 1 if run_in_bot_main_loop(
                        cancel_order_with_id(exchange_manager,
                                             order_id)) else 0
    return removed_count
コード例 #5
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
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
コード例 #9
0
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
コード例 #10
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
コード例 #11
0
def get_currencies_with_status():
    evaluations_by_exchange_by_pair = {}
    for exchange_manager in get_exchange_managers():
        trading_modes = get_trading_modes(exchange_manager)
        for pair in get_trading_pairs(exchange_manager):
            if pair not in evaluations_by_exchange_by_pair:
                evaluations_by_exchange_by_pair[pair] = {}
            status_explanation = "N/A"
            status = "N/A"
            for trading_mode in trading_modes:
                if get_trading_mode_symbol(trading_mode) == pair:
                    status_explanation, status = get_trading_mode_current_state(
                        trading_mode)
                    try:
                        status = round(status, 3)
                    except TypeError:
                        pass
                    break
            evaluations_by_exchange_by_pair[pair][get_exchange_manager_id(exchange_manager)] = \
                [status_explanation.replace("_", " "), status, get_exchange_name(exchange_manager).capitalize()]
    return evaluations_by_exchange_by_pair
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
def set_enable_trading(enable):
    for exchange_manager in get_exchange_managers():
        if is_trader_enabled_in_config_from_exchange_manager(exchange_manager):
            set_trading_enabled(exchange_manager, enable)
コード例 #15
0
def get_risk():
    try:
        return get_trader_risk(next(iter(get_exchange_managers())))
    except StopIteration:
        return None
コード例 #16
0
def set_risk(risk):
    result_risk = None
    for exchange_manager in get_exchange_managers():
        result_risk = set_trader_risk(exchange_manager, risk)
    return result_risk