Empire Avenue Stock Quotes by SMS

What is Empire Avenue

This weekend we started playing around with Empire Avenue. According to their website, “Empire Avenue is the Social Media Exchange, where you can buy and sell shares in any social media profile, meet new people, unlock Achievement badges, and earn boatloads of virtual cash by being active and social online! Buy shares in your friends, your followers, people with similar interests, brands you love, celebrities – anyone! All using a virtual currency and all for free!”

Get Stock prices by SMS/TXT Message

In this day and age we all carry smart phones that are web enabled so you can quickly access Empire Avenue using a browser or one of the native mobile apps; but we decided we wanted to be able to get access to Empire Avenue using SMS Text Messages too!

So first, we looked at the Empire Avenue API to see what kind of access we could get. (You can check out the complete API Documentation online.) For this first prototype we decided to use the GET Request to get some info back on certain Stocks/Tickers. We wanted to be able to send a text message with our ticker “DISRUPTIVE” to a phone number to get back the most recent stock price.

Next we had to find a way to actually receive and send the SMS text messages. This is where Tropo comes into play. (Check out the Tropo website for more information about Tropo and how this all works.) According to their website, “Tropo is a powerful yet simple API that adds Voice, SMS, Twitter, and IM support to the programming languages you already know.”

Using Tropo we can build the application to send and receive SMS messages. Tropo supports a slew of different programming languages including Java, PHP, and Ruby. We choose to use PHP. Writing a Tropo app in PHP is as simple as:

<php
say('Yes, Tropo is this easy.');
// Yup, that easy
?>

So how did we build this thing? Here are some code examples:

First things first, we setup a Tropo account on Tropo.com, all you need is a valid e-mail address to register and there is no cost for development accounts! Wait for the e-mail conformation to activate the account and once that is done you can start creating Tropo Applications, in this case we opted for a simple Tropo Scripting Application where the app is hosted on the Tropo Platform.

To create a new Tropo Application you can just go to Your Application, select ‘Create New Application’ and setup a Tropo Scripting Application. We won’t go through a step-by-step on how to do this, as there are tons of great tutorials you can look at on the Tropo website.

We also needed an Empire Avenue account with which to associate our new Tropo Application, so next we went to the Empire Avenue Website and setup an Empire Avenue account (you can login using your Facebook account). Once we were all setup on Empire Avenue, we went to the setting section of our profile and setup a new Application. This was needed because Empire Avenue uses both username and password for the account and API keys to authenticate third party applications.

Once we had the API keys we went back to writing the actual application. Not too complex. First we needed to be able to receive messages. Using the Tropo Scripting Language, you can use the “Ask Method” to do something like this:

<?php
 if($currentCall->initialText=="Yes") {
 say("Awesome, I totally agree.");
 }
 elseif($currentCall->initialText=="No") {
 say("Well that's just too bad");
 }
 else {
 say("That wasn't an option, sorry");
 }
?>

And once that was done we needed to write something to lookup the Ticker info on Empire Avenue. Using the API keys and and username and password we wrote some code to hit the API:

<?php

// Fetch EAV function - gets the data for a ticker from Empire Avenue.
function fetchEAV($ticker) {
 $ticker = trim(strtoupper($ticker));

 // API Url
 $url = 'https://api.empireavenue.com/profile/info?apikey=API_KEY_HERE&username=EAV_USERNAME&password=EAV_PASSWORD&ticker='.$ticker;

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 if (curl_error($ch)) {
 say("ERROR ". curl_error($ch));
 die();
 }
 $output = json_decode(curl_exec($ch));
 curl_close($ch);
 if (strtoupper($output->data[0]->ticker) <> $ticker) {
 // Debugging stuff:
 //say($output->data[0]->ticker);
 //die();
 return false;
 } else
 return $output->data[0];
}

// Get the data from Empire Avenue's API
$result = fetchEAV($currentCall->initialText);
if ($result)
 say("Last Traded Share Price: ".$result->last_trade);
else
 say("Invalid ticker.");

?>

And does it work?

It really does, if you want to see a working sample just send a text message with DISRUPTIVE to (818) 900-2731 to get back our latest stock price or replace DISRUPTIVE with your own Empire Avenue Ticker Symbol to get your own latest stock price!

By Cas Hoefman & Michael Mackus

blog comments powered by Disqus