{"id":17501,"date":"2022-09-20T15:04:38","date_gmt":"2022-09-20T15:04:38","guid":{"rendered":"https:\/\/algotrading101.com\/learn\/?p=17501"},"modified":"2023-11-25T20:49:05","modified_gmt":"2023-11-25T20:49:05","slug":"algo-trading-deployment-google-cloud-platform","status":"publish","type":"post","link":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/","title":{"rendered":"Live Algo Trading on the Cloud &#8211; Google Cloud Platform"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_17501\" class=\"pvc_stats total_only  \" data-element-id=\"17501\" 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><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"496\" height=\"497\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/Google-Cloud-Logo-Lockup-MAIN-png-1.webp\" alt=\"\" class=\"wp-image-17466\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/Google-Cloud-Logo-Lockup-MAIN-png-1.webp 496w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/Google-Cloud-Logo-Lockup-MAIN-png-1-300x300.webp 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/Google-Cloud-Logo-Lockup-MAIN-png-1-150x150.webp 150w\" sizes=\"(max-width: 496px) 100vw, 496px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Table of contents:<\/h3>\n\n\n\n<ol>\n<li><a href=\"#algorithmic-trading-cloud\">What does live algorithmic trading on the Cloud mean?<\/a><\/li>\n\n\n\n<li><a href=\"#prerequisite-basic-guide\">Rerequisite &#8211; Basic Guide<\/a><\/li>\n\n\n\n<li><a href=\"#cloud-pros\">What are the pros of deploying your trading strategies to the Cloud?<\/a><\/li>\n\n\n\n<li><a href=\"#cloud-cons\">What are the cons of deploying your trading strategies to the Cloud?<\/a><\/li>\n\n\n\n<li><a href=\"#cloud-service\">What is the Cloud Service?<\/a><\/li>\n\n\n\n<li><a href=\"#cloud-use\">What is the Cloud used for?&nbsp;<\/a><\/li>\n\n\n\n<li><a href=\"#cloud-providers\">What cloud providers are good?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-platform\">What is the Google Cloud Platform?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-pros\">Why should I use Google Cloud?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-cons\">Why shouldn\u2019t I use Google Cloud?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-start\">How to get started with Google Cloud?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-kraken-bot\">Kraken Bot Trading Algorithm<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-docker\">What is Docker?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-docker-package\">How to package a trading algorithm with Docker?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-artifact-registry\">What is Google Artifact Registry?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-push-docker-image-to-artifact-registry\">How to push a Docker image to Google Artifact Registry?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-run\">What is Google Cloud Run?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-run-configure\">How to configure Google Cloud Run?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-learn-more\">Where can I learn more?<\/a><\/li>\n\n\n\n<li><a href=\"#google-cloud-full-code\">Full code<\/a><\/li>\n<\/ol>\n\n\n\n<a name=\"algorithmic-trading-cloud\">\n\n\n\n<h2 class=\"wp-block-heading\">What does live algorithmic trading on the Cloud mean?<\/h2>\n\n\n\n<p>Live algorithmic trading on the Cloud means that your trading bots can use the cloud provider\u2019s resources to run 24\/7 while being efficiently maintainable.<\/p>\n\n\n\n<p>This is article, we will demonstrate how to deploy a live algorithmic trading strategy to the cloud server using Google Cloud Platform and Docker.<\/p>\n\n\n\n<a name=\"prerequisite-basic-guide\">\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisite \u2013 Basic Guide<\/h2>\n\n\n\n<p>If you are new to deploying strategies to the cloud, do check out ou<a href=\"https:\/\/algotrading101.com\/learn\/live-algo-trading-on-the-cloud-aws\/\">r basic guide using AWS<\/a>.<\/p>\n\n\n\n<p>We covered how to:<\/p>\n\n\n\n<ul>\n<li>Choose a location for your server<\/li>\n\n\n\n<li>Input your secret keys<\/li>\n\n\n\n<li>Deploy a trading script using Github<\/li>\n\n\n\n<li>Set Telegram notifications when trades and key events happen<\/li>\n<\/ul>\n\n\n\n<a name=\"cloud-pros\">\n\n\n\n<h2 class=\"wp-block-heading\">What are the pros of deploying your trading strategies to the Cloud?<\/h2>\n\n\n\n<ul>\n<li><strong>Cloud services are easily available<\/strong>\u2013 they allow the user to access them at any time, from anywhere, and from almost any device.<\/li>\n\n\n\n<li><strong>Can lower costs<\/strong>&nbsp;\u2013 cloud computing can lower the costs and provide you with a good connection and hardware that saves you money in the long run.<\/li>\n\n\n\n<li><strong>Easy to maintain<\/strong>&nbsp;\u2013 you can upload your trading strategies to the cloud and get them running 24\/7 with the minimal endeavor.<\/li>\n\n\n\n<li><strong>Is scalable<\/strong>&nbsp;\u2013 you can store almost limitless amounts of data in the cloud.<\/li>\n\n\n\n<li><strong>Easy to set up&nbsp;<\/strong>\u2013 setting up your cloud server is quite easy.<\/li>\n\n\n\n<li><strong>Has many solutions<\/strong> &#8211; the cloud services are upping their game by creating specialized services for almost anything you could need from blockchain to data pipelines and app runners.<\/li>\n<\/ul>\n\n\n\n<a name=\"cloud-cons\">\n\n\n\n<h2 class=\"wp-block-heading\">What are the cons of deploying your trading strategies to the Cloud?<\/h2>\n\n\n\n<ul>\n<li><strong>Security risks<\/strong>&nbsp;\u2013 your data is being stored by a third-party provider and if a security breach happens your data is at high risk.<\/li>\n\n\n\n<li><strong>Depends on the internet connection<\/strong>&nbsp;\u2013 even though this is the same case when running trading strategies by yourself, the cloud service provider can also suffer from downtime and other natural risks.<\/li>\n\n\n\n<li><strong>Data confidentiality risk&nbsp;<\/strong>\u2013 your privacy is of utmost importance and when using a third-party cloud provider you can\u2019t be too sure that you\u2019re the only one accessing your data or being able to see it.<\/li>\n\n\n\n<li><strong>It can get costly <\/strong>&#8211; sometimes engineers mess up by not exploring the costs and settings alarms, safety nets, and\/or writing optimal code which can result in surprising bills. <\/li>\n<\/ul>\n\n\n\n<a name=\"cloud-service\">\n\n\n\n<h2 class=\"wp-block-heading\">What is the Cloud Service?<\/h2>\n\n\n\n<p>A Cloud Service delivers cloud computing as a service with an intent to provide affordable, easy, and efficient access to diverse resources without the need to have your own hardware or infrastructure.<\/p>\n\n\n\n<a name=\"cloud-use\">\n\n\n\n<h2 class=\"wp-block-heading\">What is Cloud used for?<\/h2>\n\n\n\n<p>Cloud services have many purposes for which they could be used for and here are some of the most common ones:<\/p>\n\n\n\n<ul>\n<li><strong>Algorithmic trading&nbsp;<\/strong>\u2013 cloud services allow algorithmic traders to run multiple bots that trade the markets.<\/li>\n\n\n\n<li><strong>Big data storage&nbsp;<\/strong>\u2013 cloud services offer an almost limitless storage capacity which is great when dealing with big data.<\/li>\n\n\n\n<li><strong>Backup and recovery<\/strong>&nbsp;\u2013 clouds can be frequently backed up and you can easily recover data from them. They also offer good disaster recovery.<\/li>\n\n\n\n<li><strong>Testing and Development<\/strong>&nbsp;\u2013 cloud services are great when testing and developing your applications and trading strategies.<\/li>\n\n\n\n<li><strong>Model training&nbsp;<\/strong>\u2013 when doing machine learning work, model training can take up to several months, and running it on a cloud can save you computing power and in some cases even money.<\/li>\n<\/ul>\n\n\n\n<a name=\"cloud-providers\">\n\n\n\n<h2 class=\"wp-block-heading\">What cloud providers are good?<\/h2>\n\n\n\n<p>There are many cloud services and picking a quality one is important. In order to make your decisions process easier I will mention a few that are on top of their cloud game:<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/algotrading101.com\/learn\/live-algo-trading-on-the-cloud-aws\/\">Amazon Web Services (AWS)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-microsoft-azure\">Microsoft Azure<\/a><\/li>\n\n\n\n<li>Server Space<\/li>\n\n\n\n<li>IBM Cloud Services<\/li>\n\n\n\n<li>Oracle<\/li>\n\n\n\n<li>Vultr<\/li>\n<\/ul>\n\n\n\n<a name=\"google-cloud-platform\">\n\n\n\n<h2 class=\"wp-block-heading\">What is the Google Cloud Platform?<\/h2>\n\n\n\n<p>The Google Cloud Platform is a suite of&nbsp;cloud computing&nbsp;services that runs on the same infrastructure that Google uses internally for its end-user products (i.e. YouTube). It offers a lot of solutions such as cloud-based storage, computing resources, security, and more.<\/p>\n\n\n\n<a name=\"google-cloud-pros\">\n\n\n\n<h2 class=\"wp-block-heading\">Why should I use Google Cloud?<\/h2>\n\n\n\n<ul>\n<li>Google Cloud is easy to use<\/li>\n\n\n\n<li>Google Cloud has a large community<\/li>\n\n\n\n<li>Is in the top 5 cloud service providers<\/li>\n\n\n\n<li>Has a good track record<\/li>\n\n\n\n<li>Offers easy collaboration between users<\/li>\n<\/ul>\n\n\n\n<a name=\"google-cloud-cons\">\n\n\n\n<h2 class=\"wp-block-heading\">Why shouldn&#8217;t I use Google Cloud?<\/h2>\n\n\n\n<ul>\n<li>Google Cloud can be confusing for beginners<\/li>\n\n\n\n<li>Google Cloud has fewer data centers when compared to some alternatives<\/li>\n\n\n\n<li>It can be messy to move your infrastructure from Google Cloud to another cloud provider<\/li>\n\n\n\n<li>Has a complex pricing schema when compared to alternatives<\/li>\n\n\n\n<li>Can often be more pricey than its alternatives<\/li>\n<\/ul>\n\n\n\n<a name=\"google-cloud-start\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get started with Google Cloud?<\/h2>\n\n\n\n<p>To get started with Google Cloud, you will need to open an account to access cloud resources. To do this, go over to their main cloud <a href=\"https:\/\/cloud.google.com\/\">webpage<\/a> and click the blue &#8220;Get started for free&#8221; button in the middle part of your screen.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"454\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/1-1-1024x454.webp\" alt=\"\" class=\"wp-image-17467\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/1-1-1024x454.webp 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/1-1-300x133.webp 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/1-1-768x340.webp 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/1-1.webp 1307w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This will open up a new page where you will be asked from which country you&#8217;re from and for what use cases will you use Google Cloud. After answering these questions and agreeing to their terms, click the blue &#8220;Continue&#8221; button.<\/p>\n\n\n\n<p>The second step will ask you to provide your payment information so that Google can confirm that you aren&#8217;t a robot. They won&#8217;t charge you anything as we are setting up a free account and getting free $300 worth of credits that last 90 days.<\/p>\n\n\n\n<p>After that, we can choose to upgrade our account to the premium tier after which we start to get charged. When you are done adding in your payment data, click the blue &#8220;START MY FREE TRIAL&#8221; button to proceed to the Google Cloud Platform.<\/p>\n\n\n\n<p>In the following headers, we will explore how to deploy a live Kraken exchange trading algorithm to Google Cloud. The way that we&#8217;ll do this involves the use of Docker and Cloud Run.<\/p>\n\n\n\n<p>For a similar Docker way of doing this, visit our Microsoft Azure article, and for a more manual way, we have the <a href=\"https:\/\/algotrading101.com\/learn\/live-algo-trading-on-the-cloud-aws\/\">AWS<\/a> article.<\/p>\n\n\n\n<p>All three ways can be used on all three platforms as all of them have the same services with different, and sometimes similar, names.<\/p>\n\n\n\n<a name=\"google-cloud-kraken-bot\">\n\n\n\n<h2 class=\"wp-block-heading\">Kraken Bot Trading Algorithm<\/h2>\n\n\n\n<p>The simple trading strategy that we will use will feature the Kraken exchange, Docker and Cloud Run. Before we set up everything, we need to explain how this strategy works and where you can learn how to code one.<\/p>\n\n\n\n<p>The main idea behind the strategy will be to buy ETH when BTC moves 5% in the last 5 minutes. For this to work, we will pull BTC prices in 5-minute intervals and calculate the percentage difference.<\/p>\n\n\n\n<p>If this difference is more or equal to 5% we will buy ETH, if the requirement isn\u2019t reached we will continue to loop. The strategy also features error management, logging, and environmental variables.<\/p>\n\n\n\n<p>Error management is used to catch errors that might occur, logging is used so we can obtain data about our bot and what it\u2019s been up to while running on the server and environmental variables allow us to interact with the bot.<\/p>\n\n\n\n<p>The code below is what our trading strategy looks like and here you can find an article about&nbsp;<a href=\"https:\/\/algotrading101.com\/learn\/kraken-api-guide\/\">Kraken<\/a>&nbsp;and how to code a similar strategy by yourself.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># Import the libraries we need\nimport time, logging, os\nimport pandas as pd\nimport krakenex\nfrom pykrakenapi import KrakenAPI\nfrom dotenv import load_dotenv\n\n# Grab environment variables\nload_dotenv()\nAPI_KEY = os.getenv(&quot;KRAKEN_API_KEY&quot;)\nAPI_SECRET = os.getenv(&quot;KRAKEN_API_SECRET&quot;)\nTRACK_TICKER = os.getenv(&quot;TRACK_TICKER&quot;)\nTRADE_TICKER = os.getenv(&quot;TRADE_TICKER&quot;)\n\napi = krakenex.API(key=API_KEY, secret=API_SECRET)\nkraken = KrakenAPI(api)\n\n# Set up the logging\nfor handler in logging.root.handlers[:]:\n    logging.root.removeHandler(handler)\n\n\nlogging.basicConfig(\n    level=logging.INFO, format=&quot;%(asctime)s: %(levelname)s: %(message)s&quot;\n)\nconsole = logging.StreamHandler()\nconsole.setLevel(logging.INFO)\nformatter = logging.Formatter(&quot;%(asctime)s: %(levelname)s: %(message)s&quot;)\nconsole.setFormatter(formatter)\nlogging.getLogger(&quot;&quot;).addHandler(console)\n\n# Create the main script logic\nwhile True:\n    logging.info(&quot;--------- Start of current 5 minute period ---------&quot;)\n    logging.info(pd.Timestamp.now())\n\n    try:\n        BTC_old = float((kraken.get_ticker_information(TRACK_TICKER))[&quot;b&quot;][0][0])\n    except Exception as e:\n        logging.warning(&quot;Error obtaining data&quot;)\n\n    time.sleep(300)\n\n    try:\n        BTC_new = float((kraken.get_ticker_information(TRACK_TICKER))[&quot;b&quot;][0][0])\n    except Exception as e:\n        logging.warning(&quot;Error obtaining data&quot;)\n\n    percent = ((BTC_new - BTC_old) * 100) \/ BTC_old\n\n    logging.info(f&quot;BTC moved {percent:.2f}% over the last 5 minutes&quot;)\n\n    if percent &gt;= 5:\n\n        try:\n            ETH = float((kraken.get_ticker_information(TRADE_TICKER))[&quot;a&quot;][0][0]) + 2\n        except Exception as e:\n            logging.warning(&quot;Error obtaining data&quot;)\n\n        try:\n            response = kraken.add_standard_order(\n                pair=TRADE_TICKER,\n                type=&quot;buy&quot;,\n                ordertype=&quot;limit&quot;,\n                volume=&quot;0.007&quot;,\n                price=ETH,\n                validate=False,\n            )\n        except Exception as e:\n            logging.warning(&quot;Error placing order&quot;)\n\n        logging.info(f&quot;Order details:\\n{response}&quot;)\n\n        time.sleep(2)\n\n        try:\n            check_order = kraken.query_orders_info(response[&quot;txid&quot;][0])\n        except Exception as e:\n            logging.warning(&quot;Error checking order&quot;)\n\n        if check_order[&quot;status&quot;][0] == &quot;open&quot; or &quot;closed&quot;:\n            logging.info(&quot;Order executed sucessfully&quot;)\n            break\n        else:\n            logging.info(&quot;Order rejected&quot;)\n            break\n    else:\n        logging.info(&quot;--------- End of current 5 minute period ---------&quot;)<\/code><\/pre><\/div>\n\n\n\n<p>As we need to provide our API keys for the trading algorithm to work, we will need to find one of the &#8220;safer&#8221; solutions to perform that.<\/p>\n\n\n\n<a name=\"google-cloud-docker\">\n\n\n\n<h2 class=\"wp-block-heading\">What is Docker?<\/h2>\n\n\n\n<p>Docker is&nbsp;an open-source containerization platform. It lets us package our code into containers that can be smoothly deployed anywhere while being sure that the code in them will work and function in a standardized way.<\/p>\n\n\n\n<p>To install Docker please follow one of <a href=\"https:\/\/docs.docker.com\/get-docker\/\">these guides<\/a> depending on your OS. I&#8217;ll be using Docker Desktop as I&#8217;m on Windows 10.<\/p>\n\n\n\n<a name=\"google-cloud-docker-package\">\n\n\n\n<h2 class=\"wp-block-heading\">How to package a trading algorithm with Docker?<\/h2>\n\n\n\n<p>To package a trading algorithm with Docker, we will need to have a file named <code>dockerfile<\/code> that has all the instructions on how to make our algorithm ready by copying code files we need, installing libraries, passing the environment variables, and more.<\/p>\n\n\n\n<p>Because Docker needs to know what dependencies we want to install for our algorithm, it is good practice to have a <code>requirements.txt<\/code> file that lists all the libraries we need and their versions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python-dotenv==0.21.0\npandas==1.4.4\nkrakenex==2.1.0\npykrakenapi==0.3.1<\/code><\/pre>\n\n\n\n<p>To get your package version you can write <code>pip show &lt;package&gt;<\/code>.<\/p>\n\n\n\n<p>Now that the requirements are ready, we can move on to specifying our installation and other setup commands inside of the <code>dockerfile<\/code>. We first create the <code>dockerfile<\/code> by writing <code>touch dockerfile<\/code>.<\/p>\n\n\n\n<p>The inside of our <code>dockerfile<\/code> looks the following way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM python:3.8\nRUN mkdir -p \/code\n\nCOPY .\/main.py \/code\/\nCOPY .\/requirements.txt \/code\/\n\nWORKDIR \/code\n\n# set environment variablesFROM python:3.8\nRUN mkdir -p \/code\n\nCOPY .\/main.py \/code\/\nCOPY .\/requirements.txt \/code\/\n\nWORKDIR \/code\n\n# set environment variables\nARG API_KEY\nARG API_SECRET\nARG TRACK\nARG TRADE\n\nENV KRAKEN_API_KEY $API_KEY\nENV KRAKEN_API_SECRET $API_SECRET\nENV TRACK_TICKER $TRACK\nENV TRADE_TICKER $TRADE\n\nRUN pip install -r requirements.txt\n\nEXPOSE 8080\n\nCMD &#91;\"python\", \"\/code\/main.py\"]<\/code><\/pre>\n\n\n\n<p>To build this container image we run the following command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker build -t google-algotrading101 \\\n\t--build-arg API_KEY=&lt;YOUR-API-KEY&gt; \\\n\t--build-arg API_SECRET=&lt;YOUR-API-SECRET&gt; \\\n\t--build-arg TRACK=BTCUSDT \\\n\t--build-arg TRADE=ETHUSDT .<\/code><\/pre><\/div>\n\n\n\n<p>Once docker is done, you will see a message similar to this one:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>[+] Building 8.2s (11\/11) FINISHED\n=&gt; [internal] load build definition from Dockerfile ...  <\/code><\/pre><\/div>\n\n\n\n<p>To see your docker images, you can write the following command to the terminal:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker images<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>REPOSITORY                       TAG               IMAGE ID       CREATED         SIZE\ngoogle-algotrading101             latest            f81336abb1fc   2 minutes ago   1.08GB<\/code><\/pre><\/div>\n\n\n\n<p>If you want to run the container locally, you can write the following command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker run -d -p 8080:80 google-algotrading101<\/code><\/pre><\/div>\n\n\n\n<p>The next step is to store this image in the Google Artifact Registry. Prior to exploring that, we will need to install the gcloud CLI.<\/p>\n\n\n\n<a name=\"google-cloud-gcloud-cli\">\n\n\n\n<h2 class=\"wp-block-heading\">What is gcloud CLI?<\/h2>\n\n\n\n<p>Gcloud (Google Cloud) CLI is a set of tools to create and manage Google Cloud resources. You can use these tools to perform many common platform tasks from the command line or through scripts and other automation.<\/p>\n\n\n\n<p>To install gcloud follow this <a href=\"https:\/\/cloud.google.com\/sdk\/docs\/install\">guide<\/a>.<\/p>\n\n\n\n<a name=\"google-cloud-artifact-registry\">\n\n\n\n<div class=\"wp-block-group is-layout-flow\"><div class=\"wp-block-group__inner-container\">\n<h2 class=\"wp-block-heading\">What is Google Artifact Registry?<\/h2>\n\n\n\n<p>Google Artifact Registry is the evolution of the previously used Container Registry and is a single place for you to manage container images. It also integrates well with other Google Cloud services such as the Cloud Run service for easy deployment of containers.<\/p>\n\n\n\n<a name=\"google-cloud-push-docker-image-to-artifact-registry\">\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">How to push a Docker image to Google Artifact Registry?<\/h2>\n\n\n\n<p>To store a Docker image on the Google Artifact Registry, navigate to it in your Google Cloud dashboard and enable its usage. Then, click the Create Repository button and set up your repository details. In our case, it is a Docker repository.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"545\" height=\"803\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/3-1.webp\" alt=\"\" class=\"wp-image-17469\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/3-1.webp 545w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/3-1-204x300.webp 204w\" sizes=\"(max-width: 545px) 100vw, 545px\" \/><\/figure>\n\n\n\n<p>When done, click the Create button. The next step is to configure our Docker to work with the Google Artifact Registry. To do this, we will use our previously installed gcloud CLI. Let us open it up and write the following command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>gcloud auth configure-docker \\\n    northamerica-northeast1-docker.pkg.dev<\/code><\/pre><\/div>\n\n\n\n<p>Take note that your region might be different depending on your choice when creating the Registry. To view your region, you can click the &#8220;SETUP INSTRUCTIONS&#8221; hyperlink in your Artifact Registry dashboard. This will open an example query you need to run to configure your docker.<\/p>\n\n\n\n<p>Now, we need to tag our docker image with the details from our created Artifact Registry. Have in mind that this will be different for you depending on your registry location and name. I&#8217;ll add the &#8220;latest&#8221; tag to the image.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker tag google-algotrading101 \\\nnorthamerica-northeast1-docker.pkg.dev\/gifted-healer-362818\/kraken-demo\/google-algotrading101:latest<\/code><\/pre><\/div>\n\n\n\n<p>To make sure the tag was set, run <code>docker images<\/code> again. If everything is good,  we can push our Docker image to the Registry by writing the following with the gcloud CLI:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>docker push krakenexample101.azurecr.io\/azure-algotrading101:awesome<\/code><\/pre><\/div>\n\n\n\n<p>When docker is done, you should see the image in your registry:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"453\" height=\"127\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/7-1.webp\" alt=\"\" class=\"wp-image-17471\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/7-1.webp 453w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/7-1-300x84.webp 300w\" sizes=\"(max-width: 453px) 100vw, 453px\" \/><\/figure>\n\n\n\n<p>If you are facing issues, here is a good <a href=\"https:\/\/cloud.google.com\/artifact-registry\/docs\/docker\/pushing-and-pulling\">tutorial<\/a> by Google on how to push\/pull images properly.<\/p>\n\n\n\n<div class=\"wp-block-group is-layout-flow\"><div class=\"wp-block-group__inner-container\">\n<a name=\"google-cloud-run\">\n\n\n\n<h2 class=\"wp-block-heading\">What is Google Cloud Run?<\/h2>\n\n\n\n<p>Google Cloud Run is a service that allows us to easily run containerized applications. To use the Cloud Run service navigate to it by searching its name in your Google Cloud dashboard. When there, click the blue &#8220;Create service&#8221; button. <\/p>\n\n\n\n<a name=\"google-cloud-run-configure\">\n\n\n\n<h2 class=\"wp-block-heading\">How to configure Google Cloud Run?<\/h2>\n\n\n\n<p>To configure Google Cloud run we will click the &#8220;Create service&#8221; button and configure it to our liking by choosing our preferred options. For this demo, we want to select a container image from our Artifact Registry. To do this, we navigate to our container image URL.<\/p>\n\n\n\n<p>After that, scroll down and click that this service requires authentication to signal that this is private. When it comes to picking a region, you want to pick one that is closest to the exchange servers. To learn how to do this, check out the <a href=\"https:\/\/algotrading101.com\/learn\/live-algo-trading-on-the-cloud-aws\/\">AWS<\/a> article.<\/p>\n\n\n\n<p> To finish the creation process, click the blue &#8220;CREATE&#8221; button. This should automatically start the algorithm after deployment. If not, you might need to click the URL in your Cloud Run project which will start the service for you (if you were provided with one).<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>2022-09-18 22:28:22.743 CEST2022-09-18 20:28:22,742: \\\n INFO: --------- Start of current 5 minute period ---------<\/code><\/pre><\/div>\n\n\n\n<a name=\"google-cloud-learn-more\">\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Where can I learn more?<\/h2>\n\n\n\n<p>To learn more about the Google Cloud Platform, I advise visiting their <a href=\"https:\/\/cloud.google.com\/\">webpage<\/a> and exploring various google tutorials, and reading the documentation. There are also great tutorials on YouTube and other blog pages that you might want to explore.<\/p>\n\n\n\n<a name=\"google-cloud-full-code\">\n\n\n\n<h2 class=\"wp-block-heading\">Full code<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/IgorWounds\/Google-Cloud-Algotrading101\">GitHub link<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_17501\" class=\"pvc_stats total_only  \" data-element-id=\"17501\" 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 does live algorithmic trading on the Cloud mean? Live algorithmic trading on the Cloud means that your trading bots can use the cloud provider\u2019s resources to run 24\/7 while being efficiently maintainable. This is article, we will demonstrate how to deploy a live algorithmic trading strategy to the cloud server using [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":17466,"comment_status":"closed","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"","_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>Live Algo Trading on the Cloud - Google Cloud Platform - AlgoTrading101 Blog<\/title>\n<meta name=\"description\" content=\"Deploy live algorithmic trading strategies to the cloud server using Google Cloud Platform and Docker.\" \/>\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\/algo-trading-deployment-google-cloud-platform\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Live Algo Trading on the Cloud - Google Cloud Platform - AlgoTrading101 Blog\" \/>\n<meta property=\"og:description\" content=\"Deploy live algorithmic trading strategies to the cloud server using Google Cloud Platform and Docker.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/\" \/>\n<meta property=\"og:site_name\" content=\"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-20T15:04:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-25T20:49:05+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/Google-Cloud-Logo-Lockup-MAIN-png-1.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"496\" \/>\n\t<meta property=\"og:image:height\" content=\"497\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\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=\"12 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Live Algo Trading on the Cloud - Google Cloud Platform - AlgoTrading101 Blog","description":"Deploy live algorithmic trading strategies to the cloud server using Google Cloud Platform and Docker.","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\/algo-trading-deployment-google-cloud-platform\/","og_locale":"en_US","og_type":"article","og_title":"Live Algo Trading on the Cloud - Google Cloud Platform - AlgoTrading101 Blog","og_description":"Deploy live algorithmic trading strategies to the cloud server using Google Cloud Platform and Docker.","og_url":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/","og_site_name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","article_published_time":"2022-09-20T15:04:38+00:00","article_modified_time":"2023-11-25T20:49:05+00:00","og_image":[{"width":496,"height":497,"url":"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/09\/Google-Cloud-Logo-Lockup-MAIN-png-1.webp","type":"image\/webp"}],"author":"Igor Radovanovic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Igor Radovanovic","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/#article","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/"},"author":{"name":"Igor Radovanovic","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae"},"headline":"Live Algo Trading on the Cloud &#8211; Google Cloud Platform","datePublished":"2022-09-20T15:04:38+00:00","dateModified":"2023-11-25T20:49:05+00:00","mainEntityOfPage":{"@id":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/"},"wordCount":2195,"publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"articleSection":["Programming","Trading"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/","url":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/","name":"Live Algo Trading on the Cloud - Google Cloud Platform - AlgoTrading101 Blog","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/#website"},"datePublished":"2022-09-20T15:04:38+00:00","dateModified":"2023-11-25T20:49:05+00:00","description":"Deploy live algorithmic trading strategies to the cloud server using Google Cloud Platform and Docker.","breadcrumb":{"@id":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/algotrading101.com\/learn\/algo-trading-deployment-google-cloud-platform\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/algotrading101.com\/learn\/"},{"@type":"ListItem","position":2,"name":"Live Algo Trading on the Cloud &#8211; Google Cloud Platform"}]},{"@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":"Lucas Liew","_links":{"self":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/17501"}],"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=17501"}],"version-history":[{"count":6,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/17501\/revisions"}],"predecessor-version":[{"id":22314,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/17501\/revisions\/22314"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media\/17466"}],"wp:attachment":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media?parent=17501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/categories?post=17501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/tags?post=17501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}