---
id: push_candlestick
title: Candlesticks
slug: /quote/push/candlestick
sidebar_position: 9
---

Real-time candlestick (K-line) data push for subscribed securities. The callback fires whenever the current candlestick updates (Realtime mode) or when a candlestick period closes (Confirmed mode).

:::tip

This page covers the **push** API (`subscribe_candlesticks`). To pull historical candlestick data on demand, see [Candlestick - Pull](/quote/stocks/candlestick).

:::

> **Quote Permission Required: Free**
> - US stocks: US LV1 real-time quotes included free by default.
> - HK stocks: LV1 real-time quotes included by default.
> - Candlestick push requires the same permission as quote subscription.
> [My Quotes](https://open.longbridge.com/account)
> OpenAPI quote perms are separate from App/Web perms


## SDK

| Language | Link |
|---|---|
| Python | [longbridge.openapi.quote._quote_context](https://longbridge.github.io/openapi/python/reference_all/#longbridge.openapi.quote._quote_context) |
| Rust | [longbridge::<SDKLinks module="quote" klass="QuoteContext" method="set_on_candlestick" go="OnCandlestick" />::quote#_quote_context](https://longbridge.github.io/openapi/rust/longbridge/<SDKLinks module="quote" klass="QuoteContext" method="set_on_candlestick" go="OnCandlestick" />/struct.quote.html#method._quote_context) |
| Go | [quote.set_on_candlestick](https://pkg.go.dev/github.com/longbridge/openapi-go/<SDKLinks module="quote" klass="QuoteContext" method="set_on_candlestick" go="OnCandlestick" />#quote.set_on_candlestick) |
| Node.js | [quote#QuoteContext](https://longbridge.github.io/openapi/nodejs/classes/quote.html#quotecontext) |
| Java | [quote.OnCandlestick](https://longbridge.github.io/openapi/java/com/longbridge/<SDKLinks module="quote" klass="QuoteContext" method="set_on_candlestick" go="OnCandlestick" />/quote.html#OnCandlestick) |
| C++ | [longbridge::<SDKLinks module="quote" klass="QuoteContext" method="set_on_candlestick" go="OnCandlestick" />::quote::_quote_context](https://longbridge.github.io/openapi/cpp/classlongbridge_1_1<SDKLinks module="quote" klass="QuoteContext" method="set_on_candlestick" go="OnCandlestick" />_1_1_quote.html) |

:::info

[Business Command](../../socket/protocol/push): `105`

:::

## Data Format

### Properties

| Name                | Type     | Description                                                                              |
|---------------------|----------|------------------------------------------------------------------------------------------|
| symbol              | string   | Security code, for example: `AAPL.US`                                                   |
| period              | int32    | Candlestick period, see [Period](../objects#period---candlestick-period)                 |
| candlestick         | object   | Candlestick data                                                                         |
| ∟ close             | string   | Close price                                                                              |
| ∟ open              | string   | Open price                                                                               |
| ∟ high              | string   | High price                                                                               |
| ∟ low               | string   | Low price                                                                                |
| ∟ volume            | int64    | Volume                                                                                   |
| ∟ turnover          | string   | Turnover                                                                                 |
| ∟ timestamp         | int64    | Candlestick time (Unix timestamp)                                                        |
| ∟ trade_session     | int32    | Trade session, see [TradeSession](../objects#tradesession---trading-session)             |

### Protobuf

```protobuf
message PushCandlestick {
  string symbol = 1;
  Period period = 2;
  Candlestick candlestick = 3;
}

message Candlestick {
  string close = 1;
  string open = 2;
  string high = 3;
  string low = 4;
  int64 volume = 5;
  string turnover = 6;
  int64 timestamp = 7;
  TradeSession trade_session = 8;
}
```

### Example

```python
from time import sleep
from longbridge.openapi import QuoteContext, Config, Period, PushCandlestick, OAuthBuilder

def on_candlestick(symbol: str, event: PushCandlestick):
    print(symbol, event)

oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = QuoteContext(config)
ctx.set_on_candlestick(on_candlestick)

ctx.subscribe_candlesticks("700.HK", Period.Min_1)
sleep(30)
```

### JSON Example

```json
{
  "symbol": "700.HK",
  "period": 1,
  "candlestick": {
    "close": "162.500",
    "open": "160.000",
    "high": "163.000",
    "low": "159.800",
    "volume": 123456,
    "turnover": "19987654.000",
    "timestamp": 1651103700,
    "trade_session": 0
  }
}
```
