MCPcopy Create free account
hub / github.com/ccxt/ccxt / fetch_web_endpoint

Method fetch_web_endpoint

python/ccxt/base/exchange.py:4890–4933  ·  view source on GitHub ↗
(self, method, endpointMethod, returnAsJson, startRegex=None, endRegex=None)

Source from the content-addressed store, hash-verified

4888 return result
4889
4890 def fetch_web_endpoint(self, method, endpointMethod, returnAsJson, startRegex=None, endRegex=None):
4891 errorMessage = ''
4892 options = self.safe_value(self.options, method, {})
4893 muteOnFailure = self.safe_bool(options, 'webApiMuteFailure', True)
4894 try:
4895 # if it was not explicitly disabled, then don't fetch
4896 if self.safe_bool(options, 'webApiEnable', True) is not True:
4897 return None
4898 maxRetries = self.safe_value(options, 'webApiRetries', 10)
4899 response = None
4900 retry = 0
4901 shouldBreak = False
4902 while(retry < maxRetries):
4903 try:
4904 response = getattr(self, endpointMethod)({})
4905 shouldBreak = True
4906 break
4907 except Exception as e:
4908 retry = retry + 1
4909 if retry == maxRetries:
4910 raise e
4911 if shouldBreak:
4912 break # self is needed because of GO
4913 content = response
4914 if startRegex is not None:
4915 splitted_by_start = content.split(startRegex)
4916 content = splitted_by_start[1] # we need second part after start
4917 if endRegex is not None:
4918 splitted_by_end = content.split(endRegex)
4919 content = splitted_by_end[0] # we need first part after start
4920 if returnAsJson and (isinstance(content, str)):
4921 jsoned = self.parse_json(content.strip()) # content should be trimmed before json parsing
4922 if jsoned:
4923 return jsoned # if parsing was not successfull, exception should be thrown
4924 else:
4925 raise BadResponse('could not parse the response into json')
4926 else:
4927 return content
4928 except Exception as e:
4929 errorMessage = self.id + ' ' + method + '() failed to fetch correct data from website. Probably webpage markup has been changed, breaking the page custom parser.'
4930 if muteOnFailure:
4931 return None
4932 else:
4933 raise BadResponse(errorMessage)
4934
4935 def market_ids(self, symbols: Strings = None):
4936 if symbols is None:

Callers 4

fetch_currenciesMethod · 0.45
fetch_marketsMethod · 0.45

Calls 6

safe_valueMethod · 0.95
safe_boolMethod · 0.95
parse_jsonMethod · 0.95
BadResponseClass · 0.90
splitMethod · 0.80
stripMethod · 0.45

Tested by

no test coverage detected