An api class for stocktwits
Failed to load latest commit information. added flags and a new link Dec 5, 2013
index.php added flags and a new link Dec 5, 2013
stocktwits.php Initial Commit Jan 29, 2013


An api for stocktwits

To setup:

    //Include your app information
    $consumerKey = "yourclientkey";
    $clientSecret = "yourclientsecret";
    //Include the Stocktwits class

    // Instanciate the class
    $stocktwits = new Stocktwits($consumerKey, $clientSecret, $redirectUri );

    // thats it!

Examples to use from index.php:

    //generate auth url
    //get access token from the visiting users code
    $accesstoken = $stocktwits->getAccessToken($_GET['code']);

    // get current users profile
    $currentusersprofile =  json_decode($stocktwits->getProfile($stocktwits->userid));

		// You can also get another users profile by entering their ID or name, dont forget to turn into an array with decode
		$stocktwitsprofile = json_decode($stocktwits->getProfile(170), true);
		$howardsprofile = json_decode($stocktwits->getProfile('howardlindzon'), true);
    //getting profiles dosent even require authing!

		// getting the authenticated user's streams is as simple as getStream(nameofstream), home is default, 
		// You will need partner level access, which you can get by applying at

		// Some sample streams for your ease, to find more go to
		$currentUsersHomeStream = json_decode($stocktwits->getStream(), true);
		$currentUsersFriendsStream = json_decode($stocktwits->getStream('friends'), true);
		$currentUsersMentionsStream = json_decode($stocktwits->getStream('mentions'), true);
		$currentUsersDirectStream = json_decode($stocktwits->getStream('direct'), true);

		//There are three types of search, general, symbol, and user

		// Stock symbols use searchSymbol('name')
		$aStockSymbolSearch = json_decode($stocktwits->searchSymbol('aapl'), true);
		$aPersonSearch = json_decode($stocktwits->searchUser('howardlindzon'), true);
		$aGeneralSearch = json_decode($stocktwits->searchGeneral('howardlindzon'), true);
		// Messages can be sent with message($body, $sentiment = null, $in_reply_to_message_id = null, $chart = null)
		// this means you only need body to send it, null values must fill in blanks otherwise

		$body = 'I am testing the stocktwits API! Hi @jayzalowitz @howardlindzon & @stocktwits';
		$sentiment ="bullish"; // Acceptable values: bullish, bearish, neutral. Defaults to neutral. (Optional)
		$in_reply_to_message_id ="17938320";
		$chart = ""; // urls work best here
		$message = json_decode($stocktwits->message($body,$sentiment,$in_reply_to_message_id,$chart), true);