STOOQ_URL = 'https://static.stooq.com/db/h/'
def download_price_data(market='us'):
data_url = 'd_{market}_txt.zip'.format(market=market)
response = requests.get(STOOQ_URL + data_url).content
with ZipFile(BytesIO(response)) as zip_file:
for i, file in enumerate(zip_file.namelist()):
if not file.endswith('.txt'):
continue
local_file = stooq_path / file
local_file.parent.mkdir(parents=True, exist_ok=True)
with local_file.open('wb') as output:
for line in zip_file.open(file).readlines():
output.write(line)
for market in ['us', 'jp']:
download_price_data(market=market)
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-21-f0e4d2874851> in <module>()
1 for market in ['us', 'jp']:
----> 2 download_price_data(market=market)
<ipython-input-20-f37e9a3a9947> in download_price_data(market)
8 local_file = stooq_path / file
9 local_file.parent.mkdir(parents=True, exist_ok=True)
---> 10 with local_file.open('wb') as output:
11 for line in zip_file.open(file).readlines():
12 output.write(line)
~\Anaconda3\envs\backtesting\lib\pathlib.py in open(self, mode, buffering, encoding, errors, newline)
1149 self._raise_closed()
1150 return io.open(str(self), mode, buffering, encoding, errors, newline,
-> 1151 opener=self._opener)
1152
1153 def read_bytes(self):
~\Anaconda3\envs\backtesting\lib\pathlib.py in _opener(self, name, flags, mode)
1003 def _opener(self, name, flags, mode=0o666):
1004 # A stub for the opener argument to built-in open()
-> 1005 return self._accessor.open(self, flags, mode)
1006
1007 def _raw_open(self, flags, mode=0o777):
~\Anaconda3\envs\backtesting\lib\pathlib.py in wrapped(pathobj, *args)
369 @functools.wraps(strfunc)
370 def wrapped(pathobj, *args):
--> 371 return strfunc(str(pathobj), *args)
372 return staticmethod(wrapped)
373
FileNotFoundError: [Errno 2] No such file or directory: 'stooq\\data\\daily\\us\\nasdaq stocks\\2\\prn.us.txt'
Hi Stefan
when I download and store STOOQ data, I get an error message
this is an error message
can you help me plz?