Real Time Data Offline Coinbase Pro
Level: Bones
Prerequisites: Local development environs
Objective: The Coinbase API offers a variety of useful bitcoin-related data. One uncomplicated datapoint that is often of interest is the price of bitcoin. In this guide we'll walk through how to brand a asking to Coinbase's prices endpoint in order to recollect current bitcoin price information.
Featured Developer: Lawnmower
The prices endpoint is part of a broader category of unauthenticated, read-simply endpoints called Information Endpoints. As a upshot, authentication is not required to retrieve price information.
Before jumping into the code, know that there are three different prices bachelor from the prices endpoint:
- Purchase cost
- Sell price
- Spot cost
As with whatsoever data, it is of import to sympathise the difference between these prices and to request the data that is almost appropriate for your needs. In this case, let's imagine that you want just to bear witness your users the current bitcoin market price (also known as the "bitcoin spot cost"), reflected in the US dollar equivalent.
Getting the spot price is quite simple. First, let'due south take a wait at a naked scroll asking. Notation that you tin substitute whatever supported currency lawmaking for USD.
curl https://api.coinbase.com/v2/prices/spot?currency=USD Instance response:
{ "information": { "amount": "1015.00", "currency": "USD" } } Easy, correct? However, in most situations, you're going to desire to be able to take hold of the cost information from within your code (i.e., not using whorl). Let's take a await at using one of the [official Coinbase libraries](/sign in-with-coinbase/docs/client-libraries). Starting time, install the library:
gem install coinbase pip install coinbase # or easy_install coinbase npm install coinbase Now, allow's retrieve that price information:
require 'coinbase/wallet' customer = Coinbase::Wallet::Customer.new(api_key: <api key>, api_secret: <api surreptitious>, CB_VERSION: 'YYYY-MM-DD') currency_code = 'USD' # can also apply EUR, CAD, etc. # Make the request price = customer.spot_price({currency: currency_code}) puts "Current bitcoin price in #{currency_code}: #{price.amount}" from coinbase.wallet.client import Client client = Client(<api_key>, <api_secret>, api_version='YYYY-MM-DD') currency_code = 'USD' # can also use EUR, CAD, etc. # Make the asking price = client.get_spot_price(currency=currency_code) print 'Electric current bitcoin price in %s: %s' % (currency_code, price.amount) var Customer = require('coinbase').Customer; var client = new Customer({ 'apiKey': 'API Fundamental', 'apiSecret': 'API Cloak-and-dagger', 'version':'YYYY-MM-DD' }); currencyCode = 'USD' // can also apply EUR, CAD, etc. // Make the asking client.getSpotPrice({'currency': currencyCode}, part(err, cost) { console.log('Current bitcoin price in ' + currencyCode + ': ' + cost.information.amount); }); If everything went smoothly, you should encounter the current spot cost of bitcoin in USD. Now, let's run into what nosotros can do with that information.
You can way your display of toll data however you'd like. All the same, when choosing how to display bitcoin toll information, it's of import to consider what your users' needs are.
Lawnmower is a bitcoin investment app congenital on the Coinbase API. As with most investment apps, their users are interested in stats regarding the performance of their investments. Particularly, users are most interested in the current value of their bitcoin holdings (substantially, how much they'd be able to sell their bitcoin for at the electric current moment).
As you tin can see above, Lawnmower'south app displays the current bitcoin sell price every bit Current Coinbase exchange rate. This way, users tin can speedily estimate the electric current value of their holdings and also quickly get a finger on the pulse of the bitcoin market.
Congratulations!
In this short guide, you lot accept:
- Analyzed the
Datacategory of API endpoints and selectedSpot Price - Executed a cURL request for
Spot Toll - Installed a Coinbase customer library to run the same request from lawmaking
- Considered how to display the information retrieved
For additional information, don't hesitate to visit our various API aid channels:
- Stack Overflow where we monitor the Coinbase tag
Updated x months ago
Source: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/price-data

0 Response to "Real Time Data Offline Coinbase Pro"
Post a Comment