Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # get_data.py
- # ...
- # Continually fetch new trades until our LIMIT is reached
- next_trade_id = None
- iter_count = 0
- while True:
- # Fetch a set of trades
- params = {}
- if next_trade_id:
- params['after'] = next_trade_id
- r = requests.get(URL, params=params)
- # Transform each received trade into our desired format
- new_trades = [transform_trade(trade) for trade in r.json()]
- # Append the new_trades to the dataframe
- trades.append(new_trades, ignore_index=True)
- # Update the user
- new_trade_count = len(new_trades)
- print(f'Fetched {new_trade_count} trades, total count: {trade_count}...')
- # Check the number of iterations
- iter_count += 1
- if iter_count >= ITER_LIMIT:
- print(f'Reached iteration limit {ITER_LIMIT}, stopping trade fetching...')
- break
- # Get the cursor to the next page
- if NEXT_PAGE_HEADER not in r.headers:
- print('No more pages, stopping trade fetching...')
- break
- next_trade_id = r.headers[NEXT_PAGE_HEADER]
- # Check the length of the dataframe to see if we've reached our goal yet
- trade_count = len(trades.index)
- if trade_count >= LIMIT:
- print('Reached trade limit, stopping trade fetching...')
- break
Add Comment
Please, Sign In to add comment