Project showcase
Stocks market Analyzer

Stocks market Analyzer © MIT

When Stocks Holder Rise or Fall hard send SMS to certain phone number.

  • 1,134 views
  • 0 comments
  • 1 respect

Components and supplies

About this project

This project is based on internet yahoo finance API to get data about certain Stock holder like google international company as in this example.


Code

CodeC/C++
you need to change the GOGL characters in the request link to yours.
also you need to change +0123456789 to the desired destination phone number.
last step is to change 3.20 , 3.00 to your desired numbers.
#define CUSTOM_SETTINGS
#define INCLUDE_INTERNET_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_SMS_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* Create an Http request with openweathermap.org api url. */
/* It's important to be created here as a global object. */
/*  the link consists from 3 parts
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%27
GOGL
%27%29&format=json&diagnostics=true&env=http://datatables.org/alltables.env

where GOGL is the holder indicator
*/
HttpRequest request("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%27GOGL%27%29&format=json&diagnostics=true&env=http://datatables.org/alltables.env");
static boolean isSent = false;

void setup() 
{
  /* Start communication. */
  OneSheeld.begin();
  /* Subscribe to success callback for the request. */
  request.setOnSuccess(&onSuccess);
  /* Subscribe to json value replies. */
  request.getResponse().setOnJsonResponse(&onJsonReply);
  /* Subscribe to response errors. */
  request.getResponse().setOnError(&onResponseError);
  /* Subscribe to Internet errors. */
  Internet.setOnError(&onInternetError); 
  
  Internet.performGet(request);
}

void loop()
{
}

void onSuccess(HttpResponse & response)
{
  /* Using the response to query the Json chain till the required value. */
  /* i.e. Get the value of 'main' in the first object of the array 'weather' in the response. */
  /* Providing that the response is in JSON format. */
  response["query"]["results"]["quote"]["LastTradePriceOnly"].query();
}

void onJsonReply(JsonKeyChain & hell,char * output)
{
  /* 1Sheeld responds using text-to-speech shield. */
  Terminal.println(output);
  float x=atof(output);
  if(x > 3.20){
    if(!isSent){
      Terminal.println("Arrow is high! It's time to sell.");
      SMS.send("+0123456789","Arrow is high! It's time to sell.");
      isSent = true;
    }  
  }else if(x < 3.0){
    if(!isSent){
      Terminal.println("Arrow is low! It's prefered to buy now.");
      SMS.send("+0123456789","Arrow is low! It's prefered to buy now.");
      isSent = true;
    }  
  }else{
    isSent = false;
  }
  OneSheeld.delay(10000);
  Internet.performGet(request);
}

void onResponseError(int errorNumber)
{
  /* Print out error Number.*/
  Terminal.print("Response error:");
  switch(errorNumber)
  {
    case INDEX_OUT_OF_BOUNDS: Terminal.println("INDEX_OUT_OF_BOUNDS");break;
    case RESPONSE_CAN_NOT_BE_FOUND: Terminal.println("RESPONSE_CAN_NOT_BE_FOUND");break;
    case HEADER_CAN_NOT_BE_FOUND: Terminal.println("HEADER_CAN_NOT_BE_FOUND");break;
    case NO_ENOUGH_BYTES: Terminal.println("NO_ENOUGH_BYTES");break;
    case REQUEST_HAS_NO_RESPONSE: Terminal.println("REQUEST_HAS_NO_RESPONSE");break;
    case SIZE_OF_REQUEST_CAN_NOT_BE_ZERO: Terminal.println("SIZE_OF_REQUEST_CAN_NOT_BE_ZERO");break;
    case UNSUPPORTED_HTTP_ENTITY: Terminal.println("UNSUPPORTED_HTTP_ENTITY");break;
    case JSON_KEYCHAIN_IS_WRONG: Terminal.println("JSON_KEYCHAIN_IS_WRONG");break;
  }
}

void onInternetError(int requestId, int errorNumber)
{
  /* Print out error Number.*/
  Terminal.print("Request id:");
  Terminal.println(requestId);
  Terminal.print("Internet error:");
  switch(errorNumber)
  {
    case REQUEST_CAN_NOT_BE_FOUND: Terminal.println("REQUEST_CAN_NOT_BE_FOUND");break;
    case NOT_CONNECTED_TO_NETWORK: Terminal.println("NOT_CONNECTED_TO_NETWORK");break;
    case URL_IS_NOT_FOUND: Terminal.println("URL_IS_NOT_FOUND");break;
    case ALREADY_EXECUTING_REQUEST: Terminal.println("ALREADY_EXECUTING_REQUEST");break;
    case URL_IS_WRONG: Terminal.println("URL_IS_WRONG");break;
  }
}

Schematics

Circuit
GOGL.fzz

Comments

Similar projects you might like

Bitcoin Email notifier

Project showcase by Guest

  • 615 views
  • 1 comment
  • 1 respect

Track and Control Your Car Remotely

Project tutorial by Ashraf Nabil

  • 25,422 views
  • 5 comments
  • 58 respects

Noise Level Notification Alert

Project showcase by 1Sheeld

  • 1,204 views
  • 0 comments
  • 5 respects

GLCD simple house

Project showcase by soso artist

  • 647 views
  • 0 comments
  • 1 respect

GLCD Cat

Project tutorial by soso artist

  • 639 views
  • 0 comments
  • 1 respect

Foursquare ultrasonic checkin

Project showcase by Guest

  • 552 views
  • 0 comments
  • 1 respect
Add projectSign up / Login