Skip to content

Instantly share code, notes, and snippets.

@gaburipeach
Last active February 23, 2023 07:02
Show Gist options
  • Save gaburipeach/a1f6b6cf961873e46a25eaa7a4bb8d79 to your computer and use it in GitHub Desktop.
Save gaburipeach/a1f6b6cf961873e46a25eaa7a4bb8d79 to your computer and use it in GitHub Desktop.
import requests
import ccxt
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mtick
symbol = "FIL/BTC"
time = "1h"
exch = ccxt.binance()
data = exch.fetchOHLCV(
f"{symbol}", time, limit=5001
)
df = pd.DataFrame(
data, columns=["time", "open", "high", "low", "close", "volume"]
)
df["time_utc"] = pd.to_datetime(df.time, unit="ms").astype(str)
df["symbol"] = symbol
df["logret"] = np.log(df.close/df.close.shift(1))
df["ret"] = df.close/df.close.shift(1)-1
df["date"] = pd.to_datetime(df.time, unit='ms')
# ax = plt.figure().gca()
# df.set_index("date")[["ret", "logret"]].cumsum().plot(grid=True, ax=ax)
# plt.title(symbol + " Returns")
# ax.yaxis.set_major_formatter(mtick.PercentFormatter(1.0))
ax = plt.figure().gca()
df.loc[(df.date.dt.hour >= 12)&(df.date.dt.hour <=22)].set_index("date").logret.cumsum().plot(label="US")
df.loc[(df.date.dt.hour >= 22)|(df.date.dt.hour <=8)].set_index("date").logret.cumsum().plot(label="APAC")
df.loc[(df.date.dt.hour >= 8)&(df.date.dt.hour <=17)].set_index("date").logret.cumsum().plot(label="EU")
plt.legend()
plt.grid(True)
plt.title(symbol + " Returns by Region")
ax.yaxis.set_major_formatter(mtick.PercentFormatter(1.0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment