def get_user_details(self): """ Retrieve the current user's details :return: CoinbaseUser object with user details """ url = COINBASE_ENDPOINT_URL + USERS_URL self._update_session_headers(url) response = self.session.get(url) results = response.json() user_details = results['users'][0]['user'] #Convert our balance and limits to proper amounts balance = CoinbaseAmount(user_details['balance']['amount'], user_details['balance']['currency']) buy_limit = CoinbaseAmount(user_details['buy_limit']['amount'], user_details['buy_limit']['currency']) sell_limit = CoinbaseAmount(user_details['sell_limit']['amount'], user_details['sell_limit']['currency']) user = CoinbaseUser(user_id=user_details['id'], name=user_details['name'], email=user_details['email'], time_zone=user_details['time_zone'], native_currency=user_details['native_currency'], balance=balance, buy_level=user_details['buy_level'], sell_level=user_details['sell_level'], buy_limit=buy_limit, sell_limit=sell_limit) return user
def balance(self): """ Retrieve coinbase's account balance :return: CoinbaseAmount (float) with currency attribute """ url = COINBASE_ENDPOINT + '/account/balance' response = self.session.get(url, params=self.global_request_params) results = response.json() return CoinbaseAmount(results['amount'], results['currency'])
def balance(self): """ Retrieve coinbase's account balance :return: CoinbaseAmount (float) with currency attribute """ url = COINBASE_ENDPOINT_URL + ACCOUNT_BALANCE_URL self._update_session_headers(url) response = self.session.get(url) results = response.json() return CoinbaseAmount(results['amount'], results['currency'])
def sell_price(self, qty=1): """ Return the sell price of BitCoin in USD :param qty: Quantity of BitCoin to price :return: CoinbaseAmount (float) with currency attribute """ url = COINBASE_ENDPOINT_URL + PRICES_SELL_URL params = {'qty': qty} self._update_session_headers(url) response = self.session.get(url, params=params) results = response.json() return CoinbaseAmount(results['amount'], results['currency'])
def sell_price(self, qty=1): """ Return the sell price of BitCoin in USD :param qty: Quantity of BitCoin to price :return: CoinbaseAmount (float) with currency attribute """ url = COINBASE_ENDPOINT + '/prices/sell' params = {'qty': qty} params.update(self.global_request_params) response = self.session.get(url, params=params) results = response.json() return CoinbaseAmount(results['amount'], results['currency'])
def setUp(self): mock_http('GET https://coinbase.com/api/v1/account/balance', response_body) def test_balance_with_key(self): account = account_setup.with_key() this(account.balance).should.equal(expected_balance) this(last_request_params()).should.equal( {'api_key': [account_setup.api_key]}) def test_balance_with_oauth(self): account = account_setup.with_oauth() this(account.balance).should.equal(expected_balance) this(last_request_params()).should.equal({}) response_body = """ { "amount": "1.00000000", "currency": "BTC" } """ expected_balance = CoinbaseAmount('1.0', 'BTC') def test_url_injection_attempt(): account = account_setup.with_oauth() this(lambda: account.get_order('../account/balance')) \ .should.throw(UrlValueError)
def test_currency(): this(CoinbaseAmount('1.063', 'BTC').currency).should.equal('BTC')
def test_amount(): this(CoinbaseAmount('1.063', 'BTC').amount).should.equal(Decimal('1.063'))
def test_str_or_decimal(): this(CoinbaseAmount(Decimal('1.063'), 'BTC')) \ .should.equal(CoinbaseAmount('1.063', 'BTC'))