Subscription
BitHash Websocket API is based on the Pusher protocol, implementing channels.
Subscribe to any channel with these parameters using Pusher library:
Websocket Endpoint Host:
wss://socket.bithash.net
Websocket Endpoint Port:
443
AppID:
547fc3e6948237f5d376
Here is a simple JavaScript example:
<!DOCTYPE html>
<pre id="log"></pre>
<script src="https://js.pusher.com/7.0.3/pusher.min.js"></script>
<script>
var pusher = new Pusher("547fc3e6948237f5d376", {
wsHost: 'socket.bithash.net',
wssPort: 443,
enabledTransports: ['ws','wss'],
encrypted: true,
forceTLS: true,
});
var channel = pusher.subscribe("market");
channel.bind("update", (data) => {
document.getElementById('log').innerHTML += JSON.stringify(data) + "\r\n";
});
</script>
Channels
MARKET
Channel streams market data for all active pairs.
{
"timestamp": 1638549571394
"id": "etc/btc",
"last": "0.00074",
"change": "+2.35%",
"high": 0.00074444,
"low": 0.0007201,
"volcur": 15.317214,
"vol": 20992.911
}
ORDERBOOK
Channel streams the entire orderbook level 2 snapshots for all active pairs.
{
"symbol": "DASH/BTC",
"timestamp": 1641331676285,
"asks": [
[
0.0029455,
3.87576428
],
...
],
"bids": [
[
0.0029451,
2.28203203
],
...
]
}
TRADES
Channel streams the recent trades feed for all active pairs.
{
"symbol": "ZEC/BTC",
"timestamp": 1641332085670,
"trades": [
{
"trade_id": 562120437,
"trade_timestamp": 1641332088000,
"price": 0.0032269,
"base_volume": 0.55556392,
"quote_volume": 0.00179275,
"type": "sell"
},
...
{
"trade_id": 562120440,
"trade_timestamp": 1641332088000,
"price": 0.0032269,
"base_volume": 0.55556392,
"quote_volume": 0.00179275,
"type": "buy"
}
]
}