1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #! python2
# -*- coding:Utf-8 -*-
import io
import datetime
import requests
import pandas as pd
def unix_time_ms(dt):
ref = datetime.datetime.utcfromtimestamp(0)
return int((dt - ref).total_seconds() * 1000)
def get_hist_data_euronext(isin, from_date, to_date):
""" """
# Build url of the product to download
from_date, to_date = unix_time_ms(from_date), unix_time_ms(to_date)
template = 'https://www.euronext.com/nyx_eu_listings/price_chart/' \
'download_historical?typefile=csv&layout=vertical&' \
'typedate=dmy&separator=pointt&mic=XPAR&isin={0}&' \
'namefile=Price_Data_Historical&from={1}&to={2}' \
'&adjusted=1&base=0'
url = template.format(isin, from_date, to_date)
# Download csv file from Euronext
response = requests.get(url).content
# Build Pandas DataFrame of OHLC
df = pd.read_csv(io.StringIO(response.decode('utf-8')), skiprows=3,
usecols=['Date', 'Open', 'High', 'Low', 'Close'])
df.index = pd.to_datetime(df['Date'].values, format='%d/%m/%Y')
del(df['Date'])
return df
if __name__ == '__main__':
isin = 'FR0010168773'
from_date = datetime.datetime(2001, 12, 16, 0, 0)
to_date = datetime.datetime(2015, 12, 16, 0, 0)
ohlc = get_hist_data_euronext(isin, from_date, to_date)
print ohlc |
Partager