Quick Start

Two minimal examples, one per API surface. They assume you have an API key set up — see Authentication if not.

Historical: pull a slice of trades

using DatabentoAPI, Dates

client = Historical()
store  = get_range(client;
    dataset  = "XNAS.ITCH",
    schema   = Schema.TRADES,
    symbols  = ["AAPL"],
    start    = DateTime(2024, 1, 2, 14, 30),
    end_     = DateTime(2024, 1, 2, 14, 31),
    stype_in = SType.RAW_SYMBOL)

df = to_dataframe(store)
@show size(df) first(df, 3)

For datasets too large to materialize, use foreach_record with a typed callback (zero-allocation hot path) — see Historical Data.

Live: subscribe inside a do-block

using DatabentoAPI

Live(dataset = "GLBX.MDP3") do live
    connect!(live)
    subscribe!(live;
        schema   = Schema.TRADES,
        symbols  = ["ES.FUT"],
        stype_in = SType.PARENT)
    start!(live)
    for rec in live
        rec isa DBN.TradeMsg && @info "trade" rec.price rec.size
    end
end
# Ctrl-C exits the loop, the do-block's `finally` calls `close(live)`,
# and the function returns normally.

For long-running captures that write to disk and survive disconnects, use stream_to_file — see Capture to File.

What next?