ws = new WebSocket("wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?markets=coinbase-btc-usd-spot&pretty=true&api_key=<your_key>")
ws.onmessage = m => console.log(m.data); ws.onclose = () => console.log("closed")import asyncio
import websockets
async def handle(uri):
async with websockets.connect(uri) as websocket:
while True:
print(await websocket.recv())
asyncio.get_event_loop().run_until_complete(handle('wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?markets=coinbase-btc-usd-spot&pretty=true&api_key=<your_key>'))
curl --request GET \
--url 'wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key='<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key="
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key=")
.asString();require 'uri'
require 'net/http'
url = URI("wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key=")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"time": "2020-06-08T21:07:27.015507000Z",
"market": "coinbase-btc-usd-spot",
"coin_metrics_id": "1591540219445728-16126985",
"asks": [
{
"price": "9695.09",
"size": "1.58265903"
},
{
"price": "9695.1",
"size": "0.01056118"
},
{
"price": "9695.14",
"size": "0.0257"
}
],
"bids": [
{
"price": "9695.07",
"size": "0.97684462"
},
{
"price": "9694.38",
"size": "0.14852787"
},
{
"price": "9694.37",
"size": "0.90808736"
},
{
"price": "9693.24",
"size": "0.46738235"
},
{
"price": "9693",
"size": "0.0023"
}
],
"type": "snapshot",
"collect_time": "2020-06-08T21:07:27.082612000Z",
"cm_sequence_id": "0"
}Market orderbooks
Returns a WebSocket stream of orderbooks for specified markets.
Prediction markets (<exchange>-<symbol>-event_contract) are supported, both by name and via market patterns, e.g. kalshi-* or *-event_contract. Patterns match prediction markets of the exchanges available with the supplied credentials. backfill is ignored for prediction markets: only live books are sent. A market requested by name gets a full snapshot within about 10 seconds. A prediction market matched only by a pattern is sent from the first snapshot after its first change, so idle markets are not streamed.
Orderbooks are delivered using a sequence of snapshot and update messages.
Zero value of the size response field for asks or bids means negative update.
If you are falling behind (slow client) you will get warning message first, then error message and disconnection will happen.
ws = new WebSocket("wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?markets=coinbase-btc-usd-spot&pretty=true&api_key=<your_key>")
ws.onmessage = m => console.log(m.data); ws.onclose = () => console.log("closed")import asyncio
import websockets
async def handle(uri):
async with websockets.connect(uri) as websocket:
while True:
print(await websocket.recv())
asyncio.get_event_loop().run_until_complete(handle('wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?markets=coinbase-btc-usd-spot&pretty=true&api_key=<your_key>'))
curl --request GET \
--url 'wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key='<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key="
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key=")
.asString();require 'uri'
require 'net/http'
url = URI("wss://api.coinmetrics.io/v4/timeseries-stream/market-orderbooks?api_key=")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"time": "2020-06-08T21:07:27.015507000Z",
"market": "coinbase-btc-usd-spot",
"coin_metrics_id": "1591540219445728-16126985",
"asks": [
{
"price": "9695.09",
"size": "1.58265903"
},
{
"price": "9695.1",
"size": "0.01056118"
},
{
"price": "9695.14",
"size": "0.0257"
}
],
"bids": [
{
"price": "9695.07",
"size": "0.97684462"
},
{
"price": "9694.38",
"size": "0.14852787"
},
{
"price": "9694.37",
"size": "0.90808736"
},
{
"price": "9693.24",
"size": "0.46738235"
},
{
"price": "9693",
"size": "0.0023"
}
],
"type": "snapshot",
"collect_time": "2020-06-08T21:07:27.082612000Z",
"cm_sequence_id": "0"
}Authorizations
Query Parameters
Response
Orderbook WebSocket message.

