예제 #1
0
def create_candles_data(symbol, time_frame, new_data, bot, list_arrays,
                        in_backtesting):
    candles_key = "candles"
    real_trades_key = "real_trades"
    simulated_trades_key = "simulated_trades"
    result_dict = {
        candles_key: [],
        real_trades_key: [],
        simulated_trades_key: [],
    }

    if not in_backtesting:
        add_to_symbol_data_history(symbol, new_data, time_frame, False)
        data = get_symbol_data_history(symbol, time_frame)
    else:
        data = new_data

    data_x = convert_timestamps_to_datetime(
        data[PriceIndexes.IND_PRICE_TIME.value],
        time_format="%y-%m-%d %H:%M:%S",
        force_timezone=False)

    real_trades_history, simulated_trades_history = get_trades_history(
        bot, symbol)

    if real_trades_history:
        result_dict[real_trades_key] = _format_trades(real_trades_history)

    if real_trades_history:
        result_dict[simulated_trades_key] = _format_trades(
            simulated_trades_history)

    if list_arrays:
        result_dict[candles_key] = {
            PriceStrings.STR_PRICE_TIME.value:
            data_x,
            PriceStrings.STR_PRICE_CLOSE.value:
            data[PriceIndexes.IND_PRICE_CLOSE.value].tolist(),
            PriceStrings.STR_PRICE_LOW.value:
            data[PriceIndexes.IND_PRICE_LOW.value].tolist(),
            PriceStrings.STR_PRICE_OPEN.value:
            data[PriceIndexes.IND_PRICE_OPEN.value].tolist(),
            PriceStrings.STR_PRICE_HIGH.value:
            data[PriceIndexes.IND_PRICE_HIGH.value].tolist()
        }
    else:
        result_dict[candles_key] = {
            PriceStrings.STR_PRICE_TIME.value:
            data_x,
            PriceStrings.STR_PRICE_CLOSE.value:
            data[PriceIndexes.IND_PRICE_CLOSE.value],
            PriceStrings.STR_PRICE_LOW.value:
            data[PriceIndexes.IND_PRICE_LOW.value],
            PriceStrings.STR_PRICE_OPEN.value:
            data[PriceIndexes.IND_PRICE_OPEN.value],
            PriceStrings.STR_PRICE_HIGH.value:
            data[PriceIndexes.IND_PRICE_HIGH.value]
        }
    return result_dict
예제 #2
0
def get_currency_graph_update(exchange_name, symbol, time_frame, cryptocurrency_name):
    symbol_evaluator_list = get_bot().get_symbol_evaluator_list()
    exchange_list = get_bot().get_exchanges_list()

    if time_frame is not None:
        if len(symbol_evaluator_list) > 0:
            evaluator_thread_managers = symbol_evaluator_list[symbol].get_evaluator_thread_managers(
                exchange_list[exchange_name])

            if time_frame in evaluator_thread_managers:
                evaluator_thread_manager = evaluator_thread_managers[time_frame]
                df = evaluator_thread_manager.get_evaluator().get_data()

                if df is not None:
                    symbol_tag, pair_tag = Exchange.split_symbol(symbol)
                    add_to_symbol_data_history(symbol, df, time_frame)
                    df = get_symbol_data_history(symbol, time_frame)

                    # df.loc[:, PriceStrings.STR_PRICE_TIME.value] /= 1000

                    X = df[PriceStrings.STR_PRICE_TIME.value]
                    Y = df[PriceStrings.STR_PRICE_CLOSE.value]

                    # Candlestick
                    data = go.Ohlc(x=df[PriceStrings.STR_PRICE_TIME.value],
                                   open=df[PriceStrings.STR_PRICE_OPEN.value],
                                   high=df[PriceStrings.STR_PRICE_HIGH.value],
                                   low=df[PriceStrings.STR_PRICE_LOW.value],
                                   close=df[PriceStrings.STR_PRICE_CLOSE.value])

                    real_trades_prices, real_trades_times, simulated_trades_prices, simulated_trades_times = \
                        get_trades_by_times_and_prices()

                    real_trades_points = go.Scatter(
                        x=real_trades_prices,
                        y=real_trades_times,
                        mode='markers',
                        name='markers'
                    )

                    simulated_trades_points = go.Scatter(
                        x=simulated_trades_times,
                        y=simulated_trades_prices,
                        mode='markers',
                        name='markers'
                    )

                    return {'data': [data, real_trades_points, simulated_trades_points],
                            'layout': go.Layout(
                                title="{} real time data (per time frame)".format(cryptocurrency_name),
                                xaxis=dict(range=[min(X), max(X)],
                                           title=TIME_AXIS_TITLE),
                                yaxis=dict(range=[min(Y) * 0.98, max(Y) * 1.02],
                                           title=pair_tag)
                            )}
    return None
예제 #3
0
def get_currency_graph_update(exchange_name, symbol, time_frame, cryptocurrency_name):
    symbol_evaluator_list = get_bot().get_symbol_evaluator_list()
    exchange_list = get_bot().get_exchanges_list()

    if time_frame is not None:
        if len(symbol_evaluator_list) > 0:
            evaluator_thread_managers = symbol_evaluator_list[symbol].get_evaluator_thread_managers(
                exchange_list[exchange_name])

            if time_frame in evaluator_thread_managers:
                evaluator_thread_manager = evaluator_thread_managers[time_frame]
                data = evaluator_thread_manager.get_evaluator().get_data()

                if data is not None:
                    _, pair_tag = split_symbol(symbol)
                    add_to_symbol_data_history(symbol, data, time_frame)
                    data = get_symbol_data_history(symbol, time_frame)

                    # data.loc[:, PriceStrings.STR_PRICE_TIME.value] /= 1000

                    data_x = data[PriceIndexes.IND_PRICE_TIME.value]
                    data_y = data[PriceIndexes.IND_PRICE_CLOSE.value]

                    # Candlestick
                    ohlc_graph = go.Ohlc(x=data[PriceIndexes.IND_PRICE_TIME.value],
                                         open=data[PriceIndexes.IND_PRICE_OPEN.value],
                                         high=data[PriceIndexes.IND_PRICE_HIGH.value],
                                         low=data[PriceIndexes.IND_PRICE_LOW.value],
                                         close=data[PriceIndexes.IND_PRICE_CLOSE.value])

                    real_trades_prices, real_trades_times, simulated_trades_prices, simulated_trades_times = \
                        get_trades_by_times_and_prices()

                    real_trades_points = go.Scatter(
                        x=real_trades_prices,
                        y=real_trades_times,
                        mode='markers',
                        name='markers'
                    )

                    simulated_trades_points = go.Scatter(
                        x=simulated_trades_times,
                        y=simulated_trades_prices,
                        mode='markers',
                        name='markers'
                    )

                    return {'data': [ohlc_graph, real_trades_points, simulated_trades_points],
                            'layout': go.Layout(
                                title="{} real time data (per time frame)".format(cryptocurrency_name),
                                xaxis=dict(range=[min(data_x), max(data_x)],
                                           title=TIME_AXIS_TITLE),
                                yaxis=dict(range=[min(data_y) * 0.98, max(data_y) * 1.02],
                                           title=pair_tag)
                            )}
    return None
예제 #4
0
def get_currency_price_graph_update(exchange_name,
                                    symbol,
                                    time_frame,
                                    list_arrays=True,
                                    backtesting=False):
    bot = get_bot()
    if backtesting and bot.get_tools() and bot.get_tools(
    )[BOT_TOOLS_BACKTESTING]:
        bot = bot.get_tools()[BOT_TOOLS_BACKTESTING].get_bot()
    symbol = parse_get_symbol(symbol)
    symbol_evaluator_list = bot.get_symbol_evaluator_list()
    in_backtesting = Backtesting.enabled(get_global_config()) or backtesting

    exchange = exchange_name
    exchange_list = bot.get_exchanges_list()
    if backtesting:
        exchanges = [key for key in exchange_list if exchange_name in key]
        if exchanges:
            exchange = exchanges[0]

    if time_frame is not None:
        if symbol_evaluator_list:
            evaluator_thread_managers = symbol_evaluator_list[
                symbol].get_evaluator_thread_managers(exchange_list[exchange])

            if time_frame in evaluator_thread_managers:
                evaluator_thread_manager = evaluator_thread_managers[
                    time_frame]
                data = evaluator_thread_manager.get_evaluator().get_data()

                if data is not None:

                    candles_key = "candles"
                    real_trades_key = "real_trades"
                    simulated_trades_key = "simulated_trades"
                    result_dict = {
                        candles_key: [],
                        real_trades_key: [],
                        simulated_trades_key: [],
                    }

                    _, pair_tag = split_symbol(symbol)
                    add_to_symbol_data_history(symbol, data, time_frame,
                                               in_backtesting)
                    data = get_symbol_data_history(symbol, time_frame)

                    data_x = convert_timestamps_to_datetime(
                        data[PriceIndexes.IND_PRICE_TIME.value],
                        time_format="%y-%m-%d %H:%M:%S",
                        force_timezone=False)

                    real_trades_history, simulated_trades_history = get_trades_history(
                        bot, symbol)

                    if real_trades_history:
                        result_dict[real_trades_key] = _format_trades(
                            real_trades_history)

                    if real_trades_history:
                        result_dict[simulated_trades_key] = _format_trades(
                            simulated_trades_history)

                    if list_arrays:
                        result_dict[candles_key] = {
                            PriceStrings.STR_PRICE_TIME.value:
                            data_x,
                            PriceStrings.STR_PRICE_CLOSE.value:
                            data[PriceIndexes.IND_PRICE_CLOSE.value].tolist(),
                            PriceStrings.STR_PRICE_LOW.value:
                            data[PriceIndexes.IND_PRICE_LOW.value].tolist(),
                            PriceStrings.STR_PRICE_OPEN.value:
                            data[PriceIndexes.IND_PRICE_OPEN.value].tolist(),
                            PriceStrings.STR_PRICE_HIGH.value:
                            data[PriceIndexes.IND_PRICE_HIGH.value].tolist()
                        }
                    else:
                        result_dict[candles_key] = {
                            PriceStrings.STR_PRICE_TIME.value:
                            data_x,
                            PriceStrings.STR_PRICE_CLOSE.value:
                            data[PriceIndexes.IND_PRICE_CLOSE.value],
                            PriceStrings.STR_PRICE_LOW.value:
                            data[PriceIndexes.IND_PRICE_LOW.value],
                            PriceStrings.STR_PRICE_OPEN.value:
                            data[PriceIndexes.IND_PRICE_OPEN.value],
                            PriceStrings.STR_PRICE_HIGH.value:
                            data[PriceIndexes.IND_PRICE_HIGH.value]
                        }
                    return result_dict
    return None