def get_trades_by_times_and_prices(symbol, side, force_timezone=False): simulated_trades_times = [] simulated_trades_prices = [] real_trades_times = [] real_trades_prices = [] real_times = None simulated_times = None traders = get_traders() for trader in traders: for trade in trader.get_trades_manager().get_trade_history(): if trade.get_symbol() == symbol: if trade.get_side() == side: if trader.get_simulate(): simulated_trades_times.append(trade.get_filled_time()) simulated_trades_prices.append(trade.get_price()) else: real_trades_times.append(trade.get_filled_time()) real_trades_prices.append(trade.get_price()) real_times = convert_timestamps_to_datetime( real_trades_times, force_timezone=force_timezone) simulated_times = convert_timestamps_to_datetime( simulated_trades_times, force_timezone=force_timezone) return real_trades_prices, real_times, simulated_trades_prices, simulated_times
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
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