Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_ohlcv 및 get_ohlcv_from 에서 timezone 수정으로 메소드 스펙 바뀌던 문제 원복 #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions pyupbit/quotation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_ohlcv(ticker="KRW-BTC", interval="day", count=200, to=None,
elif isinstance(to, pd._libs.tslibs.timestamps.Timestamp):
to = to.to_pydatetime()

#to = to.astimezone(datetime.timezone.utc)
to = to.astimezone(datetime.timezone.utc)

dfs = []
count = max(count, 1)
Expand All @@ -107,7 +107,6 @@ def get_ohlcv(ticker="KRW-BTC", interval="day", count=200, to=None,
for x in contents:
dt = datetime.datetime.strptime(
x['candle_date_time_kst'], "%Y-%m-%dT%H:%M:%S")
#dt_list.append(dt.astimezone())
dt_list.append(dt)

df = pd.DataFrame(contents,
Expand Down Expand Up @@ -154,15 +153,15 @@ def get_ohlcv_from(ticker="KRW-BTC", interval="day", fromDatetime=None,
fromDatetime = pd.to_datetime(fromDatetime).to_pydatetime()
elif isinstance(fromDatetime, pd._libs.tslibs.timestamps.Timestamp):
fromDatetime = fromDatetime.to_pydatetime()
#fromDatetime = fromDatetime.astimezone(datetime.timezone.utc)
fromDatetime = fromDatetime.astimezone(datetime.timezone.utc)

if to is None:
to = datetime.datetime.now()
elif isinstance(to, str):
to = pd.to_datetime(to).to_pydatetime()
elif isinstance(to, pd._libs.tslibs.timestamps.Timestamp):
to = to.to_pydatetime()
#to = to.astimezone(datetime.timezone.utc)
to = to.astimezone(datetime.timezone.utc)

dfs = []
while to > fromDatetime:
Expand All @@ -177,10 +176,9 @@ def get_ohlcv_from(ticker="KRW-BTC", interval="day", fromDatetime=None,
for x in contents:
dt = datetime.datetime.strptime(
x['candle_date_time_kst'], "%Y-%m-%dT%H:%M:%S")
#dt_list.append(dt.astimezone())
dt_list.append(dt)
# set timezone for time comparison
# timezone will be removed before DataFrame returned
dt_list.append(dt.astimezone())
# set timezone for time comparison
# timezone will be removed before DataFrame returned

df = pd.DataFrame(contents,
columns=[
Expand All @@ -198,15 +196,18 @@ def get_ohlcv_from(ticker="KRW-BTC", interval="day", fromDatetime=None,

to = datetime.datetime.strptime(
contents[-1]['candle_date_time_utc'], "%Y-%m-%dT%H:%M:%S")
#to = to.replace(tzinfo=datetime.timezone.utc)
to = to.replace(tzinfo=datetime.timezone.utc)
# to compare fromTs and to, set tzinfo
# timezone will be removed before DataFrame returned

if to > fromDatetime:
time.sleep(period)

df = pd.concat(dfs).sort_index()
df = df[df.index >= fromDatetime]
df.index = df.index.tz_localize(None)
# remove timezone, return DataFrame whose index has no timezone
# like get_ohlcv method
df = df.rename(columns={"opening_price": "open",
"high_price": "high",
"low_price": "low",
Expand Down