> For the complete documentation index, see [llms.txt](https://gitbook-docs.coinmetrics.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook-docs.coinmetrics.io/cm-api-spec/timeseries/timeseries-stream/market-trades.md).

# Market trades

Returns a WebSocket stream of trades for specified markets.\
If you are falling behind (slow client) you will get `warning` message first, then `error` message and disconnection will happen.

```json
{"openapi":"3.0.2","info":{"title":"Coin Metrics API v4","version":"4.0.0"},"tags":[{"name":"Timeseries stream","description":"WebSocket endpoints for getting a real-time stream of metrics, market data, indexes and other time series data.\n\n**Endpoints on this page:**\n- `GET /timeseries-stream/asset-metrics` — Asset metrics\n- `GET /timeseries-stream/asset-quotes` — Asset quotes\n- `GET /timeseries-stream/index-levels` — Index levels\n- `GET /timeseries-stream/market-candles` — Market candles\n- `GET /timeseries-stream/market-contract-prices` — Market contract prices\n- `GET /timeseries-stream/market-liquidations` — Market liquidations\n- `GET /timeseries-stream/market-openinterest` — Market open interest\n- `GET /timeseries-stream/market-orderbooks` — Market orderbooks\n- `GET /timeseries-stream/market-quotes` — Market quotes\n- `GET /timeseries-stream/market-trades` — Market trades\n- `GET /timeseries-stream/pair-quotes` — Pair quotes"}],"servers":[{"url":"wss://api.coinmetrics.io/v4"}],"security":[{"api_key":[]}],"components":{"securitySchemes":{"api_key":{"description":"Coin Metrics API key can be specified as `?api_key=` query parameter.","in":"query","name":"api_key","type":"apiKey"}},"parameters":{"MarketId":{"description":"Comma separated list of markets or market patterns like `exchange-*` or `exchange-*-spot` or `*USDT-future`.<br/> Use a corresponding `/catalog-all-v2/market-{dataType}` endpoint for the full list of supported markets for a given data type.","in":"query","name":"markets","required":true,"schema":{"type":"array","items":{"type":"string"}},"explode":false},"Backfill":{"description":"What data should be sent upon a connection.<br/> By default the latest values are sent just before real-time data.","in":"query","name":"backfill","schema":{"type":"string","default":"latest","enum":["latest","none"]}},"Pretty":{"description":"Human-readable formatting of JSON responses.","in":"query","name":"pretty","schema":{"type":"boolean","default":false}}},"responses":{"UriTooLong":{"description":"Provided URI is too long. It must not be greater than 10000 symbols."},"StreamingMarketTrades":{"description":"Trade WebSocket message.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/StreamingMarketTrade"}}}}},"schemas":{"StreamingMarketTrade":{"description":"Market trade WebSocket message.","properties":{"market":{"$ref":"#/components/schemas/MarketId"},"time":{"$ref":"#/components/schemas/Time"},"coin_metrics_id":{"$ref":"#/components/schemas/TradesCoinMetricsId"},"amount":{"$ref":"#/components/schemas/TradeAmount"},"price":{"$ref":"#/components/schemas/TradePrice"},"side":{"$ref":"#/components/schemas/TradeSide"},"cm_sequence_id":{"$ref":"#/components/schemas/cmSequenceId"},"collect_time":{"$ref":"#/components/schemas/TradeCollectTime"},"block_hash":{"$ref":"#/components/schemas/TradeBlockHash"},"block_height":{"$ref":"#/components/schemas/TradeBlockHeight"},"txid":{"$ref":"#/components/schemas/TradeTransactionId"},"initiator":{"$ref":"#/components/schemas/TradeInitiator"},"sender":{"$ref":"#/components/schemas/TradeSender"},"beneficiary":{"$ref":"#/components/schemas/TradeBeneficiary"},"mark_price":{"$ref":"#/components/schemas/TradeMarkPrice"},"index_price":{"$ref":"#/components/schemas/TradeIndexPrice"},"iv_trade":{"$ref":"#/components/schemas/TradeImpliedVolatility"},"liquidation":{"$ref":"#/components/schemas/TradeLiquidation"}},"required":["market","time","coin_metrics_id","amount","price","collect_time","cm_sequence_id"],"type":"object"},"MarketId":{"description":"Unique name of the market.","type":"string"},"Time":{"description":"The time in ISO 8601 date-time format. Always with nanoseconds precision.","type":"string","format":"date-time"},"TradesCoinMetricsId":{"description":"ID of a trade (unique per exchange market). We are using exchange reported value if exchange reports a unique numeric trade id. If exchange reports trade id as a string we convert to numeric using Bijective mapping from exchange reported trade id's string. If exchange doesn't report unique ID we transform it using exchange reported data to form a unique value per market.","type":"string"},"TradeAmount":{"description":"The amount of the base asset traded.","type":"string","format":"decimal"},"TradePrice":{"description":"The price of the base asset quoted in the quote asset that the trade was executed at.","type":"string","format":"decimal"},"TradeSide":{"description":"The market order side. \"buy\" means that an ask was removed from the book by an incoming buy order, \"sell\" means that a bid was removed from the book by an incoming sell order.","type":"string"},"cmSequenceId":{"description":"The monotonically increasing message number, resets on disconnection.","type":"string"},"TradeCollectTime":{"description":"Time of when the trade was received from the exchange.","type":"string","format":"date-time"},"TradeBlockHash":{"description":"Swap block hash. Available for DeFi markets only.","type":"string"},"TradeBlockHeight":{"description":"Swap block height. Available for DeFi markets only.","type":"string","format":"int64"},"TradeTransactionId":{"description":"Swap transaction ID. Available for DeFi markets only.","type":"string"},"TradeInitiator":{"description":"Swap transaction initiator. Available for DeFi markets only.","type":"string"},"TradeSender":{"description":"Swap caller. Available for DeFi markets only.","type":"string"},"TradeBeneficiary":{"description":"Swap output receiver. Available for DeFi markets only.","type":"string"},"TradeMarkPrice":{"description":"The price representing the futures' or option's price calculated by the exchange for risk management purposes.","type":"string","format":"decimal"},"TradeIndexPrice":{"description":"The price index is an aggregate price derived from the major exchanges to be representative of the underlying asset's market consensus price.","type":"string","format":"decimal"},"TradeImpliedVolatility":{"description":"Implied volatility calculated from the trade price.","type":"string","format":"decimal"},"TradeLiquidation":{"description":"Indicates whether the maker side, taker side, or both sides of the trade is under liquidation.","type":"string"}}},"paths":{"/timeseries-stream/market-trades":{"get":{"summary":"Market trades","description":"Returns a WebSocket stream of trades for specified markets.<br/> If you are falling behind (slow client) you will get `warning` message first, then `error` message and disconnection will happen.","operationId":"getTimeseriesStreamMarketTrades","tags":["Timeseries stream"],"parameters":[{"$ref":"#/components/parameters/MarketId"},{"$ref":"#/components/parameters/Backfill"},{"$ref":"#/components/parameters/Pretty"}],"responses":{"414":{"$ref":"#/components/responses/UriTooLong"},"default":{"$ref":"#/components/responses/StreamingMarketTrades"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook-docs.coinmetrics.io/cm-api-spec/timeseries/timeseries-stream/market-trades.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
