https://developers.coinbase.com/api/v2#buy-bitcoin
482597
def buy(self, account_id, **params):
        """"""
        if 'amount' not in params and 'total' not in params:
            raise ValueError("Missing required parameter: 'amount' or 'total'")
        for required in ['currency', 'payment_method']:
            if required not in params:
                raise ValueError("Missing required parameter: %s" % required)
        response = self._post('v2', 'accounts', account_id, 'buys', data=params)
        return self._make_api_object(response, Buy)
1034772
def push(self, tx):
        
        self._service.push_tx(tx)
        return bitcoin.txhash(tx)
789916
def commit_buy(self, account_id, buy_id, **params):
        """"""
        response = self._post(
            'v2', 'accounts', account_id, 'buys', buy_id, 'commit', data=params)
        return self._make_api_object(response, Buy)
16870
def create_hd_wallet(wallet_name, xpubkey, api_key, subchain_indices=[], coin_symbol='btc'):
    '''
    
    '''
    inferred_coin_symbol = coin_symbol_from_mkey(mkey=xpubkey)
    if inferred_coin_symbol:
        assert inferred_coin_symbol == coin_symbol
    assert api_key, 'api_key required'
    assert len(wallet_name) <= 25, wallet_name

    data = {
            'name': wallet_name,
            'extended_public_key': xpubkey,
            }
    params = {'token': api_key}

    if subchain_indices:
        data['subchain_indexes'] = subchain_indices

    url = make_url(coin_symbol, **dict(wallets='hd'))

    r = requests.post(url, json=data, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    return get_valid_json(r)
288382
def withdraw(self, account_id, **params):
        """"""
        for required in ['payment_method', 'amount', 'currency']:
            if required not in params:
                raise ValueError("Missing required parameter: %s" % required)
        response = self._post('v2', 'accounts', account_id, 'withdrawals', data=params)
        return self._make_api_object(response, Withdrawal)
517195
def get_sell(self, account_id, sell_id, **params):
        """"""
        response = self._get(
            'v2', 'accounts', account_id, 'sells', sell_id, params=params)
        return self._make_api_object(response, Sell)
102399
def get_transactions_details(tx_hash_list, coin_symbol='btc', limit=None, api_key=None):
    

    for tx_hash in tx_hash_list:
        assert is_valid_hash(tx_hash)
    assert is_valid_coin_symbol(coin_symbol)

    if len(tx_hash_list) == 0:
        return []
    elif len(tx_hash_list) == 1:
        return [get_transaction_details(tx_hash=tx_hash_list[0],
                                        coin_symbol=coin_symbol,
                                        limit=limit,
                                        api_key=api_key
                                        )]

        url = make_url(coin_symbol, **dict(txs=';'.join(tx_hash_list)))

    params = {}
    if api_key:
        params['token'] = api_key
    if limit:
        params['limit'] = limit

    r = requests.get(url, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    response_dict_list = get_valid_json(r)

    cleaned_dict_list = []

    for response_dict in response_dict_list:
        if 'error' not in response_dict:
            if response_dict['block_height'] > 0:
                response_dict['confirmed'] = parser.parse(response_dict['confirmed'])
            else:
                # Blockcypher reports fake times if it's not in a block
                response_dict['confirmed'] = None
                response_dict['block_height'] = None

            # format this string as a datetime object
            response_dict['received'] = parser.parse(response_dict['received'])
        cleaned_dict_list.append(response_dict)

    return cleaned_dict_list
973623
def get_wallet_balance(wallet_name, api_key, omit_addresses=False, coin_symbol='btc'):
    '''
    
    '''
    assert is_valid_coin_symbol(coin_symbol)
    assert api_key
    assert len(wallet_name) <= 25, wallet_name
    assert isinstance(omit_addresses, bool), omit_addresses

    params = {'token': api_key}
    if omit_addresses:
        params['omitWalletAddresses'] = 'true'

    url = make_url(coin_symbol, 'addrs/{}/balance'.format(wallet_name))

    r = requests.get(url, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    return get_valid_json(r)
169694
def get_transaction(self, account_id, transaction_id, **params):
        """"""
        response = self._get(
            'v2', 'accounts', account_id, 'transactions', transaction_id, params=params)
        return self._make_api_object(response, Transaction)
105258
function composeCoinbaseJoint(from_address, coinbase_address, round_index, coinbase_amount, signer, callbacks){
	var coinbase_foundation_amount = Math.floor(coinbase_amount*constants.FOUNDATION_RATIO);
	composeJoint({
		paying_addresses: [from_address],
		outputs: [{address: coinbase_address, amount: 0}, {address: constants.FOUNDATION_ADDRESS, amount: coinbase_foundation_amount}],
		//inputs: [{type: "coinbase", amount: coinbase_amount, address: from_address}],
		inputs: [{type: "coinbase", amount: coinbase_amount}],
		round_index: round_index,
		input_amount: coinbase_amount,
		pow_type: constants.POW_TYPE_COIN_BASE,
		signer: signer,
		callbacks: callbacks
	});
}
1024152
function DoVFTSale($ccno,
                       $expdate,
                       $cvc,
                       $orderid,
                       $amount,
                       $currency,
                       $instnumber,
                       $vftcode) {

        $posnetRequest = new PosnetRequest();

        $posnetRequest->ccno = $ccno;
        $posnetRequest->expdate = $expdate;
        $posnetRequest->cvc = $cvc;
        $posnetRequest->orderid = $orderid;
        $posnetRequest->amount = $amount;
        $posnetRequest->currency = $currency;
        $posnetRequest->instnumber = $instnumber;
        $posnetRequest->vftcode = $vftcode;
        $posnetRequest->koicode = $this->koicode;

        return $this->DoTran($posnetRequest, "vftsale");
    }
571457
protected function buildBitCoinString()
    {
        $query = http_build_query([
            'amount'    => $this->amount,
            'label'     => $this->label,
            '$message'  => $this->message,
            'r'         => $this->returnAddress,
        ]);

        $btc = $this->prefix.$this->address.'?'.$query;

        return $btc;
    }
331866
def put_metadata(metadata_dict, address=None, tx_hash=None, block_hash=None, api_key=None, private=True, coin_symbol='btc'):
    '''
    
    '''
    assert is_valid_coin_symbol(coin_symbol), coin_symbol
    assert api_key
    assert metadata_dict and isinstance(metadata_dict, dict), metadata_dict

    kwarg = get_valid_metadata_identifier(
        coin_symbol=coin_symbol,
        address=address,
        tx_hash=tx_hash,
        block_hash=block_hash,
        )

    url = make_url(coin_symbol, meta=True, **kwarg)

    params = {'token': api_key}
    if private:
        params['private'] = 'true'

    r = requests.put(url, json=metadata_dict, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    return get_valid_json(r, allow_204=True)
1234576
def get_buy(self, account_id, buy_id, **params):
        """"""
        response = self._get('v2', 'accounts', account_id, 'buys', buy_id, params=params)
        return self._make_api_object(response, Buy)
398197
def ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
            return trade(currency_code, price, amount, "ask", limit, counter_currency_code)
        end
10343
function(bitcoin) {
    //validate arg
    var bitcoinType = typeof bitcoin;
    if (bitcoinType === 'string') {
      bitcoin = toNumber(bitcoin);
      bitcoinType = 'number';
    }
    if (bitcoinType !== 'number'){
      throw new TypeError('toSatoshi must be called on a number or string, got ' + bitcoinType);
    }

    var bigBitcoin = new Big(bitcoin);
    return Number(bigBitcoin.times(conversion));
  }
364525
async def get(self, public_key):
		
		# Sign-verifying functional
		if settings.SIGNATURE_VERIFICATION:
			super().verify()

		logging.debug("\n\n --  Input offers debugging")

		message = json.loads(self.get_argument("message"))
		cid = message.get("cid")
		coinid = message.get("coinid")
		if not cid:
			self.set_status(400)
			self.write({"error":400, "reason":"Missed required fields."})
			raise tornado.web.Finish


		account = await self.account.getaccountdata(public_key=public_key)
		if "error" in account.keys():
			self.set_status(account["error"])
			self.write(account)
			raise tornado.web.Finish

		if coinid in settings.bridges.keys():
			self.account.blockchain.setendpoint(settings.bridges[coinid])
		offers = await self.account.blockchain.getcidoffers(cid=cid)
		logging.debug("\n\n -- Offers")
		logging.debug(offers)

		if isinstance(offers, dict):
			self.set_status(offers["error"])
			self.write(offers)
			raise tornado.web.Finish

		for offer in offers:
			offer["type"] = self.account.ident_offer[offer["type"]]

		storage_offers = await self.account.getoffers(cid=cid, coinid=coinid)
		logging.debug("\n\n -- Storage offers. ")
		logging.debug(storage_offers)

		self.write(json.dumps(offers + storage_offers))