Photo by Roman Synkevych on Unsplash

In the final part of this setup series on How to build a Production-Ready Algorithmic Trading Framework, we will talk about the most important part of any software development lifecycle, version control, or as it's commonly known, GIT.

If you have joined me late in this series, you can find the intro blog below. It has all the links to the rest of the articles you will need to make my wild dream come true. Let’s get started.

A prerequisite for this, you will need a GitHub account. If you don't have one yet, WHAT ON EARTH ARE YOU… I’m only kidding. Follow the link below, get one and be thankful that all your projects are safe in the cloud on a stranger's server.

For the upcoming project there is a Github Here. Please star, fork and help me make this framework better.

Once you have a nice new account and have signed in, the fun can begin. Click the big green button in the top-left that says ‘New’. You will be presented with the following screen; copy what I have done. If you want to understand more about what it all does, smarter people have written amazing blog posts about it. This article is designed to get you up and running.

New Repository

This project’s GitHub will be staying private for the time being. When I have finished the series and testing, I will make the project code publicly available (I guess you are going to have to subscribe to stay up to date, ehe)

Authenticating With GitHub through SSH

To send things, we need to set up the SSH link between your local dev machine and GitHub.

In your terminal (be sure you are not in a conda environment), enter the following commands. You can press enter to every prompt after entering the below command unless you want to password-protect this file (it is recommended), but we won't for the sake of simplicity.

ssh-keygen -t ed25519 -C "YOUR_GIT_HUB_EMAIL"

Next, you will enter the following:

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_ed25519

Now this bit is tricky depending on where your ‘.ssh’ file is saved. On Linux and Mac, it is normally here “/Users/PC_USERNAME/.ssh”.

And for Windows “%HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub”

This matters as the next command will print out your SSH key that you will copy and paste into GitHub. Using this command will print the key:

cat /Users/USER_NAME/.ssh/id_ed25519.pub

If done correctly, you should see something like this printed out:

ssh-ed25519 AAAAC3NzaokfbwefAAAIIye2gCf6hPfoienrpfnerpv8YK3tuv2mgKpbsenm GIT_HUB_EMAI

Head over to GitHub and click on your account icon in the top right of the screen, click ‘Settings’ and head into ‘SSH and GBG keys’. Click ‘New SSH key’. Give it a name and copy and paste the key we printed out above. You should be authenticated and ready to push into Git.

Add SSH Key to GitHub

Linking GitHub to Local Code

Next, we will link our PyCharm project with the GitHub repo. Head over to the repo we created earlier and see something like this. Keep this tab handy, as we will need something from it soon.

We want to head on over to PyCharm, and inside our project, we will be using the terminal. We are going to input some commands to get everything ready. Don't worry I will explain what each command is doing.

By default, we will be inside our conda environment, and to set Git up, it's better to do this in a global environment. Most modern computers have Git preinstalled. You will know if you are out of the environment as it will say ‘(base)’.

conda deactivate 

The next command checks if there is a Git repo already set up (this is unlikely), but it's good practice to check. If you get a result like the one above, happy days, we have not got an existing git repo.

git status

Let's set one up using the following command, this initialises a local git repo. It will print out where the git repo information on the terminal.

git init

Next we want to create a ‘.gitignore’ file, this does exactly what it says on the tin, it will ignore files when uploading to Github. Why do we need this? Sometimes you don't want to upload important information files or your entire database, just the code. Writing the names of those files in here will make Git ignore those files.

touch .gitignore

To access add to the ‘.gitignore’ file, we use the following command

nano .gitignore

This will bring up the following text area to input your desired ignore files, I have put the following in as an example. But as the project grows, you can add to it by opening it up with the above command in the terminal.

Using the ‘*’ wild card function means anything inside that folder or has that name. Once you are happy with your list, hit CTRL + X and press ENTER to save.

Next, we want to add the files we want to upload (or commit) to the git repo and type the following command. This will add everything within the ‘DataSpace’ directory to the commit list. If you added anything to your ‘.gitignore’, it should print on the terminal that they will be ignored; good work git!

git add *

When we upload to GitHub, it's required to give that upload a name, the following commands will allow you to add that message; this is so you know what the commit was all about, I am going to use “init” as this will be the first commit and not much has happened. The ‘-m’ is a flag for a message.

git commit -m "init"

Now we need to tell our local git version its origin is online. We do the following command. You can find the commands to copy and paste in our repo, I told you to keep this safe earlier.

git remote add origin git@github.com:YOUR_GITHUB_USERNAME/DataSpace.git
git branch -M main
git push -u origin main

if all goes well, you should see the following, try refreshing the page on GitHub, and you will now see our project and all the directories.

Files Being pushed to GitHub

--

--