GET /backups/{file_type}/{year}/{month}/{day} 

Dowload a backup for the different available stream types. This works by generating a temporary download link to the file requested. The request will respond with a 302 redirect

Request Specifications

Request Method HTTP GET
URL Found on the stream's API Help page of your dashboard, using the following structure:

https://firestream.stocktwits.com/backups/{file_type}/{year}/{month}/{day}

file_type

  • activity : The activity data objects, found in /stream. Friendship, Block, LikeMessage
  • message : The message data objects, found in /stream.

Responses

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
302 Success The file is authorized and a redirect to the temporary download link is being returned.
400 Bad Request Please verify that the date is correct.
401 Unauthorized HTTP authentication failed due to invalid credentials. Verify that your stocktwits login is correct.
404 Not Found The file requested was not found.

Example request using curl

The following example request is accomplished using cURL on the command line.

  • The 'username':'password' will need to be replaced with your user login and password in order to download the file.
  • -JLO option L: Follows redirects. The url used to download the file is a temporary link that is presigned with your authorization.
  • -JLO option J: Use the remote file name. This lets curl use the file name on the server instead of the redirecting url as the file name being saved.
  • -JLO option O: Save the response as a file.
curl -JLO -u 'username':'password' "https://firestream.stocktwits.com/backups/activity/2016/12/05"

If you are working on Windows, you may need to use double quotes instead of single quotes for the username and password.

curl -JLO -u "username":"password" "https://firestream.stocktwits.com/backups/activity/2016/12/05"

Example request using python

The following example request is accomplished using a python script with the requests library.

'''
  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/backups/activity/2016/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}")
          

Example file read using python

The following example show how to read the downloaded file using 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)