Stock market trend indicators from Bloomberg.com

Currency exchange rates, stock selling prices, metal and everything else from bloomberg.com on your OSX system statusbar.

Posted by Gediminas Siutilas on November 27, 2014

Preface

This script was crafted to demonstrate the usage of ShellWrangler and the possibilities to shell script from which you can benefit tracking any data on the web.

With this ShellWrangler script you can extract any values from bloomberg.com

* If you downloaded ShellWrangler app this scripts will be packed along with the downloaded application.

Currency exchange

For example if you will hit http://www.bloomberg.com/quote/EURUSD:CUR you will end up tracking EUR per USD currency exchange trend as follow:

With this script you will be able to track numerical & percentage trend values like: 0.0139 and 1.13% as per example.

Script configuration:
run() {
	## currency exchange trend since market open
	drawCurrencyTrendInfo EUR USD CUR
}

Stocks market overview

Let's say you want to track APPLE stock price. If you will hit http://www.bloomberg.com/quote/AAPL:US bloomberg.com will render you as follow:

So those numbers can be easily exposed to your OSX statusbar:

Script configuration:
run() {
	## company stocks trend since market open
	drawCurrencyTrendInfo AAPL US
}

Trending indicators can be combined on your statusbar with easy configuration:

Script configuration:
run() {
	## currency exchange trend since market open
	drawCurrencyTrendInfo EUR USD CUR
	
	drawSeparator	
	
	## company stocks trend since market open
	drawCurrencyTrendInfo AAPL US
}

Script:

Configuration point is the 'main' method. Based on bloomberg.com parameters ('FB' & 'US') for example: "http://www.bloomberg.com/quote/FB:US" you need to feed those 'drawCurrencyTrendInfo' method like:
drawCurrencyTrendInfo FB US
Download
#!/bin/bash

#   ____ __        __ __ _      __                       __         
#  / __// /  ___  / // /| | /| / /____ ___ _ ___  ___ _ / /___  ____
# _\ \ / _ \/ -_)/ // / | |/ |/ // __// _ `// _ \/ _ `// // -_)/ __/
#/___//_//_/\__//_//_/  |__/|__//_/   \_,_//_//_/\_, //_/ \__//_/   
#                                               /___/               
#  _    _                _                      _            
# | |__| |___  ___ _ __ | |__  ___ _ _ __ ___ _(_)_____ __ __
# | '_ \ / _ \/ _ \ '  \| '_ \/ -_) '_/ _` \ V / / -_) V  V /
# |_.__/_\___/\___/_|_|_|_.__/\___|_| \__, |\_/|_\___|\_/\_/ 
#                                     |___/                  
# Script author: gadominas@gmail.com   
#
#   Stocks, Currency, Metals selling/exchange marget is for your disposal with this
#  script. You can track any currency exchange, stocks, metal price trend.
# 
# Script fetches the data from bloomberg.com. Everything what you see in bloomberg.com
# you can get it on your taskbar with this script through ShellWrangler.
#
#$$${ Bloomberg.com stock market trend indicators on your OSX statusbar }                                                                                    

drawTrendingDirection() {	
	trendingDirection=$(echo $1 | grep -E 'trending_up')

	if [ ! -z "$trendingDirection" -a "$trendingDirection"!=" "  ];
		then
			printf "🔺 "		
	  	else
			printf "🔻 "		
	fi
}

showTrendingNumbers() {	
	trendingInfo=$(echo $1 | sed 's|\([0-9].[0-9]*\)|\1 |')
	
	delta=$(echo $trendingInfo | grep -Eo '[0-9].[0-9]*[ ]')
	deltaPercentage=$(echo $trendingInfo | grep -Eo '[0-9].[0-9]*[''%'']')
	
	printf "%s%c%s%s" $delta '|' $deltaPercentage
}

drawCurrencyTrendInfo() {
	from=$1
	to=$2
	type=$3
	
	# remap arguments in case of 2 were passed instead for example for stocks trend
	if [ "$#" -ne 3 ];
		then {
			to=
			type=$2
		}
	fi
	
	trendInfo=$(/usr/bin/curl --silent \
	 "http://www.bloomberg.com/quote/$from$to:$type" |  \
	 /usr/bin/grep -E 'trending_' )
	
	if [ ! -z "$trendInfo" -a "$trendInfo"!=" " ];
		then {
			drawHeader $from $to
			drawTrendingDirection "$trendInfo"	
			showTrendingNumbers "$trendInfo"
		} else
			## Connection timeout?
			printf "?!"
	fi
}

drawHeader() {
	if [ ! -z "$2" -a "$2"!=" " ];
		then 
			printf "%s:%s" $1 $2
		else
			printf "%s" $1
	fi
}

drawSeparator() {
	printf "%s" " "
}

run() {
	## currency exchange trend since market open
	drawCurrencyTrendInfo EUR USD CUR
	
	drawSeparator	
	
	## company stocks trend since market open
	drawCurrencyTrendInfo AAPL US
}

run