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

Coinbase trades pagination cursor #22617

Closed
x1i4b1x2 opened this issue May 25, 2024 · 9 comments
Closed

Coinbase trades pagination cursor #22617

x1i4b1x2 opened this issue May 25, 2024 · 9 comments
Assignees

Comments

@x1i4b1x2
Copy link

Operating System

No response

Programming Languages

No response

CCXT Version

No response

Description

How can you paginate trades on Coinbase with timestamps? It seems that they only use the trade id, but what if you want to fetch at some point in the past?

Is there a way to give something like a "since" parameter or the docs are correct and there is no way?

Code

  

@carlosmiei carlosmiei self-assigned this May 25, 2024
@carlosmiei
Copy link
Collaborator

Hello @x1i4b1x2,
Which coinbase branch are you using and what's your ccxt version?

@x1i4b1x2
Copy link
Author

It's latest version, and coinbaseexchange

@carlosmiei
Copy link
Collaborator

@x1i4b1x2 as you said the pagination can't be done using timestamps, but you can use the Ids, example:

    cache = []
    trades = await exchange.fetch_trades('BTC/USDT')
    cache += trades
    first = trades[0]
    cursor = first['id']
    i = 0
    max_calls = 10
    while cursor:
        i+=1
        trades = await exchange.fetch_trades('BTC/USDT', params={'after': cursor})
        if len(trades) == 0:
            break
        cache += trades
        cursor = trades[0]['id']
        print('number of trades fetched:', len(cache))
        if i > max_calls:
            break

@x1i4b1x2
Copy link
Author

Yes, so there is nothing missing in the docs, it can only be done with Ids right?

@carlosmiei
Copy link
Collaborator

@x1i4b1x2 Yes as you can see here, since/until timestamps are not supported: https://docs.cdp.coinbase.com/exchange/reference/exchangerestapi_getproducttrades/

@x1i4b1x2
Copy link
Author

That's very sad. Have you ever found a clever way to fetch in the past without having to guess the Ids?

@carlosmiei
Copy link
Collaborator

carlosmiei commented May 25, 2024

@x1i4b1x2 the ids are linear as you can see here, so you should be able to "guess" older ids

image

@carlosmiei
Copy link
Collaborator

Actually I just tested and does not seem to work, so disregard my suggestion pls

@x1i4b1x2
Copy link
Author

Yes that's very sad, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants