{"id":6105,"date":"2020-11-25T18:46:51","date_gmt":"2020-11-25T18:46:51","guid":{"rendered":"http:\/\/algotrading101.com\/learn\/?p=6105"},"modified":"2023-04-03T21:13:33","modified_gmt":"2023-04-03T21:13:33","slug":"coinbase-api-guide","status":"publish","type":"post","link":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/","title":{"rendered":"Coinbase API &#8211; A Introduction Guide"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_6105\" class=\"pvc_stats total_only  \" data-element-id=\"6105\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"600\" height=\"300\" src=\"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/Coinbase-Guide.png\" alt=\"Coinbase Logo\" class=\"wp-image-6569\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/Coinbase-Guide.png 600w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/Coinbase-Guide-300x150.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Table of contents:<\/h3>\n\n\n\n<ol><li><a href=\"#what-is-coinbase-api\">What is Coinbase API?<\/a><\/li><li><a href=\"#what-is-coinbase\">What is Coinbase?<\/a><ul><li><a href=\"#what-can-i-trade-coinbase-tradable-assets\">What can I trade on Coinbase?<\/a><\/li><li><a href=\"#what-are-pricing-fees-coinbase\">What are the pricing and fees of Coinbase?<\/a><\/li><\/ul><\/li><li><a href=\"#why-should-i-use-coinbase-api\">&nbsp;Why should I use Coinbase API?<\/a><\/li><li><a href=\"#why-shouldnt-i-use-coinbase-api\">Why shouldn\u2019t I use Coinbase API?<\/a><\/li><li><a href=\"#what-alternatives-are-there-to-coinbase-api\">What alternatives are there to Coinbase API?<\/a><\/li><li><a href=\"#what-account-types-coinbase-api\">What are the account types for Coinbase API?<\/a><\/li><li><a href=\"#what-are-the-libraries-for-the-coinbase-api\">What are the libraries for the Coinbase API?<\/a><\/li><li><a href=\"#how-to-get-started-with-the-coinbase-api\">How to get started with the Coinbase API?<\/a><\/li><li><a href=\"#how-do-i-retrieve-my-account-balance-using-the-coinbase-api\">How do I retrieve my account balance using the Coinbase API?<\/a><\/li><li><a href=\"#how-to-get-real-time-price-data-for-bitcoin-using-coinbase-api\">How to get real time price data for Bitcoin using Coinbase API?<\/a><\/li><li><a href=\"#how-to-retrieve-spot-price-data-with-the-coinbase-api\">How to retrieve spot price data with the Coinbase API?<\/a><\/li><li><a href=\"#how-to-retrieve-historical-data-using-the-coinbase-api\">How to retrieve historical data using the Coinbase API?<\/a><\/li><li><a href=\"#how-to-access-technical-indicators-such-as-the-20-sma-with-the-coinbase-api\">How to access technical indicators such as the 20 SMA with the Coinbase API?<\/a><\/li><li><a href=\"#how-to-send-and-receive-bitcoin-with-the-coinbase-api\">How to send and receive Bitcoin with the Coinbase API?<\/a><\/li><li><a href=\"#how-to-buy-and-sell-bitcoin-with-the-coinbase-api\">How to buy and sell Bitcoin with the Coinbase API?<\/a><\/li><li><a href=\"#what-are-access-and-refresh-tokens-in-the-coinbase-api\">What are access and refresh tokens in the Coinbase API?<\/a><\/li><li><a href=\"#potential-errors-and-warning\">Potential errors and warning<\/a><\/li><li><a href=\"#download-code-coinbase-api\">Download Code<\/a><\/li><\/ol>\n\n\n\n<div style=\"padding:15px 15px 15px 15px;color: #555555;background-color: #E1FFC1;border: #dddddd 2px solid\"><p>\u00bb If you are looking for the guide for <strong>Coinbase Pro API<\/strong>, check this out instead: \n\n<br><br>\n\nLink: <strong><a href=\"https:\/\/algotrading101.com\/learn\/coinbase-pro-api-guide\/\">Coinbase Pro API \u2013 An Introductory Guide<\/a><\/strong>\n\n<\/p>\n<\/div>\n\n\n\n<a name=\"what-is-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\">What is Coinbase API?<\/h2>\n\n\n\n<p>Coinbase API is a method for us to trade cryptocurrencies on Coinbase automatically via code.<\/p>\n\n\n\n<p>Link: <a href=\"https:\/\/www.coinbase.com\">https:\/\/www.coinbase.com<\/a><\/p>\n\n\n\n<a name=\"what-is-coinbase\">\n\n\n\n<h2 class=\"wp-block-heading\">What is Coinbase?<\/h2>\n\n\n\n<p>Coinbase is a trading platform allows us to buy, sell and store cryptocurrencies.<\/p>\n\n\n\n<p>Coinbase also provides a Coinbase Mobile App which is available on IOS and Android. Their mobile app provides users with the possibility to trade on the go. Their services are widely available counting up to more than 100 countries.<\/p>\n\n\n\n<p>Here are some user and revenue statistics about Coinbase: <a href=\"https:\/\/www.wallstreetzen.com\/stocks\/us\/nasdaq\/coin\/statistics\" target=\"_blank\" rel=\"noreferrer noopener\">Coinbase Statistics<\/a>.<\/p>\n\n\n\n<a name=\"what-can-i-trade-coinbase-tradable-assets\">\n\n\n\n<h3 class=\"wp-block-heading\">What can I trade on Coinbase?<\/h3>\n\n\n\n<p>When it comes to the tradable assets, Coinbase offers various cryptocurrencies like: <\/p>\n\n\n\n<ul><li>Bitcoin<\/li><li>Ethereum<\/li><li>Bitcoin Cash<\/li><li>XRP<\/li><li>Litecoin<\/li><li>Dash<\/li><li>EOS<\/li><li>Tezos<\/li><li>Augur<\/li><li>Stellar<\/li><li>USD Coin<\/li><li>Ethereum Classic<\/li><li>Chainlink, and many more.<\/li><\/ul>\n\n\n\n<a name=\"what-are-pricing-fees-coinbase\">\n\n\n\n<h3 class=\"wp-block-heading\">What are the pricing and fees of Coinbase?<\/h3>\n\n\n\n<p>If you want to learn about the pricing and fees of Coinbase which depend on things like your location and transactions, check out this link: <a href=\"https:\/\/help.coinbase.com\/en\/coinbase\/trading-and-funding\/pricing-and-fees\/fees\">https:\/\/help.coinbase.com\/en\/coinbase\/trading-and-funding\/pricing-and-fees\/fees<\/a><\/p>\n\n\n\n<p>The example for the fees that Coinbase gives us is the following:<\/p>\n\n\n\n<ul><li>If the total transaction amount is less than or equal to $10, the fee is $0.99 | \u20ac0,99 | \u00a30,99&nbsp;<\/li><li>If the total transaction amount is more than $10 but less than or equal to $25, the fee is $1.49 | \u20ac1,49 | \u00a31,49<\/li><li>If the total transaction amount is more than $25 but less than or equal to $50, the fee is $1.99 |&nbsp;\u20ac1,99 | \u00a31,99<\/li><li>If the total transaction amount is more than $50 but less than or equal to $200, the fee is $2.99 | \u20ac2,99 | \u00a32,99<\/li><\/ul>\n\n\n\n<a name=\"why-should-i-use-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\">&nbsp;<strong>Why should I use Coinbase API?<\/strong><\/h2>\n\n\n\n<ul><li>Flexible Trading Platform<\/li><li>Has many trading tools such as the Coinbase Pro API<\/li><li>Provides educational materials<\/li><li>Good customer service<\/li><li>Offers a variety of more than 25 cryptocurrencies<\/li><li>The interface is easy to use<\/li><li>Has high liquidity exchanges<\/li><\/ul>\n\n\n\n<a name=\"why-shouldnt-i-use-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why shouldn\u2019t I use Coinbase API?<\/strong><\/h2>\n\n\n\n<ul><li>Not regulated in all countries<\/li><li>Only offers cryptocurrency trading<\/li><li>There are not any MetaTrader platforms<\/li><li>Doesn\u2019t offer online chat support<\/li><li>No official libraries<\/li><li>High fees (standard version is overpriced)<\/li><li>Coinbase Pro is severely lacking in features (i.e. only two EMA indicators available)<\/li><li>No control over the wallet key<\/li><li>Doesn&#8217;t offer all the altcoins that an altcoin trader would prefer<\/li><\/ul>\n\n\n\n<a name=\"what-alternatives-are-there-to-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What alternatives are there to Coinbase API?<\/strong><\/h2>\n\n\n\n<p>Coinbase API can be replaces with some alternatives and they are the following:<\/p>\n\n\n\n<ul><li>Gemini<\/li><li><a href=\"https:\/\/algotrading101.com\/learn\/binance-python-api-guide\/\">Binance<\/a><\/li><li>Kraken.io<\/li><li>CoinGate<\/li><li>CoinPaymets<\/li><li>GoCoin<\/li><li>Coinomi<\/li><li>Cryptopay<\/li><li>Blocknomics<\/li><li>Blockchain<\/li><li>BitPay and more\u2026<\/li><\/ul>\n\n\n\n<a name=\"what-are-the-libraries-for-the-coinbase-api\">\n\n\n\n<a name=\"what-account-types-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\">What are the account types for Coinbase API?<\/h2>\n\n\n\n<p>They also have 3 types of accounts with a minimum 1$ deposit (this can change depending on the account). <\/p>\n\n\n\n<p><strong>First type<\/strong><\/p>\n\n\n\n<p>The first one is your simple Coinbase API for beginners and individual traders. It has many usages and some of them are the following:<\/p>\n\n\n\n<ul><li>Generate bitcoin cash, bitcoin, litecoin and ethereum wallets and addresses.<\/li><li>Securely store the coins.<\/li><li>Obtain real-time and\/or historical price data.<\/li><li>Get notified when the payments arrive.<\/li><li>Send\/receive or sell\/buy bitcoin cash, bitcoin, litecoin and ethereum.<\/li><\/ul>\n\n\n\n<p>Here is a link to its full documentation: <a href=\"https:\/\/developers.coinbase.com\/\">https:\/\/developers.coinbase.com\/<\/a><\/p>\n\n\n\n<p><strong>Second type<\/strong><\/p>\n\n\n\n<p>The second one is the Coinbase Pro API that provides individual traders the ability to trade various assets. It has an intuitive and easy to use interface. <\/p>\n\n\n\n<p>This app is primarily built for advanced crytocurrency traders. Coinbase Pro API also has many tools like the following:<\/p>\n\n\n\n<ul><li>Order book and candlestick chart<\/li><li>Limit and market orders<\/li><li>Portfolio overview<\/li><\/ul>\n\n\n\n<p>Here is the link to the Coinbase Pro API documentation: <a href=\"https:\/\/docs.pro.coinbase.com\/#introduction\">https:\/\/docs.pro.coinbase.com<\/a><\/p>\n\n\n\n<p><strong>Third type<\/strong><\/p>\n\n\n\n<p>The third integration is the Coinbase Prime API that is a professional trading platform built for institutional traders. With it, they gain access to various liquidity pools for all Coinbase products. Its uses are aimed for the following types of traders:<\/p>\n\n\n\n<ul><li>Financial institutions<\/li><li>Liquidity providers<\/li><li>Crypto businesses<\/li><li>Asset Issuers<\/li><li>Institutional investors<\/li><\/ul>\n\n\n\n<p>On the following link you can learn more about the Coinbase Prime by reading the resources they offer: <a href=\"https:\/\/primebroker.coinbase.com\/resource-center\">https:\/\/primebroker.coinbase.com\/resource-center<\/a><\/p>\n\n\n\n<p>If you want to check out the Coinbase API GitHub repo, you can do it on the following link: <a href=\"https:\/\/github.com\/coinbase\/coinbase-python\">https:\/\/github.com\/coinbase\/coinbase-python<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What are the libraries for the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>Coinbase doesn\u2019t offer official libraries and the ones we can use are built by the community. The client libraries are the following:<\/p>\n\n\n\n<ul><li>Python<\/li><li>Java<\/li><li>Rust<\/li><li>C#<\/li><li>Go<\/li><li>Ruby<\/li><li>Node.js<\/li><li>Haskell<\/li><\/ul>\n\n\n\n<a name=\"how-to-get-started-with-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to get started with the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>In order to get started with the Coinbase API, we\u2019ll need to go over to their website (https:\/\/www.coinbase.com) and sign up for an account.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"942\" height=\"865\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Intro.jpg\" alt=\"\" class=\"wp-image-16279\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Intro.jpg 942w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Intro-300x275.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Intro-768x705.jpg 768w\" sizes=\"(max-width: 942px) 100vw, 942px\" \/><\/figure>\n\n\n\n<p>In the top right corner you\u2019ll see a \u201cGet started\u201d button that will take you to the account creation screen when you click it. After that, you\u2019ll enter your first and last name, email and password. When everything is written click the \u201cCreate account\u201d button.<\/p>\n\n\n\n<p>After that, you\u2019ll need to verify your email and add a mobile phone number for two-step authentication. Be sure to have your phone with you as you\u2019ll get a lot of authentication messages while following through this article.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"749\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/1-11.jpg\" alt=\"\" class=\"wp-image-16280\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/1-11.jpg 682w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/1-11-273x300.jpg 273w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><\/figure>\n\n\n\n<p>The next step is to obtain our API key. When you\u2019re all logged in, click on your profile icon in the top right corner and go to settings. From there, click on the API section and press the \u201c+ New API Key\u201d button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"694\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/apip-1024x694.jpg\" alt=\"\" class=\"wp-image-16281\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/apip-1024x694.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/apip-300x203.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/apip-768x520.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/apip.jpg 1352w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The following screen will appear:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"1000\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/api1.jpg\" alt=\"\" class=\"wp-image-16282\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/api1.jpg 558w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/api1-167x300.jpg 167w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/figure>\n\n\n\n<p>You\u2019ll select the type of account you want and permissions you\u2019ll have access to. For this article I\u2019ll select both accounts and all permissions. On the newly appeared window you can also select the notification URL and input allowed IP addresses.<\/p>\n\n\n\n<p>When you\u2019re done click create. Also, have in mind that you can create multiple API keys with your account. When created, you\u2019ll get your API key and API Secret.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"367\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/api2.jpg\" alt=\"\" class=\"wp-image-16283\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/api2.jpg 551w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/api2-300x200.jpg 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/figure>\n\n\n\n<p>For all of our next examples we\u2019ll be using Python, so let\u2019s go ahead and install the Coinbase API with the following command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>pip install coinbase<\/code><\/pre><\/div>\n\n\n\n<a name=\"how-do-i-retrieve-my-account-balance-using-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How do I retrieve my account balance using the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>Coinbase API allows us to retrieve our account balance but one at a time for each account. In the following example I\u2019ll show how we can add up all of those accounts to get a full account balance sum.<\/p>\n\n\n\n<p>Firstly, let\u2019s import the Coinbase API library with the following command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from coinbase.wallet.client import Client<\/code><\/pre><\/div>\n\n\n\n<p>The next step is to add our Coinbase API Key and the Coinbase API secret. After adding them we\u2019ll start the client and authenticate them:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>coinbase_API_key = \u201cYour API Key\u201d\ncoinbase_API_secret = \u201cYour API Secret\u201d\nclient = Client(coinbase_API_key, coinbase_API_secret)<\/code><\/pre><\/div>\n\n\n\n<p>After our client is running and the key is authenticated we\u2019ll specify the starting account balance upon which the summation process will begin.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>total = 0\nmessage = [ ]<\/code><\/pre><\/div>\n\n\n\n<p>Now, we\u2019ll get our accounts and for each wallet in our accounts data we\u2019ll append the wallet name and the native balance (USD). After that, each wallet will be added to the total sum and the total account balance message will be shown:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>accounts = client.get_accounts()\nfor wallet in accounts.data:\n    message.append( str(wallet[&#39;name&#39;]) + &#39; &#39; +   str(wallet[&#39;native_balance&#39;]) )\n    value = str( wallet[&#39;native_balance&#39;]).replace(&#39;USD&#39;,&#39;&#39;)\n    total += float(value)\nmessage.append( &#39;Total Balance: &#39; + &#39;USD &#39; + str(total) )\nprint (&#39;\\n&#39;.join( message ))<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"916\" height=\"483\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/account-balance.jpg\" alt=\"\" class=\"wp-image-16285\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/account-balance.jpg 916w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/account-balance-300x158.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/account-balance-768x405.jpg 768w\" sizes=\"(max-width: 916px) 100vw, 916px\" \/><\/figure>\n\n\n\n<a name=\"how-to-get-real-time-price-data-for-bitcoin-using-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to get real time price data for Bitcoin using Coinbase API?<\/strong><\/h2>\n\n\n\n<p>Getting real time prices with the Coinbase API is quite easy. The first thing we need to do is import the relevant library and authenticate our API key:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from coinbase.wallet.client import Client\ncoinbase_API_key = \u201cYour API Key\u201d\ncoinbase_API_secret = \u201cYour API Secret\u201d\nclient = Client(coinbase_API_key, coinbase_API_secret)\nNow, we\u2019ll specify the currency code we want to obtain:\ncurrency_code = \u201cEUR\u201d<\/code><\/pre><\/div>\n\n\n\n<p>Now, we\u2019ll specify the currency code we want to obtain:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>price = client.get_spot_price(currency=currency_code)\nprint (&#39;Current bitcoin price in %s: %s&#39; % (currency_code, price.amount))<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"361\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/Real-TIME.png\" alt=\"\" class=\"wp-image-5898\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/Real-TIME.png 799w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/Real-TIME-300x136.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/Real-TIME-768x347.png 768w\" sizes=\"(max-width: 799px) 100vw, 799px\" \/><\/figure>\n\n\n\n<a name=\"how-to-retrieve-spot-price-data-with-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to retrieve spot price data with the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>Retrieving spot price data with the Coinbase API is easy to do. For this example let\u2019s retrieve the historical Bitcoin to USD spot price for the 06.06.2020 date.<\/p>\n\n\n\n<p>As in our previous examples we\u2019ll import the library and authenticate the API key:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>coinbase_API_key = \u201cYour API Key\u201d\ncoinbase_API_secret = \u201cYour API Secret\u201d\nclient = Client(coinbase_API_key, coinbase_API_secret)<\/code><\/pre><\/div>\n\n\n\n<p>After this, let\u2019s ask for the spot price date of our asset with a specified date time:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>price = client.get_spot_price(currency_pair= &#39;BTC-USD&#39;, date=&#39;2020-06-06&#39;)<\/code><\/pre><\/div>\n\n\n\n<p>That\u2019s it. \ud83d\ude00<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"415\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/spot-price.jpg\" alt=\"\" class=\"wp-image-16286\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/spot-price.jpg 796w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/spot-price-300x156.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/spot-price-768x400.jpg 768w\" sizes=\"(max-width: 796px) 100vw, 796px\" \/><\/figure>\n\n\n\n<a name=\"how-to-retrieve-historical-data-using-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to retrieve historical data using the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>In this example we\u2019ll obtain the historical price data for Ethereum converted to the EUR value. In order to do this we\u2019ll import the relevant libraries and authorize our API key:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from coinbase.wallet.client import Client\nfrom coinbase.wallet.model import APIObject\ncoinbase_API_key = \u201cYour API Key\u201d\ncoinbase_API_secret = \u201cYour API Secret\u201d\nclient = Client(coinbase_API_Key, coinbase_API_Secret)<\/code><\/pre><\/div>\n\n\n\n<p>After that, we\u2019ll ask for the historical price data:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>client._make_api_object(client._get(&#39;v2&#39;, &#39;prices&#39;, &#39;ETH-EUR&#39;, &#39;historic&#39;), APIObject)<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"789\" height=\"686\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historical.png\" alt=\"\" class=\"wp-image-5901\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historical.png 789w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historical-300x261.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historical-768x668.png 768w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/figure>\n\n\n\n<p>Allow me to show you how to get historic rates using the Coinbase API Pro as I find it more thorough to use. Firstly, we\u2019ll need to install the Coinbase API Pro as it has its own library and documentation.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>pip install cbpro\nimport cbpro\npublic_client.get_product_ticker(product_id=&#39;ETH-USD&#39;)<\/code><\/pre><\/div>\n\n\n\n<p>Now, let\u2019s access the public client that the Coinbase API Pro.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>public_client = cbpro.PublicClient()<\/code><\/pre><\/div>\n\n\n\n<p>After this, let\u2019s obtain the list of products:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>public_client.get_products()<\/code><\/pre><\/div>\n\n\n\n<p>And check for the ticker we\u2019ll work on:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>public_client.get_product_ticker(product_id=&#39;ETH-USD&#39;)<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"754\" height=\"686\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/dhdh.png\" alt=\"\" class=\"wp-image-5904\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/dhdh.png 754w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/dhdh-300x273.png 300w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><\/figure>\n\n\n\n<p>Now, let\u2019s obtain the historic rates:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>data =public_client.get_product_historic_rates(&#39;ETH-USD&#39;)<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"603\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historicrates.png\" alt=\"\" class=\"wp-image-5902\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historicrates.png 781w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historicrates-300x232.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/historicrates-768x593.png 768w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><\/figure>\n\n\n\n<p>This data will lead us straight to the next chapter where we will discuss the simple moving average.<\/p>\n\n\n\n<a name=\"how-to-access-technical-indicators-such-as-the-20-sma-with-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to access technical indicators such as the 20 SMA with the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>In this example, I\u2019ll show you how to create the 20 SMA and access other technical indicators. Have in mind that this example is leaning on the previous one, so if you jumped to here, be sure to read the chapter above.<\/p>\n\n\n\n<p>For this to work, we\u2019ll import the following libraries:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import pandas as pd\nimport btalib\t<\/code><\/pre><\/div>\n\n\n\n<p>The <a href=\"https:\/\/btalib.backtrader.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">bta-lib library<\/a> is a technical indicator library made by the creator of the <a href=\"https:\/\/algotrading101.com\/learn\/backtrader-for-backtesting\/\">Backtrader backtesting framework<\/a>.<\/p>\n\n\n\n<p>Now, we shall only keep what we need from the obtain data and that is the date, high, low, open, close. We don\u2019t need the last column so let\u2019s get rid of it:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>for line in data:\n    del line[5:]<\/code><\/pre><\/div>\n\n\n\n<p>After it is cleaned, let\u2019s create a pandas data frame and name the columns:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>dataframe = pd.DataFrame(data, columns=[&#39;date&#39;, &#39;open&#39;, &#39;high&#39;, &#39;low&#39;, &#39;close&#39;])\ndataframe.set_index(&#39;date&#39;, inplace=True)\nprint(dataframe.head())<\/code><\/pre><\/div>\n\n\n\n<p>And let\u2019s save our data frame to a CSV file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>dataframe.to_csv(&#39;HistoricRates&#39;)<\/code><\/pre><\/div>\n\n\n\n<p>Pandas can do a lot of stuff and I\u2019m going to calculate the 20SMA with it first and then show you how to do it with the bta-lib that can access more indicators such as the RSI.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>dataframe[&#39;20sma&#39;] = dataframe.close.rolling(20).mean()\nprint(dataframe.tail(5))<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"279\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/20smacist.jpg\" alt=\"\" class=\"wp-image-16287\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/20smacist.jpg 723w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/20smacist-300x116.jpg 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/figure>\n\n\n\n<p>And the other one:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>sma = btalib.sma(dataframe.close)\nprint(sma.df)<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"475\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sma20cist1.jpg\" alt=\"\" class=\"wp-image-16288\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sma20cist1.jpg 470w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sma20cist1-297x300.jpg 297w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/figure>\n\n\n\n<p>As the bta-lib calculates the 30 simple moving average, we\u2019ll need to change it. And while at it, let\u2019s add it to our data frame some we can compare the two 20 SMA:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>dataframe[&#39;sma&#39;] = btalib.sma(dataframe.close, period=20).df\nprint(dataframe.tail())<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"674\" height=\"239\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/smacomp.jpg\" alt=\"\" class=\"wp-image-16289\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/smacomp.jpg 674w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/smacomp-300x106.jpg 300w\" sizes=\"(max-width: 674px) 100vw, 674px\" \/><\/figure>\n\n\n\n<a name=\"how-to-send-and-receive-bitcoin-with-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to send and receive Bitcoin with the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>In order to receive or send Bitcoin with the Coinbase API we\u2019ll need to go through the following steps:<\/p>\n\n\n\n<ul><li>Generate a bitcoin address in order to receive funds<\/li><li>Send funds from the Coinbase wallet to a bitcoin address or email<\/li><li>Request funds via email address<\/li><\/ul>\n\n\n\n<p>Let\u2019s start by creating our bitcoin address for the primary wallet. Firstly, we\u2019ll add the required library and authenticate the API key and secret:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>coinbase_API_key = \u201cYour API Key\u201d\ncoinbase_API_secret = \u201cYour API Secret\u201d\nclient = Client(coinbase_API_key, coinbase_API_secret)<\/code><\/pre><\/div>\n\n\n\n<p>Now, let\u2019s create a primary account address:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>primary_account = client.get_primary_account()\naddress = primary_account.create_address()\nprint (address)<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"798\" height=\"848\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Address.jpg\" alt=\"\" class=\"wp-image-16290\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Address.jpg 798w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Address-282x300.jpg 282w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/Address-768x816.jpg 768w\" sizes=\"(max-width: 798px) 100vw, 798px\" \/><\/figure>\n\n\n\n<p>After creating the address we can send funds to it. With the following code we\u2019ll be able to send the funds to our primary wallet:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>primary_account = client.get_primary_account()\n\nsend = primary_account.send_money(to=address,\n                                amount=&#39;0.01&#39;,\n                                currency=&#39;BTC&#39;)<\/code><\/pre><\/div>\n\n\n\n<p>If we want to receive funds the code is similar with a few alterations. We can even specify an email or an address for our request:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>primary_account = client.get_primary_account()\n\ntx = primary_account.request_money(to=\u2019random@gmail.com\u2019,\n                                   amount=&#39;0.1&#39;,\n                                   currency=&#39;BTC&#39;)<\/code><\/pre><\/div>\n\n\n\n<p>Another and easier way is to log in to your Coinbase profile and in the upper right corner click send or receive. After that a window will pop-up asking you to specify to whom, add a note, and payment type.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"450\" height=\"682\" data-id=\"16291\"  src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/send-2.jpg\" alt=\"\" class=\"wp-image-16291\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/send-2.jpg 450w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/send-2-198x300.jpg 198w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"445\" height=\"652\" data-id=\"16292\"  src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/receive.jpg\" alt=\"\" class=\"wp-image-16292\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/receive.jpg 445w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/receive-205x300.jpg 205w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/figure>\n<\/figure>\n\n\n\n<a name=\"how-to-buy-and-sell-bitcoin-with-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to buy and sell Bitcoin with the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>As in our previous examples we\u2019ll import the library and authorize our API key:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>from coinbase.wallet.client import Client\ncoinbase_API_key = \u201cYour API Key\u201d\ncoinbase_API_secret = \u201cYour API Secret\u201d\nclient = Client(coinbase_API_key, coinbase_API_secret)<\/code><\/pre><\/div>\n\n\n\n<p>Before trying to buy or sell anything we will need to check if our payment method is verified:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>payment_methods = client.get_payment_methods()<\/code><\/pre><\/div>\n\n\n\n<p>In order to buy or sell Bitcoin we\u2019d also want to check for their prices. That can be done with the following code:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>client.get_sell_price(currency_pair = &#39;BTC-EUR\u2019)\n\nclient.get_buy_price(currency_pair = &#39;BTC-EUR\u2019)<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"598\" height=\"396\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/buy-and-sell.png\" alt=\"\" class=\"wp-image-5911\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/buy-and-sell.png 598w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/buy-and-sell-300x199.png 300w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/><\/figure>\n\n\n\n<p>After confirming that we can buy or sell bitcoin and checking their prices, we can go ahead and construct some simple price checks. These price checks will run buy or sell functions when the price of bitcoin crosses the specified threshold:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>account = client.get_primary_account()\npayment_method = client.get_payment_methods()[0]<\/code><\/pre><\/div>\n\n\n\n<p>Let\u2019s add the thresholds:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>buy_price_threshold  = 300\nsell_price_threshold = 450\n\nNow, we will ask for the currencies again:\nbuy_price  = client.get_buy_price(currency=\u2019EUR\u2019)\nsell_price = client.get_sell_price(currency=\u2019EUR\u2019)<\/code><\/pre><\/div>\n\n\n\n<p>The next step is to add the \u201cif\u201d statements that will conduct the buying or selling requests. On top of that, we\u2019ll also specify the currency (BTC):<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>if float(sell_price.amount) \n  sell = account.sell(amount=&#39;1&#39;,\n                      currency=&quot;BTC&quot;,\n                      payment_method=payment_method.id)\n\nif float(buy_price.amount) \n  buy = account.buy(amount=&#39;1&#39;,\n                    currency=&quot;BTC&quot;,\n                    payment_method=payment_method.id)<\/code><\/pre><\/div>\n\n\n\n<p>When it comes to the Coinbase Pro, it offers a trading platform that we can use. For this example we will use their virtual sandbox and explore its features. The sandbox can be found on the following link:<\/p>\n\n\n\n<p><a href=\"https:\/\/public.sandbox.pro.coinbase.com\/trade\/ETH-BTC\">https:\/\/public.sandbox.pro.coinbase.com\/trade\/ETH-BTC<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"535\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1024x535.jpg\" alt=\"\" class=\"wp-image-16293\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1024x535.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-300x157.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-768x401.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1536x802.jpg 1536w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt.jpg 1904w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As we can see, the options that are in front of us are deposit and withdraw, and buy and sell. For the buy and sell options we can specify our amount, limit, and stop price:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"334\" height=\"867\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt2.jpg\" alt=\"\" class=\"wp-image-16294\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt2.jpg 334w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt2-116x300.jpg 116w\" sizes=\"(max-width: 334px) 100vw, 334px\" \/><\/figure><\/div>\n\n\n<p>We can also alternate between the candlestick and line chart and also add overlays as EMA 12 and EMA 26<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"405\" data-id=\"16295\"  src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/line-1024x405.jpg\" alt=\"\" class=\"wp-image-16295\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/line-1024x405.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/line-300x119.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/line-768x304.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/line.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"535\" data-id=\"16296\"  src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1-1024x535.jpg\" alt=\"\" class=\"wp-image-16296\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1-1024x535.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1-300x157.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1-768x401.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1-1536x802.jpg 1536w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/sajt-1.jpg 1904w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"454\" data-id=\"5918\"  src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/candleema-1024x454.png\" alt=\"\" class=\"wp-image-5918\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/candleema-1024x454.png 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/candleema-300x133.png 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/candleema-768x340.png 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/10\/candleema.png 1216w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>For portfolio creation we can click the portfolio button in the top right corner:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"524\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/portf-1024x524.jpg\" alt=\"\" class=\"wp-image-16297\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/portf-1024x524.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/portf-300x153.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/portf-768x393.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/portf-1536x786.jpg 1536w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/portf.jpg 1890w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<a name=\"what-are-access-and-refresh-tokens-in-the-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What are access and refresh tokens in the Coinbase API?<\/strong><\/h2>\n\n\n\n<p>Coinbase implemented an optional security feature of OAuth2 that uses the refresh tokens. When we first authenticate, our app will give us an access token and a refresh token.<\/p>\n\n\n\n<p>The purpose behind the access token is to authenticate our requests and it expires after about two hours. When it is expired the refresh token comes into play as it allows us to get a new access token and refresh token.<\/p>\n\n\n\n<p>Have in mind that the refresh token doesn\u2019t have an expiration date, but it can only be used once for a new set of access and refresh tokens.<\/p>\n\n\n\n<a name=\"potential-errors-and-warning\">\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Potential errors and warning<\/strong><\/h2>\n\n\n\n<p>While writing this article I ran into several problems and informing you about them will be helpful.<\/p>\n\n\n\n<p>Firstly, the libraries for the Coinbase API aren\u2019t official and their updates aren\u2019t frequent. In my opinion, the standard Coinbase API can\u2019t compete with the Coinbase API Pro.<\/p>\n\n\n\n<p>Also, you may run into bugs while writing the code that will say that the variable isn\u2019t defined when it is. The workaround for this was to restart the kernel or move the line of code into a new cell.<\/p>\n\n\n\n<p>Sometimes the code written in the Coinbase API documentation simply won\u2019t work and thus you\u2019ll need to rely on the source code that appears when you try to run it.<\/p>\n\n\n\n<p>The tutorials on the Coinbase API website are quite simplistic and they don\u2019t go into the coding part much. Thus, I\u2019d advise beginners to practice coding with other, more tutorial\/lecture-friendly, API\u2019s before trying to learn this one.<\/p>\n\n\n\n<a name=\"download-code-coinbase-api\">\n\n\n\n<h2 class=\"wp-block-heading\">Download Code<\/h2>\n\n\n\n<p>Link: <a href=\"https:\/\/github.com\/Lucas170\/Coinbase-API-Guide-AlgoTrading101\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/Lucas170\/Coinbase-API-Guide-AlgoTrading101<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_6105\" class=\"pvc_stats total_only  \" data-element-id=\"6105\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Table of contents: What is Coinbase API? What is Coinbase? What can I trade on Coinbase? What are the pricing and fees of Coinbase? &nbsp;Why should I use Coinbase API? Why shouldn\u2019t I use Coinbase API? What alternatives are there to Coinbase API? What are the account types for Coinbase API? What are the libraries [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":6569,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"no","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[3,2],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Coinbase API - A Introduction Guide - AlgoTrading101 Blog<\/title>\n<meta name=\"description\" content=\"Coinbase API is a method for us to trade cryptocurrencies on Coinbase automatically via code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Coinbase API - A Introduction Guide - AlgoTrading101 Blog\" \/>\n<meta property=\"og:description\" content=\"Coinbase API is a method for us to trade cryptocurrencies on Coinbase automatically via code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-25T18:46:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-03T21:13:33+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/Coinbase-Guide.png\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Igor Radovanovic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Igor Radovanovic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Coinbase API - A Introduction Guide - AlgoTrading101 Blog","description":"Coinbase API is a method for us to trade cryptocurrencies on Coinbase automatically via code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/","og_locale":"en_US","og_type":"article","og_title":"Coinbase API - A Introduction Guide - AlgoTrading101 Blog","og_description":"Coinbase API is a method for us to trade cryptocurrencies on Coinbase automatically via code.","og_url":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/","og_site_name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","article_published_time":"2020-11-25T18:46:51+00:00","article_modified_time":"2023-04-03T21:13:33+00:00","og_image":[{"width":600,"height":300,"url":"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/Coinbase-Guide.png","type":"image\/png"}],"author":"Igor Radovanovic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Igor Radovanovic","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/#article","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/"},"author":{"name":"Igor Radovanovic","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae"},"headline":"Coinbase API &#8211; A Introduction Guide","datePublished":"2020-11-25T18:46:51+00:00","dateModified":"2023-04-03T21:13:33+00:00","mainEntityOfPage":{"@id":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/"},"wordCount":2535,"publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"articleSection":["Programming","Trading"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/","url":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/","name":"Coinbase API - A Introduction Guide - AlgoTrading101 Blog","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/#website"},"datePublished":"2020-11-25T18:46:51+00:00","dateModified":"2023-04-03T21:13:33+00:00","description":"Coinbase API is a method for us to trade cryptocurrencies on Coinbase automatically via code.","breadcrumb":{"@id":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/algotrading101.com\/learn\/"},{"@type":"ListItem","position":2,"name":"Coinbase API &#8211; A Introduction Guide"}]},{"@type":"WebSite","@id":"https:\/\/algotrading101.com\/learn\/#website","url":"https:\/\/algotrading101.com\/learn\/","name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","description":"Authentic Stories about Algorithmic trading, coding and life.","publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/algotrading101.com\/learn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/algotrading101.com\/learn\/#organization","name":"AlgoTrading101","url":"https:\/\/algotrading101.com\/learn\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/","url":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","contentUrl":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","width":1200,"height":627,"caption":"AlgoTrading101"},"image":{"@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae","name":"Igor Radovanovic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","caption":"Igor Radovanovic"},"sameAs":["https:\/\/igorradovanovic.com","https:\/\/www.linkedin.com\/in\/igor-radovanovic-profile"],"url":"https:\/\/algotrading101.com\/learn\/author\/igor\/"}]}},"modified_by":"Igor Radovanovic","_links":{"self":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/6105"}],"collection":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/comments?post=6105"}],"version-history":[{"count":17,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/6105\/revisions"}],"predecessor-version":[{"id":21163,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/6105\/revisions\/21163"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media\/6569"}],"wp:attachment":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media?parent=6105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/categories?post=6105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/tags?post=6105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}