Closed trnhattan closed 3 years ago
DataLoader is using old API, it's not work anymore. New class DataLoaderVND may be solving your issue.
Or try this:
def convert_date(text, date_type = '%Y-%m-%d'):
return datetime.strptime(text, date_type)
def convert_text_dateformat(text, origin_type = '%Y-%m-%d', new_type = '%Y-%m-%d'):
return convert_date(text, origin_type).strftime(new_type)
id_batch = 1
symbol ='VIC'
start = "2021-01-01"
end= "2021-07-24"
start_date = convert_text_dateformat(start, origin_type = '%Y-%m-%d', new_type = '%Y-%m-%d')
end_date = convert_text_dateformat(end, origin_type = '%Y-%m-%d', new_type = '%Y-%m-%d')
API_VNDIRECT = 'https://finfo-api.vndirect.com.vn/v4/stock_prices/'
query = 'code:' + symbol + '~date:gte:' + start_date + '~date:lte:' + end_date
delta = datetime.strptime(end_date, '%Y-%m-%d') - datetime.strptime(start_date, '%Y-%m-%d')
params = {
"sort": "date",
"size": delta.days + 1,
"page": 1,
"q": query
}
res = requests.get(API_VNDIRECT, params=params)
data = res.json()['data']
data = pd.DataFrame(data)
data.tail()
DataLoader is using old API, it's not work anymore. New class DataLoaderVND may be solving your issue.
Or try this:
def convert_date(text, date_type = '%Y-%m-%d'): return datetime.strptime(text, date_type) def convert_text_dateformat(text, origin_type = '%Y-%m-%d', new_type = '%Y-%m-%d'): return convert_date(text, origin_type).strftime(new_type) id_batch = 1 symbol ='VIC' start = "2021-01-01" end= "2021-07-24" start_date = convert_text_dateformat(start, origin_type = '%Y-%m-%d', new_type = '%Y-%m-%d') end_date = convert_text_dateformat(end, origin_type = '%Y-%m-%d', new_type = '%Y-%m-%d') API_VNDIRECT = 'https://finfo-api.vndirect.com.vn/v4/stock_prices/' query = 'code:' + symbol + '~date:gte:' + start_date + '~date:lte:' + end_date delta = datetime.strptime(end_date, '%Y-%m-%d') - datetime.strptime(start_date, '%Y-%m-%d') params = { "sort": "date", "size": delta.days + 1, "page": 1, "q": query } res = requests.get(API_VNDIRECT, params=params) data = res.json()['data'] data = pd.DataFrame(data) data.tail()
Thanks for solving my problem!
KeyError: "None of [Index(['date', 'adClose', 'close', 'pctChange', 'average', 'nmVolume',\n 'nmValue', 'ptVolume', 'ptValue', 'open', 'high', 'low'],\n dtype='object')] are in the [columns]"