Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonmellone/99835d48471c3c65dce0c043a0b04bce to your computer and use it in GitHub Desktop.
Save jasonmellone/99835d48471c3c65dce0c043a0b04bce to your computer and use it in GitHub Desktop.
Adding endpoints that are not part of the cbpro library.
import datetime
import json
import time
import cbpro.authenticated_client as cbpro_authenticated_client
class Extended_AuthenticatedClient(cbpro_authenticated_client.AuthenticatedClient):
def __init__(self, key, b64secret, passphrase):
super().__init__(key=key, b64secret=b64secret, passphrase=passphrase)
def get_all_deposits(self, deposit_type='deposit', profile_id=None,sleep=True):
"""
Get all deposits of a certain type.
Parameters
----------
deposit_type
profile_id
Returns
-------
"""
out = []
before = datetime.datetime.now()
while True:
deposits = self.get_deposits(deposit_type=deposit_type, profile_id=profile_id, before=before, after=None)
out += deposits
if len(deposits) < 100:
return out
before = out[-1]['created_at']
if sleep:
time.sleep(2)
def get_deposits(self, deposit_type='deposit', profile_id=None, before=None, after=None):
"""
type No Set to deposit or internal_deposit (transfer between portfolios)
profile_id No Limit list of deposits to this profile_id. By default, it retrieves deposits using default profile
before No If before is set, then it returns deposits created after the before timestamp, sorted by oldest creation date
after No If after is set, then it returns deposits created before the after timestamp, sorted by newest
limit No Truncate list to this many deposits, capped at 100. Default is 100.
Returns
-------
"""
params = {'type': deposit_type}
if profile_id is not None:
params['profile_id'] = profile_id
if before is not None:
assert isinstance(before, datetime.datetime), 'before must be datetime object'
params['before'] = before.isoformat()
if after is not None:
assert isinstance(after, datetime.datetime), 'after must be datetime object'
params['after'] = after.isoformat()
out = self._send_message('get', '/transfers', data=json.dumps(params))
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment