예제 #1
0
    def transactions(self, count=30):
        """
        Retrieve the list of transactions for the current account
        :param count: How many transactions to retrieve
        :return: List of CoinbaseTransaction objects
        """
        url = COINBASE_ENDPOINT + '/transactions'
        pages = count / 30 + 1
        transactions = []

        reached_final_page = False

        for page in xrange(1, pages + 1):

            if not reached_final_page:
                params = {'page': page}
                params.update(self.global_request_params)
                response = self.session.get(url=url, params=params)
                parsed_transactions = response.json()

                if parsed_transactions['num_pages'] == page:
                    reached_final_page = True

                for transaction in parsed_transactions['transactions']:
                    transactions.append(
                        CoinbaseTransaction(transaction['transaction']))

        return transactions
예제 #2
0
    def transactions(self, count=30):
        """
        Retrieve the list of transactions for the current account
        :param count: How many transactions to retrieve
        :return: List of CoinbaseTransaction objects
        """
        url = COINBASE_ENDPOINT_URL + TRANSACTIONS_URL
        pages = count / 30 + 1
        transactions = []

        reached_final_page = False

        for page in xrange(1, pages + 1):
            if not reached_final_page:
                request_data = json.dumps({'page': page})
                self._update_session_headers(url, request_data)
                response = self.session.get(url=url, data=request_data)
                parsed_transactions = response.json()
                if parsed_transactions[
                        'num_pages'] == page or parsed_transactions[
                            'num_pages'] == 0:
                    reached_final_page = True

                for transaction in parsed_transactions['transactions']:
                    transactions.append(
                        CoinbaseTransaction(transaction['transaction']))

        return transactions
예제 #3
0
    def get_transaction(self, transaction_id):
        """
        Retrieve a transaction's details
        :param transaction_id: Unique transaction identifier
        :return: CoinbaseTransaction object with transaction details
        """
        url = COINBASE_ENDPOINT + '/transactions/' + str(transaction_id)
        response = self.session.get(url, params=self.global_request_params)
        results = response.json()

        if results.get('success', True) == False:
            pass
            #TODO:  Add error handling

        return CoinbaseTransaction(results['transaction'])
예제 #4
0
    def get_transaction(self, transaction_id):
        """
        Retrieve a transaction's details
        :param transaction_id: Unique transaction identifier
        :return: CoinbaseTransaction object with transaction details
        """
        url = COINBASE_ENDPOINT_URL + TRANSACTIONS_URL + '/' + str(
            transaction_id)
        self._update_session_headers(url)
        response = self.session.get(url)
        results = response.json()

        if not results.get('success', True):
            pass
            #TODO:  Add error handling

        return CoinbaseTransaction(results['transaction'])
예제 #5
0
    def send(self,
             to_address,
             amount,
             notes='',
             currency='BTC',
             transaction_params=dict()):
        """
        Send BitCoin from this account to either an email address or a BTC address
        :param to_address: Email or BTC address to where coin should be sent
        :param amount: Amount of currency to send
        :param notes: Notes to be included with transaction
        :param currency: Currency to send
        :return: CoinbaseTransaction with status and details
        """
        url = COINBASE_ENDPOINT + '/transactions/send_money'

        if currency == 'BTC':
            request_data = {
                "transaction": {
                    "to": to_address,
                    "amount": amount,
                    "notes": notes
                }
            }
        else:

            request_data = {
                "transaction": {
                    "to": to_address,
                    "amount_string": str(amount),
                    "amount_currency_iso": currency,
                    "notes": notes
                }
            }

        request_data['transaction'].update(transaction_params)
        response = self.session.post(url=url,
                                     data=json.dumps(request_data),
                                     params=self.global_request_params)
        response_parsed = response.json()
        if response_parsed['success'] == False:
            raise RuntimeError(
                'Transaction Failed: %s' %
                response_parsed.get('errors', 'no errors returned'))

        return CoinbaseTransaction(response_parsed['transaction'])
예제 #6
0
    def request(self, from_email, amount, notes='', currency='BTC'):
        """
        Request BitCoin from an email address to be delivered to this account
        :param from_email: Email from which to request BTC
        :param amount: Amount to request in assigned currency
        :param notes: Notes to include with the request
        :param currency: Currency of the request
        :return: CoinbaseTransaction with status and details
        """
        url = COINBASE_ENDPOINT + '/transactions/request_money'

        if currency == 'BTC':
            request_data = {
                "transaction": {
                    "from": from_email,
                    "amount": amount,
                    "notes": notes
                }
            }
        else:
            request_data = {
                "transaction": {
                    "from": from_email,
                    "amount_string": str(amount),
                    "amount_currency_iso": currency,
                    "notes": notes
                }
            }

        response = self.session.post(url=url,
                                     data=json.dumps(request_data),
                                     params=self.global_request_params)
        response_parsed = response.json()
        if response_parsed['success'] == False:
            pass
            #DO ERROR HANDLING and raise something

        return CoinbaseTransaction(response_parsed['transaction'])
예제 #7
0
    def send(self, to_address, amount, notes='', currency='BTC'):
        """
        Send BitCoin from this account to either an email address or a BTC address
        :param to_address: Email or BTC address to where coin should be sent
        :param amount: Amount of currency to send
        :param notes: Notes to be included with transaction
        :param currency: Currency to send
        :return: CoinbaseTransaction with status and details
        """
        url = COINBASE_ENDPOINT_URL + TRANSACTIONS_SEND_MONEY

        if currency == 'BTC':
            request_data = json.dumps({
                "transaction": {
                    "to": to_address,
                    "amount": amount,
                    "notes": notes
                }
            })
        else:
            request_data = json.dumps({
                "transaction": {
                    "to": to_address,
                    "amount_string": str(amount),
                    "amount_currency_iso": currency,
                    "notes": notes
                }
            })
        self._update_session_headers(url, request_data)
        response = self.session.post(url=url, data=request_data)
        response_parsed = response.json()

        if not response_parsed['success']:
            raise RuntimeError('Transaction Failed')

        return CoinbaseTransaction(response_parsed['transaction'])
예제 #8
0
    def request(self, from_email, amount, notes='', currency='BTC'):
        """
        Request BitCoin from an email address to be delivered to this account
        :param from_email: Email from which to request BTC
        :param amount: Amount to request in assigned currency
        :param notes: Notes to include with the request
        :param currency: Currency of the request
        :return: CoinbaseTransaction with status and details
        """
        url = COINBASE_ENDPOINT_URL + TRANSACTIONS_REQUEST_MONEY_URL

        if currency == 'BTC':
            request_data = json.dumps({
                "transaction": {
                    "from": from_email,
                    "amount": amount,
                    "notes": notes
                }
            })
        else:
            request_data = json.dumps({
                "transaction": {
                    "from": from_email,
                    "amount_string": str(amount),
                    "amount_currency_iso": currency,
                    "notes": notes
                }
            })
        self._update_session_headers(url, request_data)
        response = self.session.post(url=url, data=request_data)
        response_parsed = response.json()
        if not response_parsed['success']:
            pass
            #DO ERROR HANDLING and raise something

        return CoinbaseTransaction(response_parsed['transaction'])