revolut-python icon indicating copy to clipboard operation
revolut-python copied to clipboard

get_account_transactions looping infinitely over the same transaction

Open dequire opened this issue 5 years ago • 1 comments

Hi @tducret ,

First of all, thanks for the great library! :-)

I was using your library to load historical transactions from last 2 years, when I noticed that get_account_transactions is getting stuck in a specific case.

In my example:

  1. first run of the loop
  • from 2019-03-01 to 2019-03-15, returned 47 transactions
  • algorithm takes startedDate from the oldest transactions and sets it as a new to parameter
  1. second run of the loop
  • from 2019-03-01 to 2019-03-01 09:29:38, returned 1 transaction - the same transaction which was present in first run
  • algorithm takes startedDate from the oldest transactions - which is the same as before
  1. step #2 is repeated endlessly

I worked around it by manually subtracting 1 second from the timestamp, as below.

    def get_account_transactions(self, from_date=None, to_date=None):
        """Get the account transactions."""
        raw_transactions = []
        params = {}
        if to_date:
            params['to'] = int(to_date.timestamp()) * 1000
        if from_date:
            params['from'] = int(from_date.timestamp()) * 1000

        while True:
            ret = self.client._get(_URL_GET_TRANSACTIONS_LAST, params=params)
            ret_transactions = ret.json()
            if not ret_transactions:
                break
            params['to'] = ret_transactions[-1]['startedDate']-1000 # fixed, because this loop was endlessly fetching the same transaction
            raw_transactions.extend(ret_transactions)
        
        return AccountTransactions(raw_transactions)

I'm not sure if it is possible to have more than one transaction with the same startedDate, but if yes, then this is not a proper solution.

Did you encounter case like that with your account?

Regards,

dequire avatar Oct 11 '20 18:10 dequire

Hey, @dequire. This is a valid point. Please see https://github.com/tducret/revolut-python/issues/34#issuecomment-756612503. PRs are welcomed

leikoilja avatar Jan 08 '21 09:01 leikoilja