async def test_initialize(): async with get_importer() as importer: assert importer.exchange_name == "binance" assert importer.symbols == ["ETH/BTC"] assert importer.time_frames == [TimeFrames(tf) for tf in ("1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "8h", "12h", "1d", "3d", "1w", "1M")] assert importer.available_data_types == [ExchangeDataTables.OHLCV]
def get_symbol_time_candles(symbol_data, time_frame, limit, include_in_construction): tf = TimeFrames(time_frame) if include_in_construction: return _add_in_construction_data( symbol_data.symbol_candles[tf].get_symbol_time_candles(limit), symbol_data, tf, PriceIndexes.IND_PRICE_TIME.value) return symbol_data.symbol_candles[tf].get_symbol_time_candles(limit)
def parse_time_frames(time_frames_string_list): result_list = [] for time_frame_string in time_frames_string_list: try: result_list.append(TimeFrames(time_frame_string)) except ValueError: get_logger(LOGGER_TAG).error( "No time frame available for: '{0}'. Available time " "frames are: {1}. '{0}' time frame requirement " "ignored.".format(time_frame_string, [t.value for t in TimeFrames])) return result_list
async def symbol_data(time_frame): symbol_candles = CandlesManager() await symbol_candles.initialize() symbol_candles.replace_all_candles(_get_candles()) symbol_kline = KlineManager() await symbol_kline.initialize() symbol_kline.kline_update(_get_candle(11)) manager = ExchangeManager({}, "binance") symbol_data = ExchangeSymbolData(manager, "BTC/USDT") tf = TimeFrames(time_frame) symbol_data.symbol_candles[tf] = symbol_candles symbol_data.symbol_klines[tf] = symbol_kline return symbol_data
async def initialize(self) -> None: self.load_database() await self.database.initialize() # load description description = (await self.database.select(DataTables.DESCRIPTION, size=1))[0] version = description[1] if version == "1.0": self.exchange_name = description[2] self.symbols = json.loads(description[3]) self.time_frames = [TimeFrames(tf) for tf in json.loads(description[4])] self.logger.info(f"Loaded {self.exchange_name} data file with " f"{', '.join(self.symbols)} on {', '.join([tf.value for tf in self.time_frames])}")
def find_min_time_frame(time_frames, min_time_frame=None): tf_list = time_frames if time_frames and isinstance(next(iter(time_frames)), TimeFrames): tf_list = [t.value for t in time_frames] if not tf_list: # if exchange has no time frame list, returns minimal time frame return TimeFramesRank[0] min_index = 0 if min_time_frame: min_index = TimeFramesRank.index(min_time_frame) # TimeFramesRank is the ordered list of timeframes for index, tf in enumerate(TimeFramesRank): tf_val = tf.value if index >= min_index and tf_val in tf_list: try: return TimeFrames(tf_val) except ValueError: pass return min_time_frame
def get_symbol_klines(symbol_data, time_frame) -> list: return symbol_data.symbol_klines[TimeFrames(time_frame)].kline
def has_symbol_klines(symbol_data, time_frame) -> bool: return TimeFrames(time_frame) in symbol_data.symbol_klines
def get_symbol_candles_manager(symbol_data, time_frame) -> CandlesManager: return symbol_data.symbol_candles[TimeFrames(time_frame)]
def test_parse_time_frames(): assert parse_time_frames( ["3d", "5d", "1m", "6h"]) == [TimeFrames("3d"), TimeFrames("1m"), TimeFrames("6h")]
def test_get_config_time_frame(): assert get_config_time_frame(load_test_config()) == [ TimeFrames("1h"), TimeFrames("4h"), TimeFrames("1d") ]
def _convert_time_frame(str_time_frame): return TimeFrames(str_time_frame)
def get_candle_manager(self, exchange_name, symbol, time_frame): return self.get_exchange_symbol_data( exchange_name, symbol).symbol_candles[TimeFrames(time_frame)]
def init_config_time_frame_for_tests(config): result = [] for time_frame in config[CONFIG_TIME_FRAME]: result.append(TimeFrames(time_frame)) config[CONFIG_TIME_FRAME] = result