# Lightstreamer

[![Hex.pm](https://img.shields.io/hexpm/v/lightstreamer.svg)](https://hex.pm/packages/lightstreamer)
[![Docs](https://img.shields.io/badge/hex-docs-blue.svg)](https://hexdocs.pm/lightstreamer)
[![CI](https://github.com/ktec/lightstreamer/actions/workflows/ci.yml/badge.svg)](https://github.com/ktec/lightstreamer/actions/workflows/ci.yml)

An unofficial Elixir client for [Lightstreamer](https://lightstreamer.com)
servers, speaking TLCP 2.5.0 over WebSocket.

Vendor-agnostic: this library implements the published TLCP protocol and
nothing else — adapter sets, item naming, field semantics and credential
formats are defined by the server you connect to. "Lightstreamer" is a
trademark of Lightstreamer Srl; this project is not affiliated with them.

## Installation

Add `lightstreamer` to your dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:lightstreamer, "~> 0.1"}
  ]
end
```

## Quick start

Stream live stock quotes from Lightstreamer's public demo server — paste
this into `iex -S mix`:

```elixir
{:ok, session} =
  Lightstreamer.connect("https://push.lightstreamer.com", adapter_set: "DEMO")

{:ok, sub} =
  Lightstreamer.subscribe(session,
    data_adapter: "QUOTE_ADAPTER",
    items: ["item1", "item2", "item3"],
    fields: ["stock_name", "last_price", "time"]
  )

for _ <- 1..10 do
  receive do
    {:lightstreamer, ^sub, {:update, %Lightstreamer.Update{} = update}} ->
      IO.inspect(update.values, label: update.item)
  end
end

Lightstreamer.close(session)
```

The first three updates are the snapshot (one full state per item); the rest
are live changes as the simulated market moves. Updates are plain messages,
so a real consumer is usually a GenServer handling them in `handle_info/2`.

Sessions heal themselves by default: server-driven rebinds are transparent,
and on connection loss the session reconnects with capped exponential
backoff, re-issuing subscriptions. See the
[`Lightstreamer` module documentation](https://hexdocs.pm/lightstreamer/Lightstreamer.html)
for the full API, options, and the delivery-message contract.

## License

Apache-2.0 — see the `LICENSE` file.
