---
title: "Fill stream"
description: "Stream your own fills (private trades), one frame per fill."
---

| | |
|---|---|
| SDK | `client.fill_stream(...)` |
| Channel | `v1.fill` on `wss://trades.<domain>/ws/full`, or `/ws/lite` for [lite names](../../guides/environments.md#encoding-full-or-lite) (the SDKs' default) |
| Selector | `<sub_account_id>[-<instrument>]` |
| Auth | Session required on the WebSocket upgrade ([Authentication](../../guides/authentication.md)) |
| Kind | `event`. Each frame is one event (an update to one object). |
| Sequenced | Yes: the first update's `prev_sequence_number` is at or below the subscribe reply's `latest_sequence_number`, then each one equals the last `sequence_number` ([rules](../../guides/websocket.md#sequence-numbers-and-gaps)). On a gap, re-subscribe, then fetch current state over HTTP ([`fill_history`](../rpc/fill_history.md)) for what you missed. |
| Contract id | `execution.fill` (`StreamFillV1`) |

## Selector

Grammar `<sub_account_id>[-<instrument>]`, e.g. `<sub_account_id>-BTC_USDT_Perp`. Parts:

- `sub_account_id` · uint64 — The sub-account ID to request for
- `instrument` · asset, optional — The instrument filter to apply.

## Frame

Type `WSFillFeedDataV1`.

- `stream` · lite `s` · string · required — The stream this frame belongs to, e.g. `v1.fill`.
- `selector` · lite `s1` · string · required — The selector this frame is for, as you subscribed with it.
- `sequence_number` · lite `sn` · string (uint64) · required — This frame's number, an unsigned 64-bit integer sent as a decimal string: compare it as an integer. `"0"` on the snapshot sent right after subscribing.
  - With `use_global_sequence_number: true` (recommended), the number is unique across the exchange. One exchange event can produce several frames, so the number is `event number × 10^5 + a counter` that tells them apart.
  - With `false`, it counts up by one per frame of this stream and starts again when the server you are connected to restarts.
- `feed` · lite `f` · object Fill · required — A private trade matching the request filter
- `feed.event_time` · lite `et` · string (int64 unix ns) · required — Time at which the event was emitted in unix nanoseconds
- `feed.sub_account_id` · lite `sa` · string (uint64) · required — The sub-account ID that participated in the trade
- `feed.instrument` · lite `i` · string (instrument name) · required — The instrument being represented
- `feed.is_buyer` · lite `ib` · bool · required — True if you bought in this trade, false if you sold.
- `feed.is_taker` · lite `it` · bool · required — True if your order took liquidity (taker), false if it was resting on the book (maker).
- `feed.size` · lite `s` · string · required — The number of assets being traded. Decimal string, e.g. "0.01"; up to the instrument's base_decimals.
- `feed.price` · lite `p` · string · required — The traded price. Decimal string, e.g. "65000.5"; up to 9 decimals.
- `feed.mark_price` · lite `mp` · string · optional — The mark price of the instrument at point of trade. Decimal string, e.g. "65000.5"; up to 9 decimals.
- `feed.index_price` · lite `ip` · string · required — The index price of the instrument at point of trade. Decimal string, e.g. "65000.5"; up to 9 decimals.
- `feed.interest_rate` · lite `ir` · string · required — The interest rate of the underlying when the trade happened, in percent (`"0.01"` = 0.01%).
- `feed.forward_price` · lite `fp` · string · optional — [Options] The forward price of the option at point of trade. Decimal string, e.g. "65000.5"; up to 9 decimals.
- `feed.realized_pnl` · lite `rp` · string · required — The realized PnL of the trade, in the quote asset. Decimal string, e.g. "12.5". (0 if increasing position size)
- `feed.fee` · lite `f` · string · required — The fees paid on the trade, in the quote asset. Decimal string, e.g. "12.5". (negative if maker rebate applied)
- `feed.fee_rate` · lite `fr` · string · required — The fee rate charged on this fill, in percent (`"0.02"` = 0.02%).
- `feed.trade_id` · lite `ti` · string · required — A trade identifier, globally unique, and monotonically increasing (not by `1`).
  All trades sharing a single taker execution share the same first component (before `-`), and `event_time`.
  `trade_id` is guaranteed to be consistent across MarketData `Trade` and Trading `Fill`.
- `feed.order_id` · lite `oi` · string (uint128) · required — The exchange's id of your order that filled.
- `feed.venue` · lite `v` · enum Venue · required — The venue where the trade occurred
  Values: `ORDERBOOK`, `RFQ` ([details](../enums.md#venue)).
- `feed.is_liquidation` · lite `il` · bool · required — If the trade was a liquidation
- `feed.client_order_id` · lite `co` · string (uint64) · required — The `client_order_id` of your order that filled.
- `feed.signer` · lite `s1` · string (uint256) · required — The address of the wallet that signed the order.
- `feed.broker` · lite `b` · enum BrokerTag · optional — Specifies the broker who brokered the order
  Values: `UNSPECIFIED`, `COIN_ROUTES`, `ALERTATRON`, `ORIGAMI` ([details](../enums.md#brokertag)).
- `feed.is_rpi` · lite `ir1` · bool · required — If the trade is a RPI trade
- `feed.builder` · lite `b1` · string (0x address) · required — The main account id of the builder the order went through, if any.
- `feed.builder_fee_rate` · lite `bf` · string · required — The builder's fee rate for this order, in percent (`"0.001"` = 0.001%), as set in the order's `builder_fee`.
- `feed.builder_fee` · lite `bf1` · string · required — The builder fee paid on this trade, in the quote asset. Decimal string, e.g. "12.5".
- `feed.fee_currency` · lite `fc` · string · required — The currency of the fee paid on the trade
- `feed.repayment_scenario` · lite `rs` · enum RepaymentScenario · required — Set when this fill repaid a multi-asset-mode USDT loan, and says how; `UNSPECIFIED` for ordinary trades.
  Values: `MANUAL_REPAYMENT`, `AUTO_REPAYMENT`, `LIQUIDATION_REPAYMENT`, `AUTO_REPAY_BORROW_LIMIT`, `AUTO_REPAY_LTV`, `LIQUIDATION_REBALANCING` ([details](../enums.md#repaymentscenario)).
- `feed.rfq_id` · lite `ri` · string (uint128) · optional — The RFQ this fill was cleared against. Only set for RFQ venue fills; unset otherwise
- `feed.counterparty_type` · lite `ct` · enum RfqCounterpartyType · optional — The type of counterparty this fill was matched against (maker quote / resting order / forced-exit netting). Only set for RFQ venue fills; unset otherwise
  Values: `MAKER_QUOTE`, `RESTING_ORDER`, `FORCED_EXIT_NETTING` ([details](../enums.md#rfqcounterpartytype)).
- `prev_sequence_number` · lite `ps` · string (uint64) · required — The `sequence_number` of the frame before this one on this selector. If it doesn't match the last frame you accepted, you missed frames.

## Errors

Subscribe errors arrive as a JSON-RPC `error` object `{code, message}` (lite `{c, m}`). Codes this stream can return ([all error codes](../errors.md)):

`1000` Unauthorized (401) · `1001` Forbidden (403) · `1002` InternalServer (500) · `1008` IPNotWhitelisted (401) · `1101` InvalidFeedFormat (400) · `1102` PrimarySelectorParts (400) · `1103` SecondarySelectorParts (400) · `3000` InvalidInstrument (400) · `3020` InvalidSubAccountID (400)

## Example

```python
import asyncio
import os

from grvt import AsyncGrvt


async def main():
    async with AsyncGrvt(env=os.environ.get("GRVT_ENV", "testnet"), api_key=os.environ["GRVT_API_KEY"]) as client:
        async with client.fill_stream(instrument="BTC_USDT_Perp", sub_account_id=os.environ["GRVT_SUB_ACCOUNT_ID"]) as sub:
            async for frame in sub:
                print(frame.sequence_number, frame.feed)


asyncio.run(main())
```

Raw WebSocket: connect to `wss://trades.$GRVT_DOMAIN/ws/full` (`/ws/lite` for lite names) with the `Cookie: gravity=...` and `X-Grvt-Account-Id` headers and send:

With full field names:

```json
{
  "jsonrpc": "2.0",
  "method": "subscribe",
  "params": {
    "stream": "v1.fill",
    "selectors": ["$GRVT_SUB_ACCOUNT_ID-BTC_USDT_Perp"],
    "use_global_sequence_number": true
  },
  "id": 1
}
```

With lite field names:

```json
{
  "j": "2.0",
  "m": "subscribe",
  "p": {
    "s": "v1.fill",
    "s1": ["$GRVT_SUB_ACCOUNT_ID-BTC_USDT_Perp"],
    "ug": true
  },
  "i": 1
}
```

The reply's `result` is a `WSSubscribeResult` (`subs`, `num_snapshots`, `latest_sequence_number`); then frames arrive in the shape under Frame above, with no JSON-RPC envelope.
