def get_exchange_credentials(self) -> Dict[str, ApiCredentials]: cursor = self.conn.cursor() result = cursor.execute( 'SELECT name, api_key, api_secret FROM user_credentials;', ) result = result.fetchall() credentials = {} for entry in result: if entry == 'rotkehlchen': continue name = entry[0] credentials[name] = ApiCredentials.serialize( api_key=str(entry[1]), api_secret=str(entry[2]), ) return credentials
def setup_exchange( self, name: str, api_key: ApiKey, api_secret: ApiSecret, database: 'DBHandler', passphrase: Optional[str] = None, ) -> Tuple[bool, str]: """ Setup a new exchange with an api key, an api secret and for some exchanges a passphrase. """ if name not in SUPPORTED_EXCHANGES: return False, 'Attempted to register unsupported exchange {}'.format( name) if self.has_exchange(name, database=database): return False, 'Exchange {} is already registered'.format(name) credentials_dict = {} api_credentials = ApiCredentials( api_key=api_key, api_secret=api_secret, passphrase=passphrase, ) credentials_dict[name] = api_credentials self.initialize_exchanges(credentials_dict, database) exchange = self.connected_exchanges[name] try: result, message = exchange.validate_api_key() except RemoteError as e: result = False message = str(e) if not result: log.error( 'Failed to validate API key for exchange', name=name, error=message, ) self.delete_exchange(name) return False, message return True, ''
def setup_exchange( self, name: str, api_key: str, api_secret: str, ) -> Tuple[bool, str]: """ Setup a new exchange with an api key and an api secret By default the api keys are always validated unless validate is False. """ log.info('setup_exchange', name=name) if name not in SUPPORTED_EXCHANGES: return False, 'Attempted to register unsupported exchange {}'.format( name) if getattr(self, name) is not None: return False, 'Exchange {} is already registered'.format(name) credentials_dict = {} api_credentials = ApiCredentials.serialize(api_key=api_key, api_secret=api_secret) credentials_dict[name] = api_credentials self.initialize_exchanges(credentials_dict) exchange = getattr(self, name) result, message = exchange.validate_api_key() if not result: log.error( 'Failed to validate API key for exchange', name=name, error=message, ) self.delete_exchange_data(name) return False, message # Success, save the result in the DB self.data.db.add_exchange(name, api_key, api_secret) return True, ''
def setup_exchange( self, name: str, api_key: str, api_secret: str, database: 'DBHandler', ) -> Tuple[bool, str]: """ Setup a new exchange with an api key and an api secret By default the api keys are always validated unless validate is False. """ if name not in SUPPORTED_EXCHANGES: return False, 'Attempted to register unsupported exchange {}'.format( name) if name in self.connected_exchanges: return False, 'Exchange {} is already registered'.format(name) credentials_dict = {} api_credentials = ApiCredentials.serialize(api_key=api_key, api_secret=api_secret) credentials_dict[name] = api_credentials self.initialize_exchanges(credentials_dict, database) exchange = self.connected_exchanges[name] result, message = exchange.validate_api_key() if not result: log.error( 'Failed to validate API key for exchange', name=name, error=message, ) self.delete_exchange(name) return False, message return True, ''