Authentication
ThetaDataDx authenticates with ThetaData's servers using your account email and password. There are two ways to provide credentials.
Credentials File
Create a creds.txt file with your ThetaData email on line 1 and password on line 2:
your-email@example.com
your-passwordWARNING
Do not commit creds.txt to version control. Add it to your .gitignore.
Load the file in your application:
let creds = Credentials::from_file("creds.txt")?;from thetadatadx import Credentials
creds = Credentials.from_file("creds.txt")creds, err := thetadatadx.CredentialsFromFile("creds.txt")
if err != nil {
log.Fatal(err)
}
defer creds.Close()auto creds = tdx::Credentials::from_file("creds.txt");Environment Variables
For containerized deployments or CI pipelines, pass credentials through environment variables:
let creds = Credentials::new(
std::env::var("THETA_EMAIL")?,
std::env::var("THETA_PASS")?,
);import os
from thetadatadx import Credentials
creds = Credentials(os.environ["THETA_EMAIL"], os.environ["THETA_PASS"])creds, err := thetadatadx.CredentialsFromEnv("THETA_EMAIL", "THETA_PASS")
if err != nil {
log.Fatal(err)
}
defer creds.Close()auto creds = tdx::Credentials(
std::getenv("THETA_EMAIL"),
std::getenv("THETA_PASS")
);TIP
Environment variables are the recommended approach for production deployments and Docker containers. The file-based approach is convenient for local development.
Connecting
Once you have credentials, create a client connected to ThetaData's production servers:
use thetadatadx::{ThetaDataDx, Credentials, DirectConfig};
let creds = Credentials::from_file("creds.txt")?;
let client = ThetaDataDx::connect(&creds, DirectConfig::production()).await?;from thetadatadx import Credentials, Config, ThetaDataDx
creds = Credentials.from_file("creds.txt")
client = ThetaDataDx(creds, Config.production())creds, _ := thetadatadx.CredentialsFromFile("creds.txt")
defer creds.Close()
config := thetadatadx.ProductionConfig()
defer config.Close()
client, err := thetadatadx.Connect(creds, config)
if err != nil {
log.Fatal(err)
}
defer client.Close()auto creds = tdx::Credentials::from_file("creds.txt");
auto client = tdx::Client::connect(creds, tdx::Config::production());The client authenticates automatically on connection. If credentials are invalid, the connection call returns an error immediately.