Skip to content

Commit

Permalink
fixed coinbase advanced trade missing candles issue
Browse files Browse the repository at this point in the history
  • Loading branch information
whittlem committed Aug 16, 2023
1 parent 83fb152 commit 96dad6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11
- name: Find typos with codespell
uses: codespell-project/actions-codespell@master
with:
Expand Down
6 changes: 2 additions & 4 deletions examples/script-coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
app1 = PyCryptoBot(exchange="coinbase")
model1 = CBAuthAPI(app1.api_key, app1.api_secret, app1.api_url, app=app1)

"""
app2 = PyCryptoBot(exchange="coinbasepro")
model2 = CAuthAPI(app2.api_key, app2.api_secret, app2.api_passphrase, app2.api_url, app=app2)
model3 = CPublicAPI(app=app2)
"""

""" COINBASE"""
# df = model1.get_accounts()
Expand Down Expand Up @@ -74,8 +72,8 @@
print(df)

""" COINBASE PRO"""
# df = model3.get_historical_data("ADA-GBP", Granularity.ONE_HOUR) # Coinbase Pro has this in the public API, Advanced Trade has this in the auth API
# print(df)
df = model3.get_historical_data("ADA-GBP", Granularity.ONE_HOUR) # Coinbase Pro has this in the public API, Advanced Trade has this in the auth API
print(df)


""" COINBASE"""
Expand Down
16 changes: 16 additions & 0 deletions models/exchange/coinbase/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,22 @@ def get_historical_data(
df["close"] = df["close"].astype(float)
df["volume"] = df["volume"].astype(float)

# create a full range of requested interval
full_range = pd.date_range(start=df.index[0], end=df.index[-1], freq=freq)

# re-index the dataframe using the full range
df = df.reindex(full_range)

# fill missing values and forward-fill the price columns and set volume to 0 for missing rows.
df["open"].fillna(method="ffill", inplace=True)
df["high"].fillna(method="ffill", inplace=True)
df["low"].fillna(method="ffill", inplace=True)
df["close"].fillna(method="ffill", inplace=True)
df["volume"].fillna(0, inplace=True)
df["market"] = market
df["granularity"] = granularity.to_integer
df["date"] = df.index

# reset pandas dataframe index
df.reset_index()

Expand Down

0 comments on commit 96dad6a

Please sign in to comment.