Skip to content

First Query

One historical call, every SDK, side by side. Each snippet assumes you have a creds.txt file (see Authentication) and an active ThetaData subscription with stock EOD access (the free tier is sufficient).

End-of-day stock history

rust
use thetadatadx::{ThetaDataDxClient, Credentials, DirectConfig};

#[tokio::main]
async fn main() -> Result<(), thetadatadx::Error> {
    let creds = Credentials::from_file("creds.txt")?;
    let client = ThetaDataDxClient::connect(&creds, DirectConfig::production()).await?;

    let eod = client.stock_history_eod("AAPL", "20240101", "20240301").await?;
    for tick in &eod {
        println!("{}: O={:.2} H={:.2} L={:.2} C={:.2} V={}",
            tick.date, tick.open, tick.high, tick.low, tick.close, tick.volume);
    }
    Ok(())
}
python
from thetadatadx import Credentials, Config, ThetaDataDxClient

creds = Credentials.from_file("creds.txt")
client = ThetaDataDxClient(creds, Config.production())

eod = client.stock_history_eod("AAPL", "20240101", "20240301")
for tick in eod:
    print(f"{tick.date}: O={tick.open:.2f} H={tick.high:.2f} "
          f"L={tick.low:.2f} C={tick.close:.2f} V={tick.volume}")
typescript
import { ThetaDataDxClient } from 'thetadatadx';

const client = await ThetaDataDxClient.connectFromFile('creds.txt');

const eod = client.stockHistoryEOD('AAPL', '20240101', '20240301');
for (const tick of eod) {
    console.log(`${tick.date}: O=${tick.open} H=${tick.high} L=${tick.low} C=${tick.close} V=${tick.volume}`);
}
cpp
#include "thetadx.hpp"
#include <iomanip>
#include <iostream>

int main() {
    auto creds = tdx::Credentials::from_file("creds.txt");
    auto client = tdx::Client::connect(creds, tdx::Config::production());

    auto eod = client.stock_history_eod("AAPL", "20240101", "20240301");
    for (const auto& tick : eod) {
        std::cout << tick.date
                  << std::fixed << std::setprecision(2)
                  << ": O=" << tick.open << " H=" << tick.high
                  << " L=" << tick.low  << " C=" << tick.close
                  << " V=" << tick.volume << std::endl;
    }
}

Sample response

json
[
  {"date": 20240102, "open": 187.15, "high": 188.44, "low": 183.89, "close": 185.64, "volume": 82488682},
  {"date": 20240103, "open": 184.22, "high": 185.88, "low": 183.43, "close": 184.25, "volume": 58414500},
  {"date": 20240104, "open": 182.15, "high": 183.09, "low": 180.88, "close": 181.91, "volume": 71983600}
]

Every historical endpoint returns a typed tick list with the same JSON-like shape across all four SDKs. Numeric fields are decoded to f64 / double at parse time — no Price{value, type} objects to unpack.

What runs under the hood

  1. connect() loads credentials and authenticates against ThetaData's Nexus endpoint, retrieving a session UUID.
  2. The session UUID is attached to an HTTP/2 (tonic / gRPC) channel to the MDDS datacenter.
  3. stock_history_eod(...) streams a compressed protobuf DataTable response.
  4. A Rust decoder turns the DataTable into a Vec<StockEodTick> (~86k rows/sec per core on wide-schema data). The Python / TypeScript / C++ bindings expose this slice as the language's native collection.

Next

Released under the Apache-2.0 License.