Investment Price Monitoring Tools For Linux Lite Diamond 4.x Series

1) A Few Comments Before We Begin

Linux Lite 4.0 is a simple intuitive and beautiful rendering of the XFCE desktop, perhaps the best available these days. It truly manifests its own mission statement at an extremely professional and cordial level, again perhaps better than any other Linux distribution out there. Its developers’ wonderfully rendered vision is something we are not going to tamper with, but we are going to tap into its powerful Ubuntu heart a bit to add some tools and some new simple and useful investment monitoring tools. In recent years APIs have added new and interesting potential for data and content usage with Linux applications. At one time both the Yahoo and Google Finance APIs offered free access to stock market data. That is no longer the case, which is disappointing because there were many very nice Linux applications, in several programming languages, such as Java, Java via npm, Go language, C++, & Ruby to accomplish the retrieval of market data from those free APIs, not to mention full featured implementations like Chart Geany and GNUcash. Personally, and I think keeping a bit within the Linux Lite philosophy, given that these APIs seem to come and go now, I think the best solution for dealing with such data is BASH scripts that invoke the proper base applications like LibreOffice Calc when necessary, and display simpler information like real time quotes in the terminal. Such scripts are easily changed when free APIs come and go, and in the case of simple price quotes values can be easily changed as well. As I have worked and tested the last few weeks on this project the most reliable free API I have found is AlphaVantage, so that is the one we are going to use. *(If you are good with Ruby, Stefano Martin has already developed a complete featured Ruby wrapper for the AlphaVantage API, but you will need Gems for the particular applications you want to run with it. If you’ve never programmed Ruby or C++ the learning curve is quite steep.) As I mentioned before, regarding the stock markets, and the inconsistent availability of free APIs, I think we are better off with a script set.

https://www.alphavantage.co/

https://github.com/StefanoMartin/AlphaVantageRB

2) Preparation

We need to install wget to our Linux Lite 4.0 system. Curl will work fine over good Internet connections but wget is more robustly tunable for bad, noisy, or slow connections. In LL 4.0 open up >Menu>System>Install/Remove Software (Synaptic) and enter wget into the search box.

Mark it for installation and click the apply button. After wget completes installing type figlet into the search box and find figlet. We’re going to display real time stock quotes in the terminal so we’re going to add a fancy ASCII text for a title.

Mark it for installation and click the apply button. After it installs close >Install/Remove Software (Synaptic). Next we need to create a few new folders. Open Thunar file manager making sure it is open to your user name folders. Right click on a blank space in the folder view and select create new folder and create a new folder called litemarkets. When the folder appears click on it to open it and create a folder inside it called temp. Still in the litemarkets folder create another folder called intraday. AlphaVantage is a robust data API. Every connection other than batch or global quote can produce a considerable amount of market data. We will use the temp folder to hold intraday data to pass to LibreOffice Calc and then save it as a spreadsheet into the intraday folder. Once saved as a spreadsheet the data becomes malleable and can be worked into graphs, charts, and database algorithms, if you’re into such things, the beauty being the only Java is on the API end until you add something of your own.

Now we should go to the AlphaVantage web site (see the first link) and get our free API key.

Click get your free API key and follow the instructions. Once you have your new key open a new document in LibreOffice writer and copy and paste your API key into the document. Save the document as alpvaninfo.odt in your new litemarkets folder. Next go to the AlphaVantage web site and click on the API Documentation + Examples button.

As you will notice the AlphaVantage API is very full featured. We are only going to prepare two scripts, one for terminal display of current stock prices, and the other for data handling of time series files (in this case intraday, but most time series data in a delimited file like .csv can be handled the same) with LibreOffice Calc.

Click on >intraday in the left menu and scroll down on the right to find the address of the downloadable CSV file. Highlight it and copy and paste it to your alpvaninfo.odt file in your litemarkets folder. You can use this copy and paste method for all the CSV addresses available from the API. If you intend to do some heavy lifting like using trading algorithms and historical charts and graphs you may want to add some more in depth functionality to LibreOffice Calc. (See image below). What we are doing here is showing ordinary users how to automate and use the API addresses supplying delimited file data simply via BASH scripts.

3) Building Your Automating Scripts

Okay. Let’s go ahead and build our first script, and let’s begin with the intraday API address. In Linux Lite 4.0 go to >Menu>Accessories>Text Editor and open up the onboard simple text editor and make it full screen.

On the first line type the entry below.

#!/bin/bash

On the second line type the entry below.

wget -q -P /home/yourusername/litemarkets/temp/ “

*The -q initiates wget in quiet mode (no terminal messages) and the -P /home/yourusername/litemarkets/temp/ will print the downloaded CSV file to our temp folder. It’s sensible to use a folder here though we could use a temp file instead and the –noclobber action available in wget. Either way is fine, but a folder is better for new users.

Our next step is to copy and paste the intraday data address we saved in our alpvaninfo.odt file after the leading quotes in our line above and enclose it with a closing so it looks like the line below. *Also remember to change yourusername to whatever your actual user name is.

wget -q -P /home/yourusername/litemarkets/temp/ “https://www.alphavantage.co/queryfunction=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo&datatype=csv

I have put the line in a smaller font so most of you will see it displayed as a single line of code, which is what it should be. We need to edit it to insert the new API key. Using your cursor navigate to apikey=demo in the long line and backspace out demo and then type in or copy and paste you new API key stored in your alpvaninfo.odt file. Keys are usually 16 characters long. You may use any recognized stock symbol. Simply backspace out MSFT in the variable symbol=MSFT and type in a new symbol like FB for Facebook or T for AT&T or whatever you want to follow. Any stock trading publicly on NASDAQ or NYSE will work.

Okay. We have our first two lines in our script. Enter the third line just like the line below. Follow the spacing exactly. There is a space between the * and the .csv.

libreoffice –calc /home/yourusername/litemarkets/temp/* .csv

Next click >File>Save As in the window frame dropdown menu and save the file to your litemarkets folder as intraday.sh

The script file is not yet executable. There are two simple ways to make it so. Right click on it in Thunar and select >Make file executable from the menu. Logout and back in again and it should work though it will not execute directly from Thunar. The most reliable way is to open your XFCE terminal and type at the prompt: chmod +x ~/litemarkets/intraday.sh

Linux Lite 4.0 is a beautiful Linux operating system, but for our script to run without errors in the terminal, we must disable system sounds. Login and logout sounds don’t matter, but system sounds is not fully integrated into LibreOffice Calc and ALSA library errors will print to the terminal with system sounds enabled. I am researching a solution for this, but for now just go to >Menu>Settings>Settings Manager>Lite Sounds and click the >Disable System Sounds button before running our script.

To run the script open a terminal and type at the prompt: ./litemarkets/intraday.sh It should produce a screen like the one below.

Just click OK and spreadsheet will load the CSV. A warning may appear reminding you that the file you are viewing does not exist. Just click OK and we’ll make it exist from the screen below that appears next.

Click >File>Save As in the Window Menu Bar and save the file as intraday1.ods into ~/litemarkets/intraday and you now have a usable spreadsheet of your data saved. If you like you can open Thunar and delete the query CSV file from your ~/litemarkets/temp folder afterwards, or leave it there if you intend to use database functions for another operation. This LibreOffice Calc BASH script will work the same for any delimited file data you wish to process via spreadsheet that is available on the AlphaVantage API, so we will not configure any other addresses now. Just remember to add new folders to save to, to your litemarkets folder to differentiate your data. You can use the same temp folder.

Now we are going to configure a delimited file data retrieving address that obtains price quotes of a list of ten stocks showing opening, high, low and current, prices, that will display in a terminal. Originally the AlphaVantage API offered a batch quote address, but has now simplified it into a global address. I expect this is because batch is actually command and not a pure variable on some systems and global allows a delimited list anyway, however batch as a function still works with the API on Debian/Ubuntu OSs, so we will use it here.

Once again open up simple text editor on your Linux Lite 4.0 desktop and toggle it to full screen. Type in the first line like the line below.

#!/bin/bash

On the second line we’ll add a large ASCII title using figlet to display in the terminal above our current price quotes table.

figlet -f small “Lite Stock Prices”

On the next line we’ll use figlet again to pass a line of text crediting the developers.

figlet -f term “Quotes courtesy of AlphaVantage API & IEX”

On the next long line of code we begin with wget -q again but pass the -O option to print our downloaded delimited file to our terminal, and because delimited files print without a nice tabular presentation we will pipe | our data to the column function. Again you will have to replace demo with your 16 character API key, and the stock symbols are all optional. Again this line is all one long line of code though it may not display that way in your browser as you read this. Don’t forget the trailing , after -s.

wget -q -O - “https://www.alphavantage.co/query?function=BATCH_QUOTES_US&symbols=FB,GOOG,AMZN,AAPL,MSFT,VMW,AMD,INTC,T,IBM&apikey=DEMO&datatype=csv” | column -t -s,

Now save this file to your litemarkets folder as quotes.sh

Open a terminal now and type chmod +x ~/litemarkets/quotes.sh You may have to log out and back in again on some systems afterwards for the script to run the first time. To run the script open a terminal and toggle it to full screen and type at the prompt ./litemarkets/quotes.sh The result should look like the image below.

To finish our automation we are now going to alias our shell script commands in our ~/.bashrc file. Open Thunar and make sure to choose Show Hidden Files in the view options.

Next locate your .bashrc file in you home directory.

Right click on the file and select >open with text editor.

Move your cursor to the line below the listed aliases as shown above, and add the following two lines as shown below.

alias intraday=’./litemarkets/intraday.sh’

alias prices=’./litemarkets/quotes.sh’

Save the file. Close Thunar, and log out and back in again. Now when you open your terminal you can type either prices or intraday to run your scripts.

4) Getting Crypto-Currency Prices

Unlike the US stock exchanges, there are many free APIs for downloading crypto-currency price data. The Alphavantage API provides a decent but somewhat laboriously configurable download address, especially if you want to work with and monitor several different C-Cs. Rather than write all the wget shell scripts necessary for monitoring many C-Cs and C-C markets we are going to recommend a very nice Ruby device here called coinpare. There is also a decently featured and somewhat lighter nodejs and/or npm based application called coinmon which you may prefer if you are worried about system weight. Below is the link to the coinmon website and an image of it in action in Linux Lite 4.0.

https://github.com/bichenkk/coinmon

I am not going to go through the installation process for coinmon now other than to say it is a fairly simple process which can be done three different ways, the easiest with npm and/or github clone.

As I said before we are going to install coinpare, a comprehensive and beautifully displaying Ruby wrapper and console application using many APIs that will really look good in our XFCE terminal, and because it’s Ruby we can simply add its commands to our prices script and produce a screen with our stock price quotes and our crypto-currency price quotes with the single BASH command: prices which we just finished automating.

In your Linux Lite 4.0 system open up >Menu>System>Install/Remove Software (Synaptic) and type ruby into the search box. Find the entry for ruby-full. Mark it for installation and accept all its dependencies. Click >Apply and install. See below.

When installation completes close >Install/Remove Software (Synaptic) and logout and restart you system. After the system reboots open a terminal on your desktop and enter ruby -v at the prompt. Your terminal should return the information below, specifying the current Debian version for Ubuntu.

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

Okay ruby-full is installed. Ruby uses the gem command to install available components for an application. A complete gem contains the bundled software packages required to run a ruby coded application. To install coinpare enter the line below into your terminal.

gem install coinpare

After installation completes logout and back in again. Now open a terminal and toggle it to full screen and simply type coinpare. The screen below should appear in your terminal.

As I mentioned before we want to automate this further. Let’s return to our already aliased ~/litemarkets/quotes.sh script file and add some entries for crypto-currency price monitoring. Let’s add a couple more figlets for looks, and a couple of coinpare commands. We’re going to use the commands coinpare coins (which returns the aggregate average price for the 10 most active coins at any given moment) and just for the sake of symmetry coinpare markets LTC (which returns the prices for LiteCoin on various exchanges at any given moment. The base currency for the application is US $ but others are available. Enter coinpare help at your terminal prompt for more information. Below is the link to coinpare’s web page on git-hub.

https://github.com/piotrmurach/coinpare

Okay let’s open up our script at ~/litemarkets/quotes.sh with Linux Lite’s simple text editor. I should mention because our applications involve connecting to various data servers over the Internet I don’t recommend chaining commands with operands (*exception being wget connection issues that require functions to clean up). By putting each new command on a new line we are allowing each command to complete before another is run.

Okay on the next line below the long wget line add the lines below in order.

figlet -f small “Lite Crypto$”

coinpare coins

figlet -f small “LiteCoin Market$”

coinpare markets LTC

Save the script and you’re good to go. Open a terminal and toggle it to full screen and type prices at the prompt. If all has gone well you should load a nice looking screen like the one here below.

In this case you may have to scroll down a little but you could fit it in one whole screen by using smaller figlets. You can also narrow the first crypto table by not including the volume or market cap cells. You now have a very customizable group of nice looking investment monitoring tools.

*This tutorial was prepared on Debian 9 with LibreOffice Writer/Web and images from Linux Lite 4.0 screenshot tool. This installation process for coinpare requires Ruby Version Manager RVM to do correctly in Debian 9. The required hitimes gem will not install correctly on older ruby versions in Debian 9.

RETURN to Cruz Analytics