From the last two years, I was planning to invest some money into Bitcoin and yet, here we are, with the price of Bitcoin up more than 2000% in the past 24 months. I just kept thinking and I got nothing. The price was fluctuating and I was waiting for a good time and that good time never come. I wish someone had alerted me at that time. And finally, in November, I invested my some money in various cryptocurrency and yes I got some good return in just two months.
But I am not a full-time CryptoInvestors and I can't keep checking the price every time on my laptop. But I also want to sell or buy my coins at a good time. so I planned to build my crypto alert system using Bolt IoT that will notify me the best time to become rich :).
The best thing that I like about Bolt IoT is the easy interface to quickly build the IoT product.
Ok, so let's get started and see how easy this project goes.
Step 1. Hardware SetupPlug the longer end of the Buzzer in the Pin 0 of Bolt WiFi module and the shorter end to the ground pin (GND) using Male/Female Jumper Wire.
Login to cloud.boltiot.com and note the ID of your Bolt WiFi Module.
Now click on the API Tab and under the section for Generate Key, click on Enable.
Next click on the copy button to copy your API key. Your API key will may look something like this: f1f918e9-d9c2-4e5b-aed0-b7cb743f74cf
Step 3: Setting up your EnvironmentFor this project, I am using Ubuntu 14.04 with python 2.7 but you can use other OS also, you just need to find out the alternatives for that or you can buy some online ubuntu server here www.digitalocean.com .
Login to your Ubuntu server and create a folder and you can give any name to the folder.
mkdir crypto_alert
After creating the folder we will go inside the folder by typing the below commands.
cd crypto_alert
now we shall install the pip package manager for Python-2.7. A pip command is a tool for installing and managing Python packages, such as those found in the Python Package Index, For example, boltiot, Twilio etc.
sudo apt-get -y install python-pip
and then we will install the python virtualenv and virtualenvwrapper.
virtualenv will help us to create isolated Python environments. Type the below command to install virtualenv and virtualenvwrapper.
sudo apt-get install python-virtualenv
sudo pip install virtualenvwrapper
After installing the virtualenv and virtualenvwrapper , we will add it in bashrc file.
Type the below command.
sudo echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
sudo echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc
.
Now installation is done and we will create a virtual environment.
mkvirtualenv crypto_alert
The above command will create virtual environment with name crypto_alert
and we will activate the crypto_alert virtual environment by typing the below command.
workon crypto_alert
and then we shall install the boltiot packages and after installing the boltiot packages.
pip install boltiot
pip install --upgrade pip
and we will install some security packages because we will be using some external API.
pip install pyOpenSSL ndg-httpsclient pyasn1
pip install 'requests[security]'
We will use cryptocompare to fetch the current Bitcoin rate using GET request. You can also fetch the rate for other coins.
In the first four line of below code, we are importing the json, request , time and Bolt packages. and in last four line we are just setting some global variables like our desired SELLING_PRICE , Bolt Cloud API key and device ID and in the last line creating a bolt object.
import json
import time
import requests
from boltiot import Bolt
SELLING_PRICE = 17082.93
API_KEY = "1c52500c-0b77-4370-bd0a-015fedce1db5"
DEVICE_ID = "BOLT3433748"
bolt = Bolt(API_KEY, DEVICE_ID)
Then I wrote a function to fetch the current Bitcoin rate from cryptocompare. The below function will return the per bitcoins rate in US doller. You can also fetch the rate for other cryptocurrencies also.
def price_check():
url = "https://min-api.cryptocompare.com/data/price"
querystring = {"fsym":"BTC","tsyms":"USD"}
response = requests.request("GET", url, params=querystring)
response = json.loads(response.text)
current_price = response['USD']
return current_price
and then in last I wrote a infinite while loop that keep checking the bitcoins price in every 4 second and will switch on and off the buzzer according to conditions.
while True:
market_price = price_check()
print "Market price is", market_price
print "Selling price is", SELLING_PRICE
time.sleep(4)
if market_price > SELLING_PRICE:
bolt.digitalWrite("0", "HIGH")
time.sleep(60)
bolt.digitalWrite("0", "LOW")
Save the code wih crypto_alert.py
and execute it by typing
python crypto_alert.py
and the alarm will beep as soon as market price will become greater than your desired SELLING_PRICE
I have been using this system from from past few days and it helps me a lot in bitcoin trading.
Comments