!pip install mplfinance
import mplfinance as mpf
import requests
import json
import datetime
from datetime import tzinfo, timezone, timedelta
import pandas as pd
JST = timezone(timedelta(hours=+9))
url = f'https://api.polygon.io/v2/aggs/ticker/DOW/range/1/minute/2022-09-22/2022-09-23' \
+ f'?adjusted=true&sort=asc&limit=49997&apiKey={key}'
resp = requests.get(url)
resp_json = json.loads(resp.text)
def convert(json):
print(json)
dt = datetime.datetime.fromtimestamp(json['t']/1000, JST)
return { **json, 't': dt, }
arr = [convert(j) for j in resp_json['results']]
df = pd.DataFrame(arr)
df.index = df.t
df['Open'] = df.o
df['High'] = df.h
df['Low'] = df.l
df['Close'] = df.c
df['Volume'] = df.v
df['NumOfAggregatedTransactions'] = df.n
df.drop(columns=['v', 'vw', 'o', 'c', 'h', 'l', 't', 'n'], inplace=True)
df
mpf.plot(df, figratio=(12,4), type='candle', style="yahoo", volume=True)