# Live Quotes (Per Second)

`WS` `wss://socket.vantafin.com/v1/stocks`

Subscribe to per-second live quotes over Vantafin’s WebSocket API. After authenticating with your API key, send a subscribe message for channel LS.{ticker} (e.g. LS.AAPL) or LS.* for every live ticker. During market hours (4:00 AM-8:00 PM ET on trading days) you receive one quote per ticker per second with open, high, low, close, volume and a timestamp. If the market is closed, the server may respond with a market_status message instead of data.

## Use cases

- Real-time intraday charts with second-level resolution
- High-frequency monitoring and short-horizon signals
- Live dashboards that need fresher updates than one-minute data
- Market microstructure and liquidity research during the session

## Subscribe

Subscribe to `LS.{ticker}` (e.g. `LS.AAPL`) for a single ticker, or `LS.*` for every ticker:

```json
{"action":"subscribe","params":"LS.AAPL"}
```

## Message fields

| Field | Type | Description |
| --- | --- | --- |
| `type` | string | Message type discriminator. |
| `ticker` | string | Ticker. |
| `open` | float | Opening price of the window. |
| `high` | float | Highest trade price in the window. |
| `low` | float | Lowest trade price in the window. |
| `close` | float | Closing price of the window. |
| `volume` | integer | Traded volume in the window. |
| `timestamp` | integer | Window timestamp, epoch milliseconds. |

## Example output

```json
{
  "type": "live_quote_second",
  "ticker": "AAPL",
  "open": 189.12,
  "high": 189.2,
  "low": 189.05,
  "close": 189.18,
  "volume": 12500,
  "timestamp": 1700000001000
}
```

## Connection examples

### cURL

```bash
# install websocat: https://github.com/vi/websocat
echo '{"action":"subscribe","params":"LS.AAPL"}' \
  | websocat "wss://socket.vantafin.com/v1/stocks?apiKey=$VANTAFIN_API_KEY"
```

### Python

```python
from vantafin import WebSocketClient

ws = WebSocketClient("vf-live-your_api_key")
ws.connect()
ws.subscribe(["LS.AAPL"])

for message in ws:
    print(message)
```

### JavaScript

```javascript
import { WebSocketClient } from "vantafin";

const ws = new WebSocketClient("vf-live-your_api_key");
ws.on("message", (msg) => console.log(msg));

await ws.connect();
ws.subscribe(["LS.AAPL"]);
```

### Go

```go
package main

import (
	"fmt"
	"log"

	"github.com/vantafin/vantafin-go"
)

func main() {
	ws := vantafin.NewWebSocketClient("vf-live-your_api_key")
	conn, err := ws.Connect()
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	conn.Subscribe("LS.AAPL")
	for {
		msg, err := conn.Read()
		if err != nil {
			break
		}
		fmt.Println(msg)
	}
}
```

### Java

```java
import com.vantafin.WebSocketClient;

public class Example {
    public static void main(String[] args) throws Exception {
        WebSocketClient ws = new WebSocketClient("vf-live-your_api_key");
        ws.connect(message -> System.out.println(message));
        ws.subscribe("LS.AAPL");
    }
}
```

### Ruby

```ruby
require "vantafin"

ws = Vantafin::WebSocketClient.new("vf-live-your_api_key")
ws.on(:message) { |msg| pp msg }
ws.connect
ws.subscribe("LS.AAPL")
sleep
```
