Steps to Deploy your Trading Robot to the Cloud (2024)

I recently helped a newbie Python Developer host his trading robot on the cloud, which made me realize how daunting this process can be for people just starting with the world of programming. It gets even more confusing because of the wide variety of industry terms floating around, like an **AWS EC2 Instance, a DigitalOcean Droplet, AWS Lambda, Azure Server, Alibaba Cloud. **

Oh my god, can't they keep things simple? But I guess they probably do this to differentiate their products from each other from a marketing standpoint. Still, every major cloud provider provides more or less similar services. Anyway, getting back to the point, How do you host a Trading Robot to the Cloud?

I will be using a Virtual Server by DigitalOcean to demonstrate this, which they call a Droplet. If you find this reading worthwhile and would like to follow the steps I have mentioned, do signup for DigitalOcean using our affiliate badge below, which will give you $100 worth free credits, and you can launch your own Virtual Machine for free.

Steps to Deploy your Trading Robot to the Cloud (1)

We will divide this into a few steps, but before I lay out the steps, I want to tell you that this article is more about how to deploy rather than discussing the specifics of the Trading Bot. I will be using a very simple snippet of code below, which will send me the average price of RELIANCE for the last 5 minutes on Telegram. This is to show you the overall process; you are, of course, free to upload your complex strategies. To achieve this, here are the steps:

  1. Building the Trading Robot.

  2. Building a Telegram Bot.

  3. Creating a DigitalOcean Droplet.

  4. Deploying Our Code.

If you prefer watching rather than reading, we have prepared the below Youtube video for you.

Installing the Libraries

pip install jugaad_data
pip install telegram_send

We will be using jugaad_data to fetch live prices from NSE Website and use telegram_send to send messages to our Telegram.

from jugaad_data.nse import NSELiveimport telegram_send as tsimport timedef get_prices(stockSymbol): '''A function to get live prices using jugaad_data library''' n = NSELive() q = n.stock_quote(stockSymbol) return q['priceInfo']['lastPrice']def send_telegram_message(message): ts.send(messages = [str(message)])live_prices = []count = 0while True: current_price = get_prices('HDFC') live_prices.append(current_price) count = count + 1 print(f'{count} Minutes Done') if len(live_prices) == 5: avg_price = round((sum(live_prices[-5:])/len(live_prices[-5:])),2) if count == 5: send_telegram_message(f'The Average Price of HDFC For Last 5 Minutes is {avg_price}') #print(f'The Average Price of HDFC For Last 5 Minutes is {avg_price}') count = 0 live_prices.clear() time.sleep(60)

What's Happening in the Above Code?

  • We create function get_prices to get live prices from NSE and function send_telegram_message to send a message. Note: jugaad_data scrapes the actual NSE website for data and may be illegal; please use it at your own risk. This is just for demonstration purposes only. The while loop runs continuously, fetches a price, and sleeps for 60 seconds. - The current_price is added to a list live_prices, as soon as there are additional 5 entries in that list, we calculate the avg_price and send it to Telegram.

To send messages via Python to our Telegram App, we need to create a Bot; if you are a Telegram user, you might have already seen such bots. Follow these steps to create a Bot.

  • Open Anaconda Prompt and change the directory to where your .py file is; for me, it's in a folder called cloud_bot. If the below is not visible properly, please zoom in.

Steps to Deploy your Trading Robot to the Cloud (2)

  • Talk with BotFather on Telegram and follow the instructions until you get a Unique ID for your Bot.

Steps to Deploy your Trading Robot to the Cloud (3)

  • I have redacted by Unique Bot ID for obvious reasons. Enter this Unique ID back into the anaconda terminal.

Steps to Deploy your Trading Robot to the Cloud (4)

Steps to Deploy your Trading Robot to the Cloud (5)

Great, our Telegram Bot is now ready to use, wasn't that really easy?

A DigitalOcean Droplet is nothing but a Virtual Machine in the Cloud. There are various advantages to deploy your strategy to Cloud primary one being stability. For example, you have a very risky strategy running on your laptop, and you have many positions open, and suddenly your home Wi-Fi stops working, and your algo stops running. Imagine that nightmare! Better to deploy on the cloud and let DigitalOcean take care of the infrastructure. If you follow me in this article, I would really appreciate it if you could sign up using my affiliate badge below.

Steps to Deploy your Trading Robot to the Cloud (6)

  • Create an Account On DigitalOcean.

  • Once you are logged in, create a new Droplet.

Steps to Deploy your Trading Robot to the Cloud (7)

  • Select Your Machine Configuration and other Resources. If you plan to deploy your trading robot in India, I recommend selecting the Bangalore Data Centre. DigitalOcean does not offer Windows VMs, and just so you know, Windows VM is generally costlier than Linux VMs due to Windows License Fee. (Talk about Bill Gates being a philanthropist LOL)

Steps to Deploy your Trading Robot to the Cloud (8)

  • Create an Authentication Method, to keep things simple, select Password and enter a complex password.

  • Give Your Droplet a HostName and Create It. Great, now you have your own Virtual Machine at zero cost.

Steps to Deploy your Trading Robot to the Cloud (9)

  • **Let's login into our Virtual Machine to see if we can access it. ** a. Open cmd on your Windows Machine or the Terminal on Linux.
    b. Type in ssh root@your.ipv4.address highlighted in the above image and input the password you entered while creating the droplet.

Steps to Deploy your Trading Robot to the Cloud (10)

Awesome, if you see a screen like above, that means you are now logged into your Ubuntu Virtual Machine. How cool, right? Moreover, this droplet comes pre-installed with Python3. If you got an error in the above step, please let me know in the comments.

To deploy the robot you created on your personal laptop, you will first have to transfer it to the Droplet and then try and run it. You can do it in various ways, but here is the preferred way.

Transferring the Code to our Droplet

  • Download FileZilla from this link. This will be used to transfer the file. Once downloaded, please install it.

  • Go to File --> Site Manager --> New Site --> Select SFTP Protocol --> Enter Host (this is your Droplet ipv4 address) -->** Logon Type** (Interactive) --> User (root) --> Connect

Steps to Deploy your Trading Robot to the Cloud (11)

  • You will get a popup saying Unknown host key if you connect this for the first time, ignore that and click OK.

Steps to Deploy your Trading Robot to the Cloud (12)

  • Enter the Droplet Password and click OK. If everything goes well, you should be connected to the root folder on your Virtual Machine.

Steps to Deploy your Trading Robot to the Cloud (13)

  • Now, it's just as simple as finding the relevant folder in your local site on the left-hand side of the screen and then dragging it to the remote site.

Steps to Deploy your Trading Robot to the Cloud (14)

Awesome, you now have your files on the Virtual Machine. Now it's just a matter of running them from your Terminal.

Running the Code on Droplet

  • Go back to your Command Prompt cmd, log in again into your Droplet if you haven't already and type in ls into the terminal; you will see your folder cloud_bot present there. Change your directory using cd cloud_bot and then try and run the code python3 cloud_botv2.py (Substitute it with your file name, please)

Steps to Deploy your Trading Robot to the Cloud (15)

  • Woah! We got an error; if you look closely, that was pretty much expected. Our code uses external libraries like jugaad_data and telegram_send, which are not present on this machine, so first, we have to install them again. But, to do that, first, we need to install pip3 into this machine as well.

apt install python3-pip

Followed by: pip3 install jugaad_data telegram_send

Steps to Deploy your Trading Robot to the Cloud (16)

Steps to Deploy your Trading Robot to the Cloud (17)

  • **Configure the Telegram Bot on this Droplet Again and finally run the code. **

Steps to Deploy your Trading Robot to the Cloud (18)

Steps to Deploy your Trading Robot to the Cloud (19)

Awesome 🎆, so now you have a code running on your Virtual Machine (Droplet) where there is no dependency on your local system at all. This was a very basic example but you can upload complex options trading strategies or just bots where you want to get notified if certain conditions meet. There are tons of possibilities if you imagine.

I hope this is a very detailed step-by-step guide for you to set up your own Droplet and host your trading robot on it. If you are confused at any time, please feel free to comment below or speak to me via TopMate.

**You can also find the code I uploaded to the Droplet here on GitHub. **

If you like the content on Trade With Python, please do consider subscribing to our newsletter (you will find an option at the top of the page), and lastly, if you would like to keep our spirits high and produce more content like this, you can BuyMeACoffee by clicking here or on the button below.

💡

Please note we haven't made any new posts since Nov 2021 on this blog, you are free to subscribe to the mailing list, however, you will be auto-added to the new blog's (thealtinvestor.in) mailing list as well.

Steps to Deploy your Trading Robot to the Cloud (2024)

FAQs

How to deploy a trading bot? ›

6 Steps to Create a Crypto Trading Bot
  1. Step 1: Define Your Trading Objectives And Goals. ...
  2. Step 2: Choose a Trading Strategy. ...
  3. Step 3: Design The Architecture of Your Bot. ...
  4. Step 4: Write Code for Your Crypto Trading Bot. ...
  5. Step 5: Testing and Enhancing. ...
  6. Step 6: Deploy Your Crypto Trading Bot.
Feb 5, 2024

How to program a trading robot? ›

How to Create Mt4 Robot - 6 Steps From Mt4 Developer
  1. Define Your Strategy. When creating an MT4 trading robot, defining your strategy is one of the most important steps. ...
  2. Choose Your Programming Language. ...
  3. Learn the Basics of MQL4. ...
  4. Write Your Code. ...
  5. Optimize Your Robot. ...
  6. Test Your Robot.

How to make a trading bot with Python? ›

Building a Trading Bot in Python: A Step-by-Step Guide with...
  1. Step 1: Define Your Strategy. ...
  2. Step 2: Connect to a Broker. ...
  3. Step 3: Set Up Your Environment. ...
  4. Step 4: Write Your Trading Algorithm. ...
  5. Step 5: Implement Risk Management. ...
  6. Step 6: Deploy Your Trading Bot.
Feb 25, 2023

How to deploy a trading algorithm? ›

Use the deployment wizard in the Algorithm Lab to deploy your algorithms to live trading. The deployment wizard lets you select a brokerage, enter your brokerage credentials, select a data provider, select a live trading node, set up notifications, and configure automatic algorithm restarts.

Are trading robots illegal? ›

Different regulatory systems are more or less permissive in what they allow traders to do. So, when it comes to robot trading in forex, the simple answer is: Yes, it's perfectly legal to trade with forex robots.

What is the most profitable trading robot? ›

Waka Waka is a record-breaking expert advisor (EA) forex trading bot – that has offered an account gain of more than 7,500% since its origin. Notably, Waka Waka also holds the world record for the most number of consecutive months in profit on a live account – 66 and counting.

Can I create my own trading bot? ›

Can I Create My Own Bots? Yes, SpeedBot 'NoCode' Bot Builder help users to create their own Strategies into a Trading Bot. Create Bots on various symbols, and define Entery/Exit rules, Capital Allocation and Stoploss.

Are AI trading bots illegal? ›

While trading bots are legal, investment firms and traders are responsible for ensuring that they're used in a compliant manner.

Is there a free AI trading bot? ›

Pionex — FREE best trading bots for crypto

Don't need to hassle with the API Keys while using Pionex. Pionex is the exchange with in-built crypto trading bots. It's one of the best free trading bot platforms for cryptocurrency I've ever seen since 2017.

Is AI trading legal? ›

Algorithmic trading is now legal; it's just that investment firms and stock market traders are responsible for ensuring that AI is used and following the compliance rules and regulations.

What programming language do trading bots use? ›

Python is a popular choice for developing trading bots, thanks to its simplicity and extensive libraries like Pandas, NumPy and SciPy. These libraries enable efficient data analysis, making Python a preferred language for data-driven trading strategies.

Which language is used to create trading bots? ›

Ease of use: Python is a popular choice for crypto trading bots because it is relatively easy to learn and use. Performance: Python is also a relatively fast language, which is important for crypto trading bots, which need to make decisions quickly.

Is it legal to make a trading bot? ›

Using a trading bot is perfectly legal.

How do I deploy my discord bot? ›

How to host a discord bot
  1. Step 1: Turn on developer mode.
  2. Step 2: Choose applications.
  3. Step 3: Name and create.
  4. Step 4: Add bot.
  5. Step 5: Programme your bot.
  6. Step 6: Set the details.
  7. Step 7: Set bot permissions.
  8. Step 8: Authentication link.
Apr 28, 2023

Are trading bots profitable? ›

Conclusion. Trading bots have the potential to generate profits for traders by automating the trading process and capitalizing on market opportunities. However, their effectiveness depends on various factors, including market conditions, strategy effectiveness, risk management, and technology infrastructure.

Is making a trading bot profitable? ›

Crypto trading bots are profitable. However, it's not as simple as it sounds. You need a deeper understanding of how these tools work. You also need to be equipped with the knowledge to decide whether they are the missing piece in your crypto trading puzzle.

Top Articles
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 5827

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.