Skip to content

Configuration

ThetaDataDx provides sensible defaults for production use, with full control over every parameter when you need it.

Presets

Two built-in presets cover the common cases:

rust
use thetadatadx::DirectConfig;

// Production (ThetaData NJ datacenter, gRPC over TLS)
let config = DirectConfig::production();

// Dev (same servers, shorter timeouts for faster iteration)
let config = DirectConfig::dev();
python
from thetadatadx import Config

# Production (ThetaData NJ datacenter, gRPC over TLS)
config = Config.production()

# Dev (same servers, shorter timeouts for faster iteration)
config = Config.dev()

Custom Configuration

Override specific fields while keeping production defaults:

rust
let config = DirectConfig {
    fpss_timeout_ms: 5_000,
    reconnect_wait_ms: 2_000,
    ..DirectConfig::production()
};
python
config = Config.production()
config.fpss_timeout_ms = 5_000
config.reconnect_wait_ms = 2_000

Override gRPC Concurrency

By default, the number of concurrent gRPC requests is auto-detected from your subscription tier (2^tier). You can override this:

rust
let config = DirectConfig {
    mdds_concurrent_requests: Some(8),  // manual override
    ..DirectConfig::production()        // None = auto from tier
};
python
config = Config.production()
config.mdds_concurrent_requests = 8  # manual override; None = auto from tier

Configuration Fields

rust
pub struct DirectConfig {
    // MDDS (Historical gRPC)
    pub mdds_host: String,                  // "mdds-01.thetadata.us"
    pub mdds_port: u16,                     // 443
    pub mdds_tls: bool,                     // true
    pub mdds_max_message_size: usize,       // max gRPC message size
    pub mdds_keepalive_secs: u64,           // gRPC keepalive interval
    pub mdds_keepalive_timeout_secs: u64,   // gRPC keepalive timeout

    // FPSS (Real-Time TCP)
    pub fpss_hosts: Vec<(String, u16)>,     // server failover list
    pub fpss_timeout_ms: u64,               // read timeout
    pub fpss_queue_depth: usize,            // event ring buffer size
    pub fpss_ping_interval_ms: u64,         // heartbeat interval (100ms)
    pub fpss_connect_timeout_ms: u64,       // TCP connect timeout

    // Reconnection
    pub reconnect_wait_ms: u64,             // base reconnect delay (2000ms)
    pub reconnect_wait_rate_limited_ms: u64,// rate-limit delay (130000ms)

    // Concurrency
    pub mdds_concurrent_requests: Option<usize>,  // None = auto (2^tier)

    // Threading
    pub tokio_worker_threads: Option<usize>,// Tokio runtime thread count
}

FPSS Server List

The default FPSS server list matches the Java terminal:

ServerPort
nj-a.thetadata.us20000
nj-a.thetadata.us20001
nj-b.thetadata.us20000
nj-b.thetadata.us20001

Servers are tried in order during connection. If the first server fails, the client automatically falls over to the next.

Concurrency Model

The mdds_concurrent_requests field controls the maximum number of in-flight gRPC requests. Each endpoint method acquires a semaphore permit before sending and releases it when the response is fully consumed.

SettingBehavior
None / not set (default)Auto-detected from subscription tier: 2^tier
Explicit valueFixed at n concurrent requests

TIP

Higher concurrency lets you fetch more data in parallel, but exceeding your tier's limit will trigger rate-limiting (error code 12) with a 130-second backoff.

Timeouts

TimeoutDefaultDescription
FPSS connect2000msTCP connection to FPSS servers
FPSS read10000msFrame read timeout
FPSS ping100msHeartbeat interval (required by server)
Reconnect (normal)2000msDelay before reconnecting after disconnect
Reconnect (rate-limited)130000msDelay after TooManyRequests (code 12)
Nexus HTTP connect5000msHTTP connection to auth server
Nexus HTTP request10000msTotal auth request timeout

Environment Variables

For development and testing, you can override the server target:

bash
export THETADX_HOST="127.0.0.1"
export THETADX_PORT="11000"

WARNING

Environment variable overrides are intended for local development only. In production, use the DirectConfig / Config presets which point to the correct ThetaData datacenter endpoints.

Released under the GPL-3.0-or-later License.