### Complete event JSON example Source: https://firestream.stocktwits.com/documentation/symbols-stream Full example of a streamed event object. ```json { "symbol_id": 125625, "symbol": "AAPL", "metric": "pageview", "user_id": 5548695, "created_at": "2015-12-24T20:00:01Z", "seq_id":"49567487888076093524624994048752032346222860024699420674" } ``` -------------------------------- ### prices array example Source: https://firestream.stocktwits.com/documentation/stream Complete example of the prices array with a single price object. ```json "prices": [{ "id": 686, "symbol": "ABC", "price": "29.84" }], ``` -------------------------------- ### Example JSON row (base version) Source: https://firestream.stocktwits.com/documentation/symbols-reference Example JSON row for the base version, showing all standard fields. ```json { "symbol_id": 125625, "ticker": "AAPL", "exchange": "NASDAQ", "country": "US", "asset_class": "equity", "delisted": false } ``` -------------------------------- ### Complete block object example Source: https://firestream.stocktwits.com/documentation/stream A complete JSON example of a block object with all fields. ```json { "id": 19037074, "user_id": 654527, "muted": false, "blocked_user_id": 364216, "created_at": "2015-12-24T20:00:01Z" } ``` -------------------------------- ### prices sub-field examples Source: https://firestream.stocktwits.com/documentation/stream Individual examples for the prices object properties: id, symbol, and price. ```json "id" : 686 ``` ```json "symbol" : "ABC" ``` ```json "price" : "29.84" ``` -------------------------------- ### Complete LikeMessage object example Source: https://firestream.stocktwits.com/documentation/stream A complete JSON example of a like message object with all fields. ```json { "id": 19037074, "message_id": 73300225, "user_id": 654527, "liked_user_id": 364216, "created_at": "2015-12-24T20:00:01Z" } ``` -------------------------------- ### Complete friendship object example Source: https://firestream.stocktwits.com/documentation/stream A complete JSON example of a friendship object with all fields. ```json { "id": 19037074, "user_id": 654527, "following_user_id": 364216, "created_at": "2015-12-24T20:00:01Z" } ``` -------------------------------- ### Link created_at example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the created_at property of a link. ```json "created_at" : "2017-02-01T19:17:29Z" ``` -------------------------------- ### Link description example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the description property of a link. ```json "description" : "A guide to getting started in the stock market" ``` -------------------------------- ### Link image example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the image property of a link. ```json "image" : "https://www.stocks.com/icon.png" ``` -------------------------------- ### Link video_url example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the video_url property of a link. ```json "video_url" : null ``` -------------------------------- ### Link URL example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the url property of a link. ```json "url" : "https://www.stocks.com/the-how-to-guide/" ``` -------------------------------- ### Data format: created_at Source: https://firestream.stocktwits.com/documentation/symbols-stream Example JSON field for created_at. ```json "created_at" : "2019-08-24T14:15:22Z" ``` -------------------------------- ### Example JSON row (alternative-identifiers version) Source: https://firestream.stocktwits.com/documentation/symbols-reference Example JSON row for the alternative-identifiers version, including the optional isin and cusip fields. ```json { "symbol_id": 125625, "ticker": "AAPL", "exchange": "NASDAQ", "country": "US", "asset_class": "equity", "delisted": false, "isin": "US0378331005", "cusip": "037833100" } ``` -------------------------------- ### Example URL with AAPL symbol Source: https://firestream.stocktwits.com/documentation/sentiment-detail Example URL using the AAPL symbol for the sentiment detail endpoint. ```text https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/AAPL/detail ``` -------------------------------- ### Link source example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the source property of a link, containing name and website. ```json "source" : { "name": "Stocks", "website": "https://www.stocks.com" } ``` -------------------------------- ### mentioned_users field example Source: https://firestream.stocktwits.com/documentation/stream Example of the mentioned_users array, listing usernames of users mentioned in the post. ```json "mentioned_users" : ["@OtherPerson"] ``` -------------------------------- ### reshares field example Source: https://firestream.stocktwits.com/documentation/stream Example of the reshares object, providing the count of reshares and the user_ids array. ```json "reshares": { "reshared_count": 0, "user_ids": [] }, ``` -------------------------------- ### Data format: symbol Source: https://firestream.stocktwits.com/documentation/symbols-stream Example JSON field for symbol. ```json "symbol" : "AAPL" ``` -------------------------------- ### Action field example Source: https://firestream.stocktwits.com/documentation/stream Shows the value of the 'action' field, which is either 'create' or 'destroy'. ```json "action" : "create" ``` -------------------------------- ### Block object field examples Source: https://firestream.stocktwits.com/documentation/stream Individual JSON field examples for the block object: id, user_id, blocked_user_id, muted, and created_at. ```json "id" : "Message" ``` ```json "user_id" : 654527 ``` ```json "blocked_user_id" : 654527 ``` ```json "muted" : false ``` ```json "created_at" : "2015-12-24T20:00:01Z" ``` -------------------------------- ### User website_url field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'website_url' field, which is the user's website. ```json "website_url" : null ``` -------------------------------- ### Link title example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the title property of a link. ```json "title" : "How to Stock Market" ``` -------------------------------- ### symbols sub-field examples Source: https://firestream.stocktwits.com/documentation/stream Individual examples for each property of a symbol object: id, symbol, title, is_following, exchange, sector, industry, logo_url, trending, trending_score, watchlist_count, and aliases. ```json "id" : 686 ``` ```json "symbol" : "ABC" ``` ```json "title" : "Alpha Bravo Charlie, inc." ``` ```json "is_following" : false ``` ```json "exchange" : "NASDAQ" ``` ```json "sector" : "Technology" ``` ```json "industry" : "Personal Computers" ``` ```json "logo_url" : "http://logos.xignite.com/NASDAQGS/00011843.gif" ``` ```json "trending" : true ``` ```json "trending_score" : 16.4019 ``` ```json "watchlist_count" : 12370 ``` ```json "aliases": ["FBOOK","MTVS","FB"] ``` -------------------------------- ### User join_date field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'join_date' field, which is the user's sign-up date. ```json "join_date" : "2016-11-04" ``` -------------------------------- ### Link shortened_url example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the shortened_url property of a link. ```json "shortened_url" : "https://www.stocks.com/the-how-to-guide/" ``` -------------------------------- ### LikeMessage object field examples Source: https://firestream.stocktwits.com/documentation/stream Individual JSON field examples for the like message object: id, message_id, user_id, liked_user_id, and created_at. ```json "id" : 27169457 ``` ```json "message_id" : 73300225 ``` ```json "user_id" : 654527 ``` ```json "liked_user_id" : 654527 ``` ```json "created_at" : "2015-12-24T20:00:01Z" ``` -------------------------------- ### symbols array example Source: https://firestream.stocktwits.com/documentation/stream Complete example of the symbols array with a single symbol object, including all fields and additional properties like trending, trending_score, and watchlist_count. ```json "symbols": [{ "id": 686, "symbol": "ABC", "title": "Alpha Bravo Charlie, inc.", "is_following": false, "exchange": "NASDAQ", "sector": "Technology", "industry": "Personal Computers", "logo_url": "http://logos.xignite.com/NASDAQGS/00011843.gif", "trending": true, "trending_score": 16.4019, "watchlist_count": 12370 }], ``` -------------------------------- ### Link shortened_expanded_url example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure for the shortened_expanded_url property of a link. ```json "shortened_expanded_url" : "stocks.com/the-how-to-guide/" ``` -------------------------------- ### Data format: metric Source: https://firestream.stocktwits.com/documentation/symbols-stream Example JSON field for metric. ```json "metric" : "pageview" ``` -------------------------------- ### Data format: user_id Source: https://firestream.stocktwits.com/documentation/symbols-stream Example JSON field for user_id. ```json "user_id" : 5548695 ``` -------------------------------- ### User bio field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'bio' field, which is the user's bio. ```json "bio" : "Learning a lot with a lot to learn." ``` -------------------------------- ### User following field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'following' field, which is the number of other users that this user follows. ```json "following" : 14 ``` -------------------------------- ### User ideas field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'ideas' field, which is the number of messages the user has posted. ```json "ideas" : 966 ``` -------------------------------- ### User classification field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'classification' field, which can be 'suggested', 'official', or 'verified'. ```json "classification" : [ "suggested" ] ``` -------------------------------- ### Time field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'time' field, which is the timestamp of the data's creation or destruction. ```json "time" : "2017-02-01T19:19:18Z" ``` -------------------------------- ### User followers field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'followers' field, which is the number of followers the user has. ```json "followers" : 16 ``` -------------------------------- ### Sentiment object example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure of the sentiment property, which can be 'Bearish', 'Bullish', or null. ```json "sentiment" : { "basic" : "Bearish" } ``` -------------------------------- ### Field example: asset_class Source: https://firestream.stocktwits.com/documentation/symbols-reference Shows the JSON representation of the optional asset_class field, which is included where available. ```json "asset_class": "equity" ``` -------------------------------- ### Message source field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'source' field of a message, which contains the source of the message posting. ```json "source": { "id": 1149, "title": "StockTwits for iOS", "url": "http://www.stocktwits.com/mobile" }, ``` -------------------------------- ### GET /external/sentiment/v2/charts Source: https://firestream.stocktwits.com Gets 5-minute sentiment data for all symbols. ```APIDOC ## [GET] /external/sentiment/v2/charts ### Description Get 5 minute sentiment data for all symbols. ### Method GET ### Endpoint /external/sentiment/v2/charts ``` -------------------------------- ### User object example Source: https://firestream.stocktwits.com/documentation/stream Shows a complete user object with all fields, including deprecated fields and trading strategy. ```json "user": { "id": 222222, "username": "StocksGuy", "name": "John Smith", "avatar_url": "http://avatars.stocktwits.com/production/222222/thumb-1481680974.png", "avatar_url_ssl": "https://s3.amazonaws.com/st-avatars/production/222222/thumb-1481680974.png", "join_date": "2016-11-04", "official": false, "identity": "User", "classification": [], "followers": 16, "following": 14, "ideas": 966, "watchlist_stocks_count": 24, "like_count": 1170, "subscribers_count": 2, // DEPRECATED "subscribed_to_count": 1, // DEPRECATED "following_stocks": 0, "location": "California", "bio": "Learning a lot with a lot to learn.", "website_url": null, "trading_strategy": { "assets_frequently_traded": ["Equities","Private Companies"], "approach": "Value", "holding_period": "Position Trader", "experience": "Professional" } }, ``` -------------------------------- ### GET /external/sentiment/v2/{symbol}/chart Source: https://firestream.stocktwits.com Gets sentiment chart data for a specific symbol. ```APIDOC ## [GET] /external/sentiment/v2/{symbol}/chart ### Description Get sentiment chart data. ### Method GET ### Endpoint /external/sentiment/v2/{symbol}/chart ### Parameters #### Path Parameters - **symbol** (string) - Required - The symbol for which sentiment chart is requested. ``` -------------------------------- ### GET /external/sentiment/v2/{symbol}/detail Source: https://firestream.stocktwits.com Gets sentiment detail data for a specific symbol. ```APIDOC ## [GET] /external/sentiment/v2/{symbol}/detail ### Description Get sentiment detail data. ### Method GET ### Endpoint /external/sentiment/v2/{symbol}/detail ### Parameters #### Path Parameters - **symbol** (string) - Required - The symbol for which sentiment detail is requested. ``` -------------------------------- ### Links array example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure of the links property, an array of link objects with title, url, shortened_url, shortened_expanded_url, description, image, created_at, video_url, and source. ```json "links": [{ "title": "How to Stock Market", "url": "https://www.stocks.com/the-how-to-guide/", "shortened_url": "https://www.stocks.com/the-how-to-guide/", "shortened_expanded_url": "stocks.com/the-how-to-guide", "description": "A guide to getting started in the stock market", "image": "https://www.stocks.com/icon.png", "created_at": "2017-02-01T19:17:29Z", "video_url": null, "source": { "name": "Stocks", "website": "https://www.stocks.com" } }] ``` -------------------------------- ### GET /external/sentiment/v2/charts Source: https://firestream.stocktwits.com/documentation/sentiment-5min-all-symbols Retrieves a compressed JSON file with 5-minute sentiment data for all symbols for the day. Requires HTTP GET with a zoom query parameter (1D). The endpoint redirects to a gzipped file URL that gets automatically downloaded. ```APIDOC ## GET /external/sentiment/v2/charts ### Description Retrieves a compressed JSON file with the 5 minute sentiment data for all symbols for the day. ### Method GET ### Endpoint https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/charts ### Parameters #### Query Parameters - **zoom** (string) - Required - The granularity level for the symbols charts. Allowed values: 1D (Currently only 1D Supported). ### Request Example https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/charts?zoom=1D ### Response #### Success Response (307) Redirect to sentiment data file. The endpoint redirects to a gzipped file URL that gets automatically downloaded. File size = 15MB approximately. #### Error Responses - **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. ### Notes - Compression: Gzip. The endpoint redirects to a gzipped file URL that gets automatically downloaded. - Read Timeout: Set a read timeout on your client, and ensure that it is set to a value beyond 30 seconds. - Authentication: HTTP basic authentication is required (username and password). ### Example Request using curl ``` curl -u 'username':'password' -JL "https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/charts?zoom=1D" | gzip -d > output.json ``` ### Example Request using python ``` ''' This script uses the "urllib" library to get the sentiment data file. The "gzip" and "shutil" libraries are used to decompress the file. No pip installation is needed as these libraries are part of the standard library. ''' import urllib.request import base64 import gzip import shutil username = "myusername" password = "mypassword" credentials = f"{username}:{password}" encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8") zoom = "1D" output_file = "output.json" url = f"https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/charts?zoom={zoom}" ``` ``` -------------------------------- ### reshare_message field example Source: https://firestream.stocktwits.com/documentation/stream Example of the reshare_message object, containing reshared_count and the message details including user information. ```json "reshare_message": { "reshared_count": 1, "message": { "id": 5556662, "body": "$AAPL is moving today", "created_at": "2017-02-01T19:16:54Z", "user": { "id": 222222, "username": "StocksGuy", "name": "John Smith", "avatar_url": "http://avatars.stocktwits.com/production/222222/thumb-1481680974.png", "avatar_url_ssl": "https://s3.amazonaws.com/st-avatars/production/222222/thumb-1481680974.png", "join_date": "2016-11-04", "official": false, "identity": "User", "classification": [], "followers": 16, "following": 14, "ideas": 966, "watchlist_stocks_count": 24, "like_count": 1170, "subscribers_count": 2, // DEPRECATED "subscribed_to_count": 1, // DEPRECATED "following_stocks": 0, "location": "California", "bio": "Learning a lot with a lot to learn.", "website_url": null, "trading_strategy": { "assets_frequently_traded": ["Equities","Private Companies"], "approach": "Value", "holding_period": "Position Trader", "experience": "Professional" } }, "source": { "id": 1149, "title": "StockTwits for iOS", "url": "http://www.stocktwits.com/mobile" }, "symbols": [{ "id": 686, "symbol": "ABC", "title": "Alpha Bravo Charlie, inc.", "is_following": false, "exchange": "NASDAQ", "sector": "Technology", "industry": "Personal Computers", "logo_url": "http://logos.xignite.com/NASDAQGS/00011843.gif", "trending": true, "trending_score": 16.4019, "watchlist_count": 12370 }], "prices": [{ "id": 686, "symbol": "ABC", "price": "29.84" }], "mentioned_users": [], "entities": {} } }, ``` -------------------------------- ### Friendship object field examples Source: https://firestream.stocktwits.com/documentation/stream Individual JSON field examples for the friendship object: id, user_id, following_user_id, and created_at. ```json "id" : "Message" ``` ```json "user_id" : 654527 ``` ```json "following_user_id" : 654527 ``` ```json "created_at" : "2015-12-24T20:00:01Z" ``` -------------------------------- ### API Request with Query Parameter Source: https://firestream.stocktwits.com/documentation/sentiment-5min-all-symbols Example request URL including the required zoom parameter set to 1D. ```text https://api-gw-prd.stocktwits.com/api-middleware/external/sentiment/v2/charts?zoom=1D ``` -------------------------------- ### User tradingStrategy field example Source: https://firestream.stocktwits.com/documentation/stream Shows the 'tradingStrategy' object, which contains information about the user's trading strategy. ```json "tradingStrategy" : { "approach" : "Technical", "assetsFrequentlyTraded" : [ "Forex" ], "experience" : "Novice", "holdingPeriod" : "Day Trader" } ``` -------------------------------- ### conversation field example Source: https://firestream.stocktwits.com/documentation/stream Example of the conversation object, present when the message is part of a conversation. Includes parent_message_id, in_reply_to_message_id, parent flag, and replies count. ```json "conversation": { "parent_message_id": 5555662, "in_reply_to_message_id": 73300365, "parent": false, "replies": 5 }, ``` -------------------------------- ### GET /symbols/backups/{metric}/{year}/{month}/{day} Source: https://firestream.stocktwits.com Downloads symbol-based stream backups for a given metric, year, month, and day. ```APIDOC ## [GET] /symbols/backups/{metric}/{year}/{month}/{day} ### Description Download symbols based stream backups. ### Method GET ### Endpoint /symbols/backups/{metric}/{year}/{month}/{day} ### Parameters #### Path Parameters - **metric** (string) - Required - The metric for the backup. - **year** (integer) - Required - The year of the backup. - **month** (integer) - Required - The month of the backup. - **day** (integer) - Required - The day of the backup. ``` -------------------------------- ### Python request to get sentiment data Source: https://firestream.stocktwits.com/documentation/sentiment-detail Creates a GET request to the StockTwits sentiment endpoint, checks for HTTP 200 status, and prints the JSON response. Exits on request or response errors. ```python 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() ``` -------------------------------- ### GET /symbols/stream Source: https://firestream.stocktwits.com Connects to the symbols based data stream. ```APIDOC ## [GET] /symbols/stream ### Description Connect to the symbols based data stream. ### Method GET ### Endpoint /symbols/stream ``` -------------------------------- ### Data format: seq_id Source: https://firestream.stocktwits.com/documentation/symbols-stream Example JSON field for seq_id. ```json "seq_id":"49567487888076093524624994048752032346222860024699420674" ``` -------------------------------- ### Download backup with curl (double quotes for Windows) Source: https://firestream.stocktwits.com/documentation/backups Windows variant of the curl command using double quotes for username and password. Replace with your actual credentials. ```bash curl -JLO -u "username":"password" "https://firestream.stocktwits.com/backups/activity/2016/12/05" ``` -------------------------------- ### Chart object example Source: https://firestream.stocktwits.com/documentation/stream Shows the JSON structure of the chart property, containing thumb, large, original, and url image references. ```json "chart" : { "thumb": "http://charts.stocktwits.com/production/small_31307994.png", "large": "http://charts.stocktwits.com/production/large_31307994.png", "original": "http://charts.stocktwits.com/production/original_31307994.png", "url": "http://stks.co/g1Ye8" } ``` -------------------------------- ### Download reference.json via curl (Windows) Source: https://firestream.stocktwits.com/documentation/symbols-reference Use this curl command on Windows to download the symbol reference JSON file. Double quotes are used for the username and password. The -JLO options follow redirects, use the remote file name, and save the response as a file. ```bash curl -JLO -u "username":"password" "https://firestream.stocktwits.com/symbols/reference.json" ``` -------------------------------- ### Accept-Encoding header for Gzip compression Source: https://firestream.stocktwits.com/documentation/sentiment-detail Header to enable Gzip compression for the connection request. ```text Accept-Encoding: gzip ``` -------------------------------- ### Data format: symbol_id Source: https://firestream.stocktwits.com/documentation/symbols-stream Example JSON field for symbol_id. ```json "symbol_id" : 125625 ``` -------------------------------- ### Python script to download a backup file using requests Source: https://firestream.stocktwits.com/documentation/symbols-backups Uses the requests library with HTTPBasicAuth to download a backup file. Expects HTTP 200; otherwise prints error and exits. Saves the file with a constructed filename. ```python ''' This script uses the "requests" library to connect to the stream. It should be installed using pip before running this script. ''' import requests from requests.auth import HTTPBasicAuth url = "https://firestream.stocktwits.com/symbols/backups/pageviews/2024/12/05" username = "myusername" password = "mypassword" # Create a new request, the stream parameter is set to True to keep the connection open resp = requests.get(url, auth=HTTPBasicAuth(username, password), stream=True) # Extract filename from url filename = "stocktwits_"+"_".join(url.split('/')[-4:]) + '.gz' # 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() # Save the file try: with open(filename, 'wb') as f: for chunk in resp.iter_content(chunk_size=1024): if chunk: f.write(chunk) except Exception as e: print(f"Error saving file stream: {e}") ``` ```python import gzip, json # This is the name of the file that was downloaded fileName = "stocktwits_symbols_pageviews_2024_12_05.gz" # This is an array of dictionaries # Each dictionary represents a message data = [] # Open the file and read each line, we are using gzip to open the file # since the file is in .gz format with gzip.open(fileName, "rb") as f: for line in f: # Unmashall the JSON object from the line message = json.loads(line) # Append the message to the data array data.append(message) ``` -------------------------------- ### Read downloaded backup file with Python Source: https://firestream.stocktwits.com/documentation/backups Python script to read a gzip-compressed backup file line by line, unmarshal each JSON line, and append to a list. Requires the gzip and json modules. ```python import gzip, json # This is the name of the file that was downloaded fileName = "stocktwits_messages_2017_09_21.gz" # This is an array of dictionaries # Each dictionary represents a message data = [] # Open the file and read each line, we are using gzip to open the file # since the file is in .gz format with gzip.open(fileName, "rb") as f: for line in f: # Unmashall the JSON object from the line message = json.loads(line) # Append the message to the data array data.append(message) ``` -------------------------------- ### Python requests example Source: https://firestream.stocktwits.com/documentation/symbols-stream Python script using the requests library to connect to the stream, check for errors, and read lines from the response. ```python ''' This script uses the "requests" library to connect to the stream. It should be installed using pip before running this script. ''' import requests from requests.auth import HTTPBasicAuth username = "myusername" password = "mypassword" # Create a new request, the stream parameter is set to True to keep the connection open try: resp = requests.get("https://firestream.stocktwits.com/symbols/stream", auth=HTTPBasicAuth(username, password), stream=True) 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() # Read the response body on a loop try: for line in resp.iter_lines(): if line: # filter out keep-alive new lines print(line.decode()) except Exception as e: print(f"Error reading stream: {e}") exit() ```