Skip to content

Commit

Permalink
payment_history_filtered fixed
Browse files Browse the repository at this point in the history
1. Added delay between pages (Crypomus raises error if paginate too fast)

2. Fixed bug with max_items not applied for pages
  • Loading branch information
Badiboy committed Apr 9, 2023
1 parent 37e7111 commit dcb051a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pyCryptomusAPI/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from hashlib import md5
from time import sleep
import base64
import requests

Expand Down Expand Up @@ -305,7 +306,7 @@ def payment_history(self, cursor = None):
def payment_history_filtered(
self, max_results = 15, max_pages = 10,
currencies = None, networks = None, addresses = None,
statuses = None, is_final = None):
statuses = None, is_final = None, page_delay = 1):
"""
Payment history (advanced mode)
Expand All @@ -323,13 +324,15 @@ def payment_history_filtered(
addresses: (List of Strings, Optional) List of accepted addresses
statuses: (List of Strings, Optional) List of accepted statuses. Codes: https://doc.cryptomus.com/payments/payment-statuses
is_final: (Bool, Optional) If True, only final payments will be collected, if False - only non-final
page_delay: (Int, Optional, default=1) Delay between pages (in seconds)
"""

result = PaymentsHistory()

page_number = 0
cursor = None
while page_number < max_pages:
if page_number > 0: sleep(1)
resp = self.payment_history(cursor = cursor)

if not resp.items:
Expand All @@ -353,6 +356,10 @@ def payment_history_filtered(
# Enough results collected
break

if len(result.items) >= max_results:
# Enough results collected
break

cursor = resp.paginate.nextCursor
if not cursor:
# No more pages
Expand Down
2 changes: 1 addition & 1 deletion pyCryptomusAPI/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Versions should comply with PEP440.
# This line is parsed in setup.py:
__version__ = '0.0.2'
__version__ = '0.0.3'

0 comments on commit dcb051a

Please sign in to comment.