Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

get_account_transactions looping infinitely over the same transaction #29

Open
dequire opened this issue Oct 11, 2020 · 1 comment
Open

Comments

@dequire
Copy link

dequire commented Oct 11, 2020

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 Downloading Transactions #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,

@leikoilja
Copy link
Contributor

Hey, @dequire. This is a valid point. Please see #34 (comment). PRs are welcomed

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

No branches or pull requests

2 participants