def __init__(self, exchange, pairlistmanager, config: Dict[str, Any], pairlistconfig: Dict[str, Any], pairlist_pos: int) -> None: super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos) if 'number_assets' not in self._pairlistconfig: raise OperationalException( '`number_assets` not specified. Please check your configuration ' 'for "pairlist.config.number_assets"') self._stake_currency = config['stake_currency'] self._number_pairs = self._pairlistconfig['number_assets'] self._sort_key = self._pairlistconfig.get('sort_key', 'quoteVolume') self._min_value = self._pairlistconfig.get('min_value', 0) self._refresh_period = self._pairlistconfig.get('refresh_period', 1800) self._pair_cache: TTLCache = TTLCache(maxsize=1, ttl=self._refresh_period) if not self._exchange.exchange_has('fetchTickers'): raise OperationalException( 'Exchange does not support dynamic whitelist. ' 'Please edit your config and restart the bot.') if not self._validate_keys(self._sort_key): raise OperationalException( f'key {self._sort_key} not in {SORT_VALUES}')
def __init__(self, org_name=None, base_url=None, proxies=None, verify=None, cache_ttl=240): """ :param org_name: The name of the organization to use. :param base_url: The base URL of the Resilient server, e.g. 'https://app.resilientsystems.com/' :param proxies: A dictionary of HTTP proxies to use, if any. :param verify: The path to a PEM file containing the trusted CAs, or False to disable all TLS verification :param cache_ttl: Time to live for cached API responses """ super(SimpleClient, self).__init__(org_name, base_url, proxies, verify) self.cache = TTLCache(maxsize=128, ttl=cache_ttl)
def __init__(self, org_name=None, base_url=None, proxies=None, verify=None, cache_ttl=240): """ :param org_name: The name of the organization to use. :type org_name: str :param base_url: The base URL of the SOAR server, e.g. ``https://soar.ibm.com/`` :type base_url: str :param proxies: A dictionary of ``HTTP`` proxies to use, if any. :type proxies: dict :param verify: The path to a ``PEM`` file containing the trusted CAs, or ``False`` to disable all TLS verification :type verify: str|bool :param cache_ttl: Time in seconds to live for cached API responses :type cache_ttl: int """ super(SimpleClient, self).__init__(org_name, base_url, proxies, verify) self.cache = TTLCache(maxsize=128, ttl=cache_ttl)
def __init__(self, exchange, pairlistmanager, config: Dict[str, Any], pairlistconfig: Dict[str, Any], pairlist_pos: int) -> None: super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos) self._days = pairlistconfig.get('lookback_days', 10) self._min_rate_of_change = pairlistconfig.get('min_rate_of_change', 0.01) self._refresh_period = pairlistconfig.get('refresh_period', 1440) self._pair_cache: TTLCache = TTLCache(maxsize=100, ttl=self._refresh_period) if self._days < 1: raise OperationalException("RangeStabilityFilter requires lookback_days to be >= 1") if self._days > exchange.ohlcv_candle_limit: raise OperationalException("RangeStabilityFilter requires lookback_days to not " "exceed exchange max request size " f"({exchange.ohlcv_candle_limit})")
def __init__(self, exchange, pairlistmanager, config: Dict[str, Any], pairlistconfig: Dict[str, Any], pairlist_pos: int) -> None: super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos) if 'number_assets' not in self._pairlistconfig: raise OperationalException( '`number_assets` not specified. Please check your configuration ' 'for "pairlist.config.number_assets"') self._stake_currency = config['stake_currency'] self._number_pairs = self._pairlistconfig['number_assets'] self._sort_key = self._pairlistconfig.get('sort_key', 'quoteVolume') self._min_value = self._pairlistconfig.get('min_value', 0) self._refresh_period = self._pairlistconfig.get('refresh_period', 1800) self._pair_cache: TTLCache = TTLCache(maxsize=1, ttl=self._refresh_period) self._lookback_days = self._pairlistconfig.get('lookback_days', 0) self._lookback_timeframe = self._pairlistconfig.get( 'lookback_timeframe', '1d') self._lookback_period = self._pairlistconfig.get('lookback_period', 0) if (self._lookback_days > 0) & (self._lookback_period > 0): raise OperationalException( 'Ambigous configuration: lookback_days and lookback_period both set in pairlist ' 'config. Please set lookback_days only or lookback_period and lookback_timeframe ' 'and restart the bot.') # overwrite lookback timeframe and days when lookback_days is set if self._lookback_days > 0: self._lookback_timeframe = '1d' self._lookback_period = self._lookback_days # get timeframe in minutes and seconds self._tf_in_min = timeframe_to_minutes(self._lookback_timeframe) self._tf_in_sec = self._tf_in_min * 60 # wether to use range lookback or not self._use_range = (self._tf_in_min > 0) & (self._lookback_period > 0) if self._use_range & (self._refresh_period < self._tf_in_sec): raise OperationalException( f'Refresh period of {self._refresh_period} seconds is smaller than one ' f'timeframe of {self._lookback_timeframe}. Please adjust refresh_period ' f'to at least {self._tf_in_sec} and restart the bot.') if not self._exchange.exchange_has('fetchTickers'): raise OperationalException( 'Exchange does not support dynamic whitelist. ' 'Please edit your config and restart the bot.') if not self._validate_keys(self._sort_key): raise OperationalException( f'key {self._sort_key} not in {SORT_VALUES}') if self._lookback_period < 0: raise OperationalException( "VolumeFilter requires lookback_period to be >= 0") if self._lookback_period > exchange.ohlcv_candle_limit( self._lookback_timeframe): raise OperationalException( "VolumeFilter requires lookback_period to not " "exceed exchange max request size " f"({exchange.ohlcv_candle_limit(self._lookback_timeframe)})")
def __init__(self) -> None: # Timeout: 6h self._pair_price: TTLCache = TTLCache(maxsize=500, ttl=6 * 60 * 60) self._load_cryptomap()
def __init__(self): """ A simple temporary code confirmation system. Used only for the 'dbclear' command. """ self.cache = TTLCache(maxsize=30, ttl=90)
class ConfirmManager: def __init__(self): """ A simple temporary code confirmation system. Used only for the 'dbclear' command. """ self.cache = TTLCache(maxsize=30, ttl=90) def gen_code(self, member: discord.Member): """ Generate a code and assign said code to a member. Lasts a maximum of 90 seconds. Parameters --------- member: :class:`discord.Member` A member of a guild. """ code = "".join(random.choice(string.ascii_lowercase) for i in range(5)) self.cache[member.id] = code return code def confirm_code(self, member: discord.Member, code: str): """ Confirm a code. Parameters --------- member: :class:`discord.Member` A discord member. code: :class:`str` The 5 character code. Returns ------ :class:`bool` True if the code was valid, else False. """ c_code = self.cache.get(member.id) if c_code is None: return False confirmed = c_code == code if confirmed: self.cache.pop(member.id) return confirmed def has_code(self, member: discord.Member): """ Check if a member has a code. Parameters --------- member: :class:`discord.Member` A discord member. Returns ------ :class:`bool A discord member. Returns ------ :class:`bool` True if the member does has a code cached, else false. """ return self.cache.get(member.id) is not None