Available languages: [Python](https://databento.com/docs/api-live/helpers/subscription.python.md) · [C++](https://databento.com/docs/api-live/helpers/subscription.cpp.md) · [Rust](https://databento.com/docs/api-live/helpers/subscription.rust.md) · [Raw](https://databento.com/docs/api-live/helpers/subscription.raw.md)

Source: https://databento.com/docs/api-live/helpers/subscription


### Subscription

The parameter struct and builder for [LiveClient::subscribe](https://databento.com/docs/api-live/client/subscribe.md).

The builder can be instantiated with the associated function `builder()`, and the struct is created from the builder with the `build()` method.
For every field except `sent_at`, there is an identically named setter method on the builder.
For `Option` fields, there is also a `maybe_` prefixed setter that accepts `Option<T>` directly.

To reverse a subscription, convert it to an `Unsubscription` with [Subscription::to_unsubscription](https://databento.com/docs/api-live/helpers/unsubscription.md).

#### API method

```rust
pub struct Subscription {
    pub symbols: Symbols,
    pub schema: Schema,
    pub stype_in: SType,
    pub start: Option<OffsetDateTime>,
    pub use_snapshot: bool,
    pub id: Option<u32>,
    pub sent_at: OffsetDateTime,
}
```

#### Fields

| Parameter | Type | Description |
| `symbols` | Symbols | The symbols of the instruments to subscribe to. |
| `schema` | Schema | The data record [schema](https://databento.com/docs/schemas/whats-a-schema.md). |
| `stype_in` | SType | The [symbology type](https://databento.com/docs/api-live/basics/symbology.md) of input `symbols`. Defaults to `SType::RawSymbol`. |
| `start` | Option\ | The inclusive start of subscription replay. Filters on `ts_event` except for the CBBO and BBO schemas, which filter on `ts_recv`. Must be within the last 24 hours. Pass `OffsetDateTime::UNIX_EPOCH` to request all available data. Cannot be specified after the [session](https://databento.com/docs/api-live/basics/sessions.md) is [started](https://databento.com/docs/api-live/client/start.md). Defaults to `None`. |
| `use_snapshot` | bool | Request subscription with [snapshot](https://databento.com/docs/conventions/mbo-snapshot.md). Only supported with `Mbo` schema. Defaults to `false`. Conflicts with the `start` parameter. |
| `id` | Option\ | A numerical identifier for the subscription. |
| `sent_at` | OffsetDateTime | When the subscription was last sent to the gateway. Set by the client and used by [LiveClient::resubscribe](https://databento.com/docs/api-live/client/resubscribe.md) to replay subscriptions and unsubscriptions in order. Defaults to `OffsetDateTime::UNIX_EPOCH` until sent. |

#### Example usage

```rust
use databento::{
    dbn::{SType, Schema},
    live::Subscription,
};

let sub = Subscription::builder()
    .symbols(vec!["AAPL", "MSFT"])
    .schema(Schema::Tbbo)
    .build();
assert_eq!(
    Subscription {
        symbols: vec!["AAPL", "MSFT"].into(),
        schema: Schema::Tbbo,
        stype_in: SType::RawSymbol,
        start: None,
        use_snapshot: false,
        id: None,
        sent_at: sub.sent_at,
    },
    sub
);
```
