Retrieves detailed sentiment analysis, message volume, and participation metrics for a given symbol across different timeframes.
Request Method | HTTP GET |
Accept | application/json |
URL |
https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/{symbol}/detail |
Path Parameters |
symbol (required) - Stock symbol to get sentiment analysis for (e.g., AAPL, NIFTY50.NSE)
https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/AAPL/detail |
Compression | Gzip. To connect to the stream using Gzip compression, simply send an Accept-Encoding header in the connection request. The header should look like the following:
Accept-Encoding: gzip |
Read Timeout | Set a read timeout on your client, and ensure that it is set to a value beyond 30 seconds. |
Authentication | Basic Authentication using username and password |
The following responses may be returned by the API for these requests. Most error codes are returned with a string with additional details in the body. For non-200 responses, clients should attempt to reconnect.
Status | Text | Description |
---|---|---|
200 | Success | Sentiment data successfully returned. |
401 | Unauthorized | HTTP authentication failed due to invalid credentials. Verify that your login combination matches this site, and that your user has the needed permissions. |
503 | Service Unavailable | Stocktwits server issue. Retry using an exponential backoff pattern. If no notice about this issue has been posted on this site under status, email support@stocktwits.com. |
The following example request is accomplished using cURL on the command line.
curl -u 'username':'password' -H"Accept: application/json" "https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/AAPL/detail"
If you are working on Windows, you may need to use double quotes instead of single quotes for the username and password.
curl -u "username":"password" -H"Accept: application/json" "https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/AAPL/detail"
The following example request is accomplished using a python script with the requests library.
''' This script uses the "requests" library to get sentiment data. It should be installed using pip before running this script. ''' import requests from requests.auth import HTTPBasicAuth username = "myusername" password = "mypassword" symbol = "AAPL" # Create a request to get sentiment data try: resp = requests.get( f"https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/{symbol}/detail", auth=HTTPBasicAuth(username, password), headers={"Accept": "application/json"} ) except Exception as e: print(f"Error creating request: {e}") exit() # Check for errors on the response a HTTP status code of 200 is expected if resp.status_code != 200: print(f"Error response: {resp.status_code} {resp.reason}") exit() # Print the response data try: print(resp.json()) except Exception as e: print(f"Error reading response: {e}") exit()
The response object contains a "data" field with three main sections:
Field | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
messageVolume |
Contains message volume metrics for the following timeframes:
|
||||||||||||||||
sentiment |
Contains sentiment metrics for the following timeframes:
|
||||||||||||||||
timeframes |
Contains detailed metrics (buzz, message volume, participation score, and sentiment) for the following timeframes:
|
labelNormalized |
Returns a string representing the normalized sentiment attitude or activity level of a given score.
Possible values:
|
valueNormalized | If the value is z-score, valueNormalized is the CDF of the zScore. If the value is a range of 0..1 valueNormalized is value*100. |
{ "data": { "messageVolume": { "15m": { "labelNormalized": "NORMAL", "valueNormalized": 50.5 }, "24h": { "labelNormalized": "HIGH", "valueNormalized": 75.2 }, "now": { "labelNormalized": "LOW", "valueNormalized": 25.8 } }, "sentiment": { "15m": { "labelNormalized": "BULLISH", "valueNormalized": 65.3 }, "24h": { "labelNormalized": "NEUTRAL", "valueNormalized": 50.0 }, "now": { "labelNormalized": "BEARISH", "valueNormalized": 35.7 } }, "timeframes": { "1D": { "buzz": { "labelNormalized": "NORMAL", "valueNormalized": 52.1 }, "loaded": true, "messageVolume": { "labelNormalized": "HIGH", "valueNormalized": 78.4 }, "participationScore": { "labelNormalized": "NORMAL", "valueNormalized": 55.2 }, "sentiment": { "labelNormalized": "BULLISH", "valueNormalized": 68.9 } } } } }