chmod 400 /Users/markwindsor/Desktop/binanceKey.pem
Connect to the EC2 instance:
Use SSH to connect to your instance:
ssh -i /path/to/your-key.pem ec2-user@your-ec2-public-dns
example:
ssh -v -i 'c:/Users/markw/Desktop/binanceKey.pem' ec2-43-198-247-154.ap-east-1.compute.amazonaws.com
Install Python:
Most Amazon Linux AMIs come with Python pre-installed. If it's not installed, or if you want a different version, you can install it using package managers like yum
or apt
.
sudo yum install python3 # For Amazon Linux
Write your Python Script:
Once connected, create a Python script using an editor like vim
, nano
, etc.
nano my_script.py
Write your desired Python code in this script.
Set Up cron
:
Open the crontab
editor:
crontab -e
Add a new line to make your script run every hour. The cron
syntax is minute, hour, day of the month, month, day of the week, followed by the command to be executed:This means the script will be executed when the minute is 0, i.e., at the start of every hour.
0 * * * * /usr/bin/python3 /path/to/my_script.py
Logging
If you want to keep track of your script's output or errors, you can redirect them to log files:
0 * * * * /usr/bin/python3 /path/to/my_script.py >> /path/to/output.log 2>> /path/to/error.log
59 * * * * source atlas_trade_prod/venv/bin/activate && atlas_trade_prod/venv/bin/python atlas_trade_prod/src/statistical_arbitrage_crypto/ATOM_AXS.py >> atlas_trade_prod/src/statistical_arbitrage_crypto/atom_axs_logfile.log 2>&1
Permissions:
Ensure your script is executable. You might need to provide execute permission to your script:
chmod +x /path/to/my_script.py
Testing:
* * * *
can help you verify that everything is working as expected.Update the EC2 Instance:
It's a good practice to ensure your instance is updated. If it's an Amazon Linux or similar instance, you can use:
sudo yum update -y
Install Git:
If git
isn't already installed, you'll need to install it:
For Amazon Linux or similar:
sudo yum install git -y
Clone the Repository:
Use the git clone
command followed by the repository URL:
git clone <https://github.com/atlas-finance-io/atlas_trade_prod.git>
Navigate to the Cloned Directory:
After cloning, you can navigate to the directory:
cd atlas_trade_prod
From here, you can see all the files in the repository using the ls
command and proceed with any other actions you'd like to perform.
sudo yum install python3-pip -y
pip3 install --user virtualenv
virtualenv
command is still not found after installation, it might be because the local bin directory where user-specific Python packages are installed isn't in your PATH. Add it:echo 'export PATH=$PATH:/home/ec2-user/.local/bin' >> ~/.bashrc
source ~/.bashrc
Now, try creating your virtual environment with the virtualenv
command.
virtualenv venv
This will create a new directory named venv
in your project directory.
source venv/bin/activate
Once activated, your terminal prompt should change, indicating that the virtual environment is active.
pip3 install -r requirements.txt
This assumes you have a requirements.txt
file with your project dependencies.
truncate -s 0 logfile.log
** IP address of EC2 instance changes when you start and stop the instance